jdk/src/share/classes/javax/smartcardio/TerminalFactory.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * A factory for CardTerminal objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * It allows an application to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <li>obtain a TerminalFactory by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * one of the static factory methods in this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * ({@linkplain #getDefault} or {@linkplain #getInstance getInstance()}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <li>use this TerminalFactory object to access the CardTerminals by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * calling the {@linkplain #terminals} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>Each TerminalFactory has a <code>type</code> indicating how it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * was implemented. It must be specified when the implementation is obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * using a {@linkplain #getInstance getInstance()} method and can be retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * via the {@linkplain #getType} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <P>The following standard type names have been defined:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <dt><code>PC/SC</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <dd>an implementation that calls into the PC/SC Smart Card stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * of the host platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Implementations do not require parameters and accept "null" as argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * in the getInstance() calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <dt><code>None</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <dd>an implementation that does not supply any CardTerminals. On platforms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * that do not support other implementations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * {@linkplain #getDefaultType} returns <code>None</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * {@linkplain #getDefault} returns an instance of a <code>None</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * TerminalFactory. Factories of this type cannot be obtained by calling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <code>getInstance()</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * Additional standard types may be defined in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p><strong>Note:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Provider implementations that accept initialization parameters via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <code>getInstance()</code> methods are strongly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * encouraged to use a {@linkplain java.util.Properties} object as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * representation for String name-value pair based parameters whenever
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * possible. This allows applications to more easily interoperate with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * multiple providers than if each provider used different provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * specific class as parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <P>TerminalFactory utilizes an extensible service provider framework.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * Service providers that wish to add a new implementation should see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * {@linkplain TerminalFactorySpi} class for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @see CardTerminals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @author  JSR 268 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
public final class TerminalFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private final static String PROP_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                        "javax.smartcardio.TerminalFactory.DefaultType";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private final static String defaultType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private final static TerminalFactory defaultFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // lookup up the user specified type, default to PC/SC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        String type = AccessController.doPrivileged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                            (new GetPropertyAction(PROP_NAME, "PC/SC")).trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        TerminalFactory factory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            factory = TerminalFactory.getInstance(type, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (factory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            // if that did not work, try the Sun PC/SC factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                type = "PC/SC";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                Provider sun = Security.getProvider("SunPCSC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                if (sun == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    Class clazz = Class.forName("sun.security.smartcardio.SunPCSC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    sun = (Provider)clazz.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                factory = TerminalFactory.getInstance(type, null, sun);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (factory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            type = "None";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            factory = new TerminalFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                        (NoneFactorySpi.INSTANCE, NoneProvider.INSTANCE, "None");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        defaultType = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        defaultFactory = factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private static final class NoneProvider extends Provider {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        final static Provider INSTANCE = new NoneProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        private NoneProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            super("None", 1.0d, "none");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private static final class NoneFactorySpi extends TerminalFactorySpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        final static TerminalFactorySpi INSTANCE = new NoneFactorySpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        private NoneFactorySpi() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        protected CardTerminals engineTerminals() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            return NoneCardTerminals.INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private static final class NoneCardTerminals extends CardTerminals {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        final static CardTerminals INSTANCE = new NoneCardTerminals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        private NoneCardTerminals() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        public List<CardTerminal> list(State state) throws CardException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            if (state == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return Collections.emptyList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        public boolean waitForChange(long timeout) throws CardException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            throw new IllegalStateException("no terminals");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private final TerminalFactorySpi spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private final Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private final String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    private TerminalFactory(TerminalFactorySpi spi, Provider provider, String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        this.spi = spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Get the default TerminalFactory type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * <p>It is determined as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * when this class is initialized, the system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <code>javax.smartcardio.TerminalFactory.DefaultType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * is examined. If it is set, a TerminalFactory of this type is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * instantiated by calling the {@linkplain #getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * getInstance(String,Object)} method passing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * <code>null</code> as the value for <code>params</code>. If the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * succeeds, the type becomes the default type and the factory becomes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * the {@linkplain #getDefault default} factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * <p>If the system property is not set or the getInstance() call fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * for any reason, the system defaults to an implementation specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * default type and TerminalFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @return the default TerminalFactory type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public static String getDefaultType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return defaultType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Returns the default TerminalFactory instance. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * {@linkplain #getDefaultType} for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * <p>A default TerminalFactory is always available. However, depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * on the implementation, it may not offer any terminals.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @return the default TerminalFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public static TerminalFactory getDefault() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return defaultFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Returns a TerminalFactory of the specified type that is initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * with the specified parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * A new TerminalFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * TerminalFactorySpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Provider that supports the specified type is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * the {@linkplain Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <p>The <code>TerminalFactory</code> is initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * specified parameters Object. The type of parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * needed may vary between different types of <code>TerminalFactory</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param type the type of the requested TerminalFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param params the parameters to pass to the TerminalFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *   implementation, or null if no parameters are needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @return a TerminalFactory of the specified type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @throws NullPointerException if type is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @throws NoSuchAlgorithmException if no Provider supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *   TerminalFactorySpi of the specified type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public static TerminalFactory getInstance(String type, Object params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        Instance instance = GetInstance.getInstance("TerminalFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            TerminalFactorySpi.class, type, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return new TerminalFactory((TerminalFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Returns a TerminalFactory of the specified type that is initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * with the specified parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <p> A new TerminalFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * TerminalFactorySpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * the {@linkplain Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <p>The <code>TerminalFactory</code> is initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * specified parameters Object. The type of parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * needed may vary between different types of <code>TerminalFactory</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param type the type of the requested TerminalFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param params the parameters to pass to the TerminalFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *   implementation, or null if no parameters are needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param provider the name of the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @return a TerminalFactory of the specified type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @throws NullPointerException if type is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @throws IllegalArgumentException if provider is null or the empty String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @throws NoSuchAlgorithmException if a TerminalFactorySpi implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *   of the specified type is not available from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @throws NoSuchAlgorithmException if no TerminalFactory of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *   specified type could be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @throws NoSuchProviderException if the specified provider could not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *   be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public static TerminalFactory getInstance(String type, Object params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            String provider) throws NoSuchAlgorithmException, NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        Instance instance = GetInstance.getInstance("TerminalFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            TerminalFactorySpi.class, type, params, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return new TerminalFactory((TerminalFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Returns a TerminalFactory of the specified type that is initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * with the specified parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * <p> A new TerminalFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * TerminalFactorySpi implementation from the specified provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * is returned. Note that the specified provider object does not have to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * <p>The <code>TerminalFactory</code> is initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * specified parameters Object. The type of parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * needed may vary between different types of <code>TerminalFactory</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @param type the type of the requested TerminalFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @param params the parameters to pass to the TerminalFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *   implementation, or null if no parameters are needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @return a TerminalFactory of the specified type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @throws NullPointerException if type is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @throws IllegalArgumentException if provider is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @throws NoSuchAlgorithmException if a TerminalFactorySpi implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *   of the specified type is not available from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public static TerminalFactory getInstance(String type, Object params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            Provider provider) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        Instance instance = GetInstance.getInstance("TerminalFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            TerminalFactorySpi.class, type, params, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return new TerminalFactory((TerminalFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * Returns the provider of this TerminalFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @return the provider of this TerminalFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return provider;
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 type of this TerminalFactory. This is the value that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * specified in the getInstance() method that returned this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @return the type of this TerminalFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Returns a new CardTerminals object encapsulating the terminals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * supported by this factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * See the class comment of the {@linkplain CardTerminals} class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * regarding how the returned objects can be shared and reused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @return a new CardTerminals object encapsulating the terminals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * supported by this factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public CardTerminals terminals() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return spi.engineTerminals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Returns a string representation of this TerminalFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @return a string representation of this TerminalFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return "TerminalFactory for type " + type + " from provider "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            + provider.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
}