com.ibm.opencard.terminal.pcsc10
Class Pcsc10LockableTerminal

java.lang.Object
  extended by opencard.core.terminal.CardTerminal
      extended by opencard.opt.terminal.AbstractLockableTerminal
          extended by com.ibm.opencard.terminal.pcsc10.Pcsc10LockableTerminal
All Implemented Interfaces:
Pollable, Lockable, TerminalCommand

public final class Pcsc10LockableTerminal
extends AbstractLockableTerminal
implements TerminalCommand, Pollable

Implementation of a lockable OpenCard CardTerminal for PCSC.

Version:
$Id: Pcsc10LockableTerminal.java,v 1.2 2005/09/19 10:21:22 asc Exp $
Author:
Peter Bendel (peter_bendel@de.ibm.com)
See Also:
AbstractLockableTerminal

Field Summary
 
Fields inherited from class opencard.core.terminal.CardTerminal
address, name, slots, type
 
Constructor Summary
protected Pcsc10LockableTerminal(java.lang.String name, java.lang.String type, java.lang.String address)
          Instantiate an Pcsc10Terminal.
 
Method Summary
protected  void cardRemoved(int slotID)
          Signal to observers that an inserted card was removed.
 void close()
          Close the connection to the card terminal.
 CardID getCardID(int slot)
          Return the CardID of the presently inserted card.
 CardID getCardID(int slot, int timeout)
          Deprecated.  
protected  void internalCloseSlotChannel(SlotChannel sc)
          The internal closeSlotChannel method.
protected  java.util.Properties internalFeatures(java.util.Properties features)
          Query the card terminal about its features.
protected  void internalLock()
           
protected  void internalLockSlot(int slotNr)
           
protected  CardID internalReset(int slot, int ms)
          Implementation of CardTerminal.internalReset().
protected  ResponseAPDU internalSendAPDU(int slot, CommandAPDU capdu, int ms)
          The implementation of CardTerminal.internalSendAPDU().
protected  void internalUnlock()
           
protected  void internalUnlockSlot(int slotNr)
           
 boolean isCardPresent(int slot)
          Check whether there is a smart card present.
protected  void lockableOpenSlotChannel(int slotID)
          The internal openSlotChannel method.
 void open()
          Open the card terminal: We register with the CardTerminalRegistry as a Pollable card terminal.
 void poll()
          This method is normally used by the CardTerminalRegistry to generate the OpenCard events if the Slot implementation does not support events itself.
 byte[] sendTerminalCommand(byte[] cmd)
          Send control command to terminal.
 byte[] sendTerminalCommand(byte[] cmd, java.lang.Object lockHandle)
          Send control command to terminal.
protected  CardTerminalException translatePcscException(PcscException e)
          translate the PcscException into CardTerminalException.
 
Methods inherited from class opencard.opt.terminal.AbstractLockableTerminal
getSlotLockHandle, getTerminalLockHandle, internalOpenSlotChannel, internalOpenSlotChannel, lock, lockSlot, unlock, unlockSlot
 
Methods inherited from class opencard.core.terminal.CardTerminal
addSlots, cardInserted, closeSlotChannel, enumerateSlots, features, getAddress, getName, getSlot, getSlots, getType, internalReset, isCardPresent, isSlotChannelAvailable, isSlotChannelAvailable, openSlotChannel, openSlotChannel, openSlotChannel, reset, reset, reset, sendAPDU, sendAPDU, sendVerifiedCommandAPDU, slots, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pcsc10LockableTerminal

protected Pcsc10LockableTerminal(java.lang.String name,
                                 java.lang.String type,
                                 java.lang.String address)
                          throws CardTerminalException
Instantiate an Pcsc10Terminal.

Parameters:
name - The user friendly name.
type - The terminal type (here "PCSC")
address - not used
Throws:
CardTerminalException - Thrown when a problem occured.
Method Detail

open

public void open()
          throws CardTerminalException
Open the card terminal: We register with the CardTerminalRegistry as a Pollable card terminal.

Specified by:
open in class CardTerminal
Throws:
CardTerminalException - thrown in case of initialization-errors (e.g. couldn't setup transfer protocol between CardTerminal and reader).

close

public void close()
           throws CardTerminalException
Close the connection to the card terminal. Could be used by unregister to free up the resources used by the terminal.

Specified by:
close in class CardTerminal
Throws:
CardTerminalException - Thrown if there are problems with closing the connection

internalReset

protected CardID internalReset(int slot,
                               int ms)
                        throws CardTerminalException
Implementation of CardTerminal.internalReset().

Specified by:
internalReset in class CardTerminal
Parameters:
slot - The slot number of the slot to be resetted.
ms - To be ignored. If the card does not respond within the time specified for the protocol an exception should be thrown.
Returns:
The CardID of the card.
Throws:
CardTerminalException - thrown in case of errors during reset

internalFeatures

protected java.util.Properties internalFeatures(java.util.Properties features)
Query the card terminal about its features.

Overrides:
internalFeatures in class CardTerminal
Parameters:
features - A Properties object that needs to be enhanced with the card terminal specific features.
Returns:
features

isCardPresent

public boolean isCardPresent(int slot)
                      throws CardTerminalException
Check whether there is a smart card present.

Specified by:
isCardPresent in class CardTerminal
Parameters:
slot - Number of the slot to check (must be 0 for PCSC)
Returns:
True if there is a smart card inserted in the card terminals slot.
Throws:
CardTerminalException - thrown in case of problems getting the status from CardTerminal (or other serious problems in the terminal).

getCardID

public CardID getCardID(int slot,
                        int timeout)
                 throws CardTerminalException
Deprecated. 

Overrides:
getCardID in class CardTerminal
Throws:
CardTerminalException

getCardID

public CardID getCardID(int slot)
                 throws CardTerminalException
Return the CardID of the presently inserted card. Will returned the cached card if slot's status has not changed; otherwise it will really retrieve the CardID.

Specified by:
getCardID in class CardTerminal
Parameters:
slot - slot number
Returns:
A CardID object representing the inserted smart card.
Throws:
CardTerminalException - thrown when problem occured getting the ATR of the card

lockableOpenSlotChannel

protected void lockableOpenSlotChannel(int slotID)
                                throws CardTerminalException
The internal openSlotChannel method. lockableOpenSlotChannel is executed at the beginning of openSlotChannel.

Specified by:
lockableOpenSlotChannel in class AbstractLockableTerminal
Parameters:
slotID - The number of the slot for which a SlotChannel is requested.
Throws:
CardTerminalException

internalCloseSlotChannel

protected void internalCloseSlotChannel(SlotChannel sc)
                                 throws CardTerminalException
The internal closeSlotChannel method. internalCloseSlotChannel is executed at the end of closeSlotChannel.

Overrides:
internalCloseSlotChannel in class CardTerminal
Parameters:
sc - The SlotChannel to close.
Throws:
CardTerminalException - thrown in case of errors closing the card (e.g. error disconnecting the card).

sendTerminalCommand

public byte[] sendTerminalCommand(byte[] cmd)
                           throws CardTerminalException
Send control command to terminal.

Specified by:
sendTerminalCommand in interface TerminalCommand
Parameters:
cmd - a byte array containing the command to be sent to the card terminal
Returns:
Response from terminal.
Throws:
CardTerminalException - Exception thrown by driver.
See Also:
TerminalCommand

sendTerminalCommand

public byte[] sendTerminalCommand(byte[] cmd,
                                  java.lang.Object lockHandle)
                           throws CardTerminalException
Send control command to terminal.

Parameters:
cmd - a byte array containing the command to be sent to the card terminal
Returns:
Response from terminal.
Throws:
CardTerminalException - Exception thrown by driver.
See Also:
TerminalCommand

internalSendAPDU

protected ResponseAPDU internalSendAPDU(int slot,
                                        CommandAPDU capdu,
                                        int ms)
                                 throws CardTerminalException
The implementation of CardTerminal.internalSendAPDU().

Specified by:
internalSendAPDU in class CardTerminal
Parameters:
slot - logical slot number
capdu - C-APDU to send to the card
ms - timeout in ms (not supported, ignored)
Returns:
A ResponseAPDU.
Throws:
CardTerminalException - thrown in case of errors in the CardTerminal (e.g. errors during data exchange)

cardRemoved

protected void cardRemoved(int slotID)
Signal to observers that an inserted card was removed.

Overrides:
cardRemoved in class CardTerminal
Parameters:
slotID - slot number

poll

public void poll()
          throws CardTerminalException
This method is normally used by the CardTerminalRegistry to generate the OpenCard events if the Slot implementation does not support events itself.

Specified by:
poll in interface Pollable
Throws:
CardTerminalException - Thrown when error occurred in poll-mechanism.

translatePcscException

protected CardTerminalException translatePcscException(PcscException e)
translate the PcscException into CardTerminalException.


internalLock

protected void internalLock()
                     throws CardTerminalException
Specified by:
internalLock in class AbstractLockableTerminal
Throws:
CardTerminalException

internalUnlock

protected void internalUnlock()
                       throws CardTerminalException
Specified by:
internalUnlock in class AbstractLockableTerminal
Throws:
CardTerminalException

internalLockSlot

protected void internalLockSlot(int slotNr)
                         throws CardTerminalException
Specified by:
internalLockSlot in class AbstractLockableTerminal
Throws:
CardTerminalException

internalUnlockSlot

protected void internalUnlockSlot(int slotNr)
                           throws CardTerminalException
Specified by:
internalUnlockSlot in class AbstractLockableTerminal
Throws:
CardTerminalException