- java.lang.Object
-
- javax.smartcardio.CardTerminals
-
public abstract class CardTerminals extends Object
The set of terminals supported by a TerminalFactory. This class allows applications to enumerate the available CardTerminals, obtain a specific CardTerminal, or wait for the insertion or removal of cards.This class is multi-threading safe and can be used by multiple threads concurrently. However, this object keeps track of the card presence state of each of its terminals. Multiple objects should be used if independent calls to waitForChange() are required.
Applications can obtain instances of this class by calling TerminalFactory.terminals().
- Since:
- 1.6
- See Also:
TerminalFactory
,CardTerminal
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CardTerminals.State
Enumeration of attributes of a CardTerminal.
-
Constructor Summary
Constructors Modifier Constructor Description protected
CardTerminals()
Constructs a new CardTerminals object.
-
Method Summary
Modifier and Type Method Description CardTerminal
getTerminal(String name)
Returns the terminal with the specified name or null if no such terminal exists.List<CardTerminal>
list()
Returns an unmodifiable list of all available terminals.abstract List<CardTerminal>
list(CardTerminals.State state)
Returns an unmodifiable list of all terminals matching the specified state.void
waitForChange()
Waits for card insertion or removal in any of the terminals of this object.abstract boolean
waitForChange(long timeout)
Waits for card insertion or removal in any of the terminals of this object or until the timeout expires.
-
-
-
Constructor Detail
-
CardTerminals
protected CardTerminals()
Constructs a new CardTerminals object.This constructor is called by subclasses only. Application should call TerminalFactory.terminals() to obtain a CardTerminals object.
-
-
Method Detail
-
list
public List<CardTerminal> list() throws CardException
Returns an unmodifiable list of all available terminals.- Returns:
- an unmodifiable list of all available terminals.
- Throws:
CardException
- if the card operation failed
-
list
public abstract List<CardTerminal> list(CardTerminals.State state) throws CardException
Returns an unmodifiable list of all terminals matching the specified state.If state is
State.ALL
, this method returns all CardTerminals encapsulated by this object. If state isState.CARD_PRESENT
orState.CARD_ABSENT
, it returns all CardTerminals where a card is currently present or absent, respectively.If state is
State.CARD_INSERTION
orState.CARD_REMOVAL
, it returns all CardTerminals for which an insertion (or removal, respectively) was detected during the last call to waitForChange(). IfwaitForChange()
has not been called on this object,CARD_INSERTION
is equivalent toCARD_PRESENT
andCARD_REMOVAL
is equivalent toCARD_ABSENT
. For an example of the use ofCARD_INSERTION
, seewaitForChange()
.- Parameters:
state
- the State- Returns:
- an unmodifiable list of all terminals matching the specified state.
- Throws:
NullPointerException
- if state is nullCardException
- if the card operation failed
-
getTerminal
public CardTerminal getTerminal(String name)
Returns the terminal with the specified name or null if no such terminal exists.- Parameters:
name
- the terminal name- Returns:
- the terminal with the specified name or null if no such terminal exists.
- Throws:
NullPointerException
- if name is null
-
waitForChange
public void waitForChange() throws CardException
Waits for card insertion or removal in any of the terminals of this object.This call is equivalent to calling waitForChange(0).
- Throws:
IllegalStateException
- if thisCardTerminals
object does not contain any terminalsCardException
- if the card operation failed
-
waitForChange
public abstract boolean waitForChange(long timeout) throws CardException
Waits for card insertion or removal in any of the terminals of this object or until the timeout expires.This method examines each CardTerminal of this object. If a card was inserted into or removed from a CardTerminal since the previous call to
waitForChange()
, it returns immediately. Otherwise, or if this is the first call towaitForChange()
on this object, it blocks until a card is inserted into or removed from a CardTerminal.If
timeout
is greater than 0, the method returns aftertimeout
milliseconds even if there is no change in state. In that case, this method returnsfalse
; otherwise it returnstrue
.This method is often used in a loop in combination with
list(State.CARD_INSERTION)
, for example:TerminalFactory factory = ...; CardTerminals terminals = factory.terminals(); while (true) { for (CardTerminal terminal : terminals.list(CARD_INSERTION)) { // examine Card in terminal, return if it matches } terminals.waitForChange(); }
- Parameters:
timeout
- if positive, block for up totimeout
milliseconds; if zero, block indefinitely; must not be negative- Returns:
- false if the method returns due to an expired timeout, true otherwise.
- Throws:
IllegalStateException
- if thisCardTerminals
object does not contain any terminalsIllegalArgumentException
- if timeout is negativeCardException
- if the card operation failed
-
-