APIdia Launch Partner
Top Description Inners Constructors Methods
javax.smartcardio

public abstract Class CardTerminals

extends Object
Class Inheritance
Known Direct Subclasses
javax.smartcardio.TerminalFactory.NoneCardTerminals, sun.security.smartcardio.PCSCTerminals
Imports
java.util.*

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.

Authors
Andreas Sterbenz, JSR 268 Expert Group
Since
1.6
See Also
TerminalFactory, CardTerminal

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
CardTerminals.State

Enumeration of attributes of a CardTerminal.

Constructor Summary

AccessConstructor and Description
protected
CardTerminals()

Constructs a new CardTerminals object.

Method Summary

Modifier and TypeMethod and Description
public CardTerminal

Returns:

the terminal with the specified name or null if no such terminal exists.
getTerminal
(String
the terminal name
name
)

Returns the terminal with the specified name or null if no such terminal exists.

public List<CardTerminal>

Returns:

an unmodifiable list of all available terminals.
list
()

Returns an unmodifiable list of all available terminals.

public abstract List<CardTerminal>

Returns:

an unmodifiable list of all terminals matching the specified state.
list
(CardTerminals.State
the State
state
)

Returns an unmodifiable list of all terminals matching the specified state.

public void
waitForChange()

Waits for card insertion or removal in any of the terminals of this object.

public abstract boolean

Returns:

false if the method returns due to an expired timeout, true otherwise.
waitForChange
(long
if positive, block for up to timeout milliseconds; if zero, block indefinitely; must not be negative
timeout
)

Waits for card insertion or removal in any of the terminals of this object or until the timeout expires.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CardTerminalsback to summary
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

getTerminalback to summary
public CardTerminal getTerminal(String name)

Returns the terminal with the specified name or null if no such terminal exists.

Parameters
name:String

the terminal name

Returns:CardTerminal

the terminal with the specified name or null if no such terminal exists.

Exceptions
NullPointerException:
if name is null
listback to summary
public List<CardTerminal> list() throws CardException

Returns an unmodifiable list of all available terminals.

Returns:List<CardTerminal>

an unmodifiable list of all available terminals.

Exceptions
CardException:
if the card operation failed
listback to summary
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 is State.CARD_PRESENT or State.CARD_ABSENT, it returns all CardTerminals where a card is currently present or absent, respectively.

If state is State.CARD_INSERTION or State.CARD_REMOVAL, it returns all CardTerminals for which an insertion (or removal, respectively) was detected during the last call to waitForChange. If waitForChange() has not been called on this object, CARD_INSERTION is equivalent to CARD_PRESENT and CARD_REMOVAL is equivalent to CARD_ABSENT. For an example of the use of CARD_INSERTION, see waitForChange.

Parameters
state:CardTerminals.State

the State

Returns:List<CardTerminal>

an unmodifiable list of all terminals matching the specified state.

Exceptions
CardException:
if the card operation failed
NullPointerException:
if state is null
waitForChangeback to summary
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).

Exceptions
CardException:
if the card operation failed
IllegalStateException:
if this CardTerminals object does not contain any terminals
waitForChangeback to summary
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 to waitForChange() 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 after timeout milliseconds even if there is no change in state. In that case, this method returns false; otherwise it returns true.

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:long

if positive, block for up to timeout milliseconds; if zero, block indefinitely; must not be negative

Returns:boolean

false if the method returns due to an expired timeout, true otherwise.

Exceptions
CardException:
if the card operation failed
IllegalStateException:
if this CardTerminals object does not contain any terminals
IllegalArgumentException:
if timeout is negative
javax.smartcardio back to summary

public final Enum CardTerminals.State

extends Enum<CardTerminals.State>
Class Inheritance

Enumeration of attributes of a CardTerminal. It is used as a parameter to the CardTerminals#list method.
Since
1.6

Field Summary

Modifier and TypeField and Description
public static final CardTerminals.State
ALL

All CardTerminals.

public static final CardTerminals.State
CARD_ABSENT

CardTerminals in which a card is not present.

public static final CardTerminals.State
CARD_INSERTION

CardTerminals for which a card insertion was detected during the latest call to waitForChange().

public static final CardTerminals.State
CARD_PRESENT

CardTerminals in which a card is present.

public static final CardTerminals.State
CARD_REMOVAL

CardTerminals for which a card removal was detected during the latest call to waitForChange().

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static CardTerminals.State
public static CardTerminals.State[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ALLback to summary
public static final CardTerminals.State ALL

All CardTerminals.

CARD_ABSENTback to summary
public static final CardTerminals.State CARD_ABSENT

CardTerminals in which a card is not present.

CARD_INSERTIONback to summary
public static final CardTerminals.State CARD_INSERTION

CardTerminals for which a card insertion was detected during the latest call to waitForChange().

CARD_PRESENTback to summary
public static final CardTerminals.State CARD_PRESENT

CardTerminals in which a card is present.

CARD_REMOVALback to summary
public static final CardTerminals.State CARD_REMOVAL

CardTerminals for which a card removal was detected during the latest call to waitForChange().

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static CardTerminals.State valueOf(String name)
valuesback to summary
public static CardTerminals.State[] values()