J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package javax.smartcardio; |
| 27 | |
| 28 | import java.util.*; |
| 29 | |
| 30 | /** |
| 31 | * A Smart Card terminal, sometimes refered to as a Smart Card Reader. |
| 32 | * A CardTerminal object can be obtained by calling |
| 33 | * {@linkplain CardTerminals#list} |
| 34 | * or {@linkplain CardTerminals#getTerminal CardTerminals.getTerminal()}. |
| 35 | * |
| 36 | * <p>Note that physical card readers with slots for multiple cards are |
| 37 | * represented by one <code>CardTerminal</code> object per such slot. |
| 38 | * |
| 39 | * @see CardTerminals |
| 40 | * @see TerminalFactory |
| 41 | * |
| 42 | * @since 1.6 |
| 43 | * @author Andreas Sterbenz |
| 44 | * @author JSR 268 Expert Group |
| 45 | */ |
| 46 | public abstract class CardTerminal { |
| 47 | |
| 48 | /** |
| 49 | * Constructs a new CardTerminal object. |
| 50 | * |
| 51 | * <p>This constructor is called by subclasses only. Application should |
| 52 | * call {@linkplain CardTerminals#list list()} |
| 53 | * or {@linkplain CardTerminals#getTerminal getTerminal()} |
| 54 | * to obtain a CardTerminal object. |
| 55 | */ |
| 56 | protected CardTerminal() { |
| 57 | // empty |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns the unique name of this terminal. |
| 62 | * |
| 63 | * @return the unique name of this terminal. |
| 64 | */ |
| 65 | public abstract String getName(); |
| 66 | |
| 67 | /** |
| 68 | * Establishes a connection to the card. |
| 69 | * If a connection has previously established using |
| 70 | * the specified protocol, this method returns the same Card object as |
| 71 | * the previous call. |
| 72 | * |
| 73 | * @param protocol the protocol to use ("T=0", "T=1", or "T=CL"), or "*" to |
| 74 | * connect using any available protocol. |
| 75 | * |
| 76 | * @throws NullPointerException if protocol is null |
| 77 | * @throws IllegalArgumentException if protocol is an invalid protocol |
| 78 | * specification |
| 79 | * @throws CardNotPresentException if no card is present in this terminal |
| 80 | * @throws CardException if a connection could not be established |
| 81 | * using the specified protocol or if a connection has previously been |
| 82 | * established using a different protocol |
| 83 | * @throws SecurityException if a SecurityManager exists and the |
| 84 | * caller does not have the required |
| 85 | * {@linkplain CardPermission permission} |
| 86 | */ |
| 87 | public abstract Card connect(String protocol) throws CardException; |
| 88 | |
| 89 | /** |
| 90 | * Returns whether a card is present in this terminal. |
| 91 | * |
| 92 | * @return whether a card is present in this terminal. |
| 93 | * |
| 94 | * @throws CardException if the status could not be determined |
| 95 | */ |
| 96 | public abstract boolean isCardPresent() throws CardException; |
| 97 | |
| 98 | /** |
| 99 | * Waits until a card is present in this terminal or the timeout |
| 100 | * expires. If the method returns due to an expired timeout, it returns |
| 101 | * false. Otherwise it return true. |
| 102 | * |
| 103 | * <P>If a card is present in this terminal when this |
| 104 | * method is called, it returns immediately. |
| 105 | * |
| 106 | * @param timeout if positive, block for up to <code>timeout</code> |
| 107 | * milliseconds; if zero, block indefinitely; must not be negative |
| 108 | * @return false if the method returns due to an expired timeout, |
| 109 | * true otherwise. |
| 110 | * |
| 111 | * @throws IllegalArgumentException if timeout is negative |
| 112 | * @throws CardException if the operation failed |
| 113 | */ |
| 114 | public abstract boolean waitForCardPresent(long timeout) throws CardException; |
| 115 | |
| 116 | /** |
| 117 | * Waits until a card is absent in this terminal or the timeout |
| 118 | * expires. If the method returns due to an expired timeout, it returns |
| 119 | * false. Otherwise it return true. |
| 120 | * |
| 121 | * <P>If no card is present in this terminal when this |
| 122 | * method is called, it returns immediately. |
| 123 | * |
| 124 | * @param timeout if positive, block for up to <code>timeout</code> |
| 125 | * milliseconds; if zero, block indefinitely; must not be negative |
| 126 | * @return false if the method returns due to an expired timeout, |
| 127 | * true otherwise. |
| 128 | * |
| 129 | * @throws IllegalArgumentException if timeout is negative |
| 130 | * @throws CardException if the operation failed |
| 131 | */ |
| 132 | public abstract boolean waitForCardAbsent(long timeout) throws CardException; |
| 133 | |
| 134 | } |