src/java.smartcardio/share/classes/javax/smartcardio/TerminalFactory.java
author pmuthuswamy
Wed, 19 Dec 2018 11:08:08 +0530
changeset 53070 fc10906d5831
parent 47216 71c04702a3d5
permissions -rw-r--r--
8214570: Use {@systemProperty} for definitions of system properties Reviewed-by: alanb, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53070
fc10906d5831 8214570: Use {@systemProperty} for definitions of system properties
pmuthuswamy
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.smartcardio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.security.jca.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.security.jca.GetInstance.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * A factory for CardTerminal objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * It allows an application to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <li>obtain a TerminalFactory by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * one of the static factory methods in this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * ({@linkplain #getDefault} or {@linkplain #getInstance getInstance()}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <li>use this TerminalFactory object to access the CardTerminals by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * calling the {@linkplain #terminals} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>Each TerminalFactory has a <code>type</code> indicating how it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * was implemented. It must be specified when the implementation is obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * using a {@linkplain #getInstance getInstance()} method and can be retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * via the {@linkplain #getType} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <P>The following standard type names have been defined:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <dt><code>PC/SC</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <dd>an implementation that calls into the PC/SC Smart Card stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * of the host platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * Implementations do not require parameters and accept "null" as argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * in the getInstance() calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <dt><code>None</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <dd>an implementation that does not supply any CardTerminals. On platforms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * that do not support other implementations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * {@linkplain #getDefaultType} returns <code>None</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * {@linkplain #getDefault} returns an instance of a <code>None</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * TerminalFactory. Factories of this type cannot be obtained by calling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <code>getInstance()</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Additional standard types may be defined in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <p><strong>Note:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Provider implementations that accept initialization parameters via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <code>getInstance()</code> methods are strongly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * encouraged to use a {@linkplain java.util.Properties} object as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * representation for String name-value pair based parameters whenever
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * possible. This allows applications to more easily interoperate with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * multiple providers than if each provider used different provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * specific class as parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <P>TerminalFactory utilizes an extensible service provider framework.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Service providers that wish to add a new implementation should see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * {@linkplain TerminalFactorySpi} class for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @see CardTerminals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * @author  JSR 268 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
public final class TerminalFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private final static String PROP_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                        "javax.smartcardio.TerminalFactory.DefaultType";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private final static String defaultType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private final static TerminalFactory defaultFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        // lookup up the user specified type, default to PC/SC
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 14342
diff changeset
   100
        String type = AccessController.doPrivileged(
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 14342
diff changeset
   101
             (PrivilegedAction<String>) () -> System.getProperty(PROP_NAME, "PC/SC")).trim();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        TerminalFactory factory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            factory = TerminalFactory.getInstance(type, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (factory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            // if that did not work, try the Sun PC/SC factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                type = "PC/SC";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                Provider sun = Security.getProvider("SunPCSC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                if (sun == null) {
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37348
diff changeset
   114
                    @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37348
diff changeset
   115
                    Object o = Class.forName("sun.security.smartcardio.SunPCSC").newInstance();
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 37348
diff changeset
   116
                    sun = (Provider)o;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                factory = TerminalFactory.getInstance(type, null, sun);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (factory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            type = "None";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            factory = new TerminalFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                        (NoneFactorySpi.INSTANCE, NoneProvider.INSTANCE, "None");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        defaultType = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        defaultFactory = factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private static final class NoneProvider extends Provider {
10709
d865c9f21240 7092375: Security Libraries don't build with javac -Werror
xuelei
parents: 5506
diff changeset
   133
d865c9f21240 7092375: Security Libraries don't build with javac -Werror
xuelei
parents: 5506
diff changeset
   134
        private static final long serialVersionUID = 2745808869881593918L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        final static Provider INSTANCE = new NoneProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        private NoneProvider() {
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 37782
diff changeset
   137
            super("None", "1.0", "none");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private static final class NoneFactorySpi extends TerminalFactorySpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        final static TerminalFactorySpi INSTANCE = new NoneFactorySpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        private NoneFactorySpi() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        protected CardTerminals engineTerminals() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return NoneCardTerminals.INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private static final class NoneCardTerminals extends CardTerminals {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        final static CardTerminals INSTANCE = new NoneCardTerminals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        private NoneCardTerminals() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        public List<CardTerminal> list(State state) throws CardException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            if (state == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            return Collections.emptyList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        public boolean waitForChange(long timeout) throws CardException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            throw new IllegalStateException("no terminals");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    private final TerminalFactorySpi spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    private final Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private final String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private TerminalFactory(TerminalFactorySpi spi, Provider provider, String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        this.spi = spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Get the default TerminalFactory type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <p>It is determined as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * when this class is initialized, the system property
53070
fc10906d5831 8214570: Use {@systemProperty} for definitions of system properties
pmuthuswamy
parents: 47216
diff changeset
   185
     * {@systemProperty javax.smartcardio.TerminalFactory.DefaultType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * is examined. If it is set, a TerminalFactory of this type is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * instantiated by calling the {@linkplain #getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * getInstance(String,Object)} method passing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <code>null</code> as the value for <code>params</code>. If the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * succeeds, the type becomes the default type and the factory becomes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * the {@linkplain #getDefault default} factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * <p>If the system property is not set or the getInstance() call fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * for any reason, the system defaults to an implementation specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * default type and TerminalFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @return the default TerminalFactory type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public static String getDefaultType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return defaultType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Returns the default TerminalFactory instance. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * {@linkplain #getDefaultType} for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <p>A default TerminalFactory is always available. However, depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * on the implementation, it may not offer any terminals.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @return the default TerminalFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public static TerminalFactory getDefault() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return defaultFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Returns a TerminalFactory of the specified type that is initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * with the specified parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * A new TerminalFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * TerminalFactorySpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Provider that supports the specified type is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * the {@linkplain Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * <p>The <code>TerminalFactory</code> is initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * specified parameters Object. The type of parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * needed may vary between different types of <code>TerminalFactory</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25859
diff changeset
   233
     * @implNote
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25859
diff changeset
   234
     * The JDK Reference Implementation additionally uses the
37348
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   235
     * {@code jdk.security.provider.preferred}
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   236
     * {@link Security#getProperty(String) Security} property to determine
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25859
diff changeset
   237
     * the preferred provider order for the specified algorithm. This
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25859
diff changeset
   238
     * may be different than the order of providers returned by
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25859
diff changeset
   239
     * {@link Security#getProviders() Security.getProviders()}.
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25859
diff changeset
   240
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param type the type of the requested TerminalFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param params the parameters to pass to the TerminalFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *   implementation, or null if no parameters are needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @return a TerminalFactory of the specified type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @throws NullPointerException if type is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @throws NoSuchAlgorithmException if no Provider supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *   TerminalFactorySpi of the specified type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public static TerminalFactory getInstance(String type, Object params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        Instance instance = GetInstance.getInstance("TerminalFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            TerminalFactorySpi.class, type, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return new TerminalFactory((TerminalFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Returns a TerminalFactory of the specified type that is initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * with the specified parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * <p> A new TerminalFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * TerminalFactorySpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * the {@linkplain Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * <p>The <code>TerminalFactory</code> is initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * specified parameters Object. The type of parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * needed may vary between different types of <code>TerminalFactory</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @param type the type of the requested TerminalFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param params the parameters to pass to the TerminalFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *   implementation, or null if no parameters are needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param provider the name of the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @return a TerminalFactory of the specified type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @throws NullPointerException if type is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @throws IllegalArgumentException if provider is null or the empty String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @throws NoSuchAlgorithmException if a TerminalFactorySpi implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *   of the specified type is not available from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @throws NoSuchAlgorithmException if no TerminalFactory of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *   specified type could be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @throws NoSuchProviderException if the specified provider could not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *   be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public static TerminalFactory getInstance(String type, Object params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            String provider) throws NoSuchAlgorithmException, NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        Instance instance = GetInstance.getInstance("TerminalFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            TerminalFactorySpi.class, type, params, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return new TerminalFactory((TerminalFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Returns a TerminalFactory of the specified type that is initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * with the specified parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * <p> A new TerminalFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * TerminalFactorySpi implementation from the specified provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * is returned. Note that the specified provider object does not have to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * <p>The <code>TerminalFactory</code> is initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * specified parameters Object. The type of parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * needed may vary between different types of <code>TerminalFactory</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @param type the type of the requested TerminalFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @param params the parameters to pass to the TerminalFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *   implementation, or null if no parameters are needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @return a TerminalFactory of the specified type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @throws NullPointerException if type is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @throws IllegalArgumentException if provider is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @throws NoSuchAlgorithmException if a TerminalFactorySpi implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *   of the specified type is not available from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public static TerminalFactory getInstance(String type, Object params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            Provider provider) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        Instance instance = GetInstance.getInstance("TerminalFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            TerminalFactorySpi.class, type, params, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return new TerminalFactory((TerminalFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Returns the provider of this TerminalFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @return the provider of this TerminalFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Returns the type of this TerminalFactory. This is the value that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * specified in the getInstance() method that returned this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @return the type of this TerminalFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Returns a new CardTerminals object encapsulating the terminals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * supported by this factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * See the class comment of the {@linkplain CardTerminals} class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * regarding how the returned objects can be shared and reused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @return a new CardTerminals object encapsulating the terminals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * supported by this factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public CardTerminals terminals() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return spi.engineTerminals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * Returns a string representation of this TerminalFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @return a string representation of this TerminalFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return "TerminalFactory for type " + type + " from provider "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            + provider.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
}