com.ibm.jc.terminal
Class TraceJCTerminal

java.lang.Object
  extended bycom.ibm.jc.JCTerminal
      extended bycom.ibm.jc.terminal.TraceJCTerminal

public class TraceJCTerminal
extends JCTerminal


Field Summary
 
Fields inherited from class com.ibm.jc.JCTerminal
CARD_PRESENT, ERROR, NOT_CONNECTED, PROTOCOL_T0, PROTOCOL_T1, PROTOCOL_TCL, SLOT_EMPTY
 
Constructor Summary
TraceJCTerminal()
          Default constructor for generic instanciation.
 
Method Summary
 void close()
          Close connection to card terminal.
 JCTerminal filterFor()
          Determine if terminal is a filter.
 JCTerminal filterFor(JCTerminal term)
          Attache some terminal to this terminal filter.
 void generateParityError(int n)
          Schedule generation of parity error for the n-th character to be transmitted (in or out).
 java.lang.String getErrorMessage()
           
 byte[] getLastResponse()
           
 java.io.PrintWriter getLog()
          Get the log stream where traces are sent to (or null).
 int getState()
           
 JCTerminal init(java.lang.Object param)
          Initialize trace terminal with the terminal that is being traced.
 byte[] ioctl(int req, byte[] param, int off, int len)
          Perform terminal-dependent action...
 void open()
          Open the card terminal.
 void pps(int proto, int param)
          Select protocol and parameters for subsequent communication (can only be applied immediately after card reset).
 byte[] send(int nad, byte[] toSend, int offset, int len)
          Send data to the card (using the negotiated protocol).
 byte[] sendraw(byte[] toSend, int offset, int len, int timeout)
          Send data to the card (using *no* protocol, raw bytes are transmitted without modification).
 java.io.PrintWriter setLog(java.io.PrintWriter w)
          Set the log stream where traces are sent to.
 void setLogLines(int lines)
          Set number of log lines.
 byte[] waitForCard(int time)
          Wait for insertion of a card and return ATR (answer to reset).
 
Methods inherited from class com.ibm.jc.JCTerminal
getInstance, send, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TraceJCTerminal

public TraceJCTerminal()
Default constructor for generic instanciation.

Method Detail

setLog

public java.io.PrintWriter setLog(java.io.PrintWriter w)
Set the log stream where traces are sent to. By default traces are sent to System.err.

Parameters:
w - log Stream or null. Null turns logging off.
Returns:
previous log Stream.

getLog

public java.io.PrintWriter getLog()
Get the log stream where traces are sent to (or null).

Returns:
log Stream or null.

setLogLines

public void setLogLines(int lines)
Set number of log lines. At most this number of lines are printed for each APDU. Each lines has at most 16 bytes of data.


filterFor

public JCTerminal filterFor()
Description copied from class: JCTerminal
Determine if terminal is a filter. A filter modifies, traces, or otherwise processes invocations to some underlying terminal.

Overrides:
filterFor in class JCTerminal
Returns:
traced terminal

getLastResponse

public byte[] getLastResponse()

filterFor

public JCTerminal filterFor(JCTerminal term)
Description copied from class: JCTerminal
Attache some terminal to this terminal filter. The default implementation throws an exception. Terminal filter classes must override this method.

Overrides:
filterFor in class JCTerminal
Returns:
previous underlying terminal.

init

public JCTerminal init(java.lang.Object param)
Initialize trace terminal with the terminal that is being traced. The previous terminal will be closed.

Overrides:
init in class JCTerminal
Parameters:
param - either an initialized JCTerminal instance or a string of the form "term:param". The part term is passed JCTerminal,getInstance() to create the observed terminal and param is used to initialize it.
Returns:
this

open

public void open()
Description copied from class: JCTerminal
Open the card terminal. Access to the terminal by other processes usually is not possible anylonger.

Specified by:
open in class JCTerminal

close

public void close()
Description copied from class: JCTerminal
Close connection to card terminal. The caller can reconnect to the terminal using the open() method.

Specified by:
close in class JCTerminal
See Also:
JCTerminal.open()

waitForCard

public byte[] waitForCard(int time)
Description copied from class: JCTerminal
Wait for insertion of a card and return ATR (answer to reset). If a card is already inserted this explicitly resets the card and returns the ATR. If no card is inserted the call blocks for a specified amount of time.

Note, not all terminals support the time parameter. It is only guaranteed that the call will not block longer than the specified time. It might return immediately with null.

Specified by:
waitForCard in class JCTerminal
Parameters:
time - the calls blocks for specified milliseconds.
Returns:
ATR (answer to reset) or null if no ATR could be retrieved. The reason might be that no card is inserted or because of communication problems.

getErrorMessage

public java.lang.String getErrorMessage()
Overrides:
getErrorMessage in class JCTerminal
Returns:
a description of the last error. If not error is registered or if there is not verbose description a null value is returned. This default implementation returns null.

getState

public int getState()
Specified by:
getState in class JCTerminal
Returns:
the status of the terminal. See constants. The status condition of the last call to the terminal.

send

public byte[] send(int nad,
                   byte[] toSend,
                   int offset,
                   int len)
Description copied from class: JCTerminal
Send data to the card (using the negotiated protocol). (To make applications independent of logical channels JCard.send() should be used)

Specified by:
send in class JCTerminal
Parameters:
nad - node address to which data is being sent (high nibble = destination address, low = source address). Address values: 2=host, 1=terminal, 0=card. A value of 0 means from host to card.
toSend - byte array containing APDU data to be sent
offset - offset starting at which APDU data sending is to begin
len - number of bytes to be transmitted
Returns:
response APDU as a byte array
See Also:
com.ibm.jc.JCard.send

sendraw

public byte[] sendraw(byte[] toSend,
                      int offset,
                      int len,
                      int timeout)
Description copied from class: JCTerminal
Send data to the card (using *no* protocol, raw bytes are transmitted without modification).

Overrides:
sendraw in class JCTerminal
Parameters:
toSend - byte array containing raw data to be sent
offset - offset starting at which raw data sending is to begin
len - number of bytes to be transmitted
timeout - time to wait for response data (time unit is device-dependent, ignored by some readers)
Returns:
raw response data

pps

public void pps(int proto,
                int param)
Description copied from class: JCTerminal
Select protocol and parameters for subsequent communication (can only be applied immediately after card reset).

Overrides:
pps in class JCTerminal
Parameters:
proto - protocol type to be used (PROTOCOL_T0 or PROTOCOL_T1 in contact mode, PROTOCOL_TCL in contact-less mode)
param - baud rate
See Also:
PROTOCOL_T0, PROTOCOL_T1, PROTOCOL_TCL, send

generateParityError

public void generateParityError(int n)
Description copied from class: JCTerminal
Schedule generation of parity error for the n-th character to be transmitted (in or out).

Overrides:
generateParityError in class JCTerminal
Parameters:
n - index of character to manipulate (0-based)

ioctl

public byte[] ioctl(int req,
                    byte[] param,
                    int off,
                    int len)
Description copied from class: JCTerminal
Perform terminal-dependent action...

Overrides:
ioctl in class JCTerminal
Parameters:
req - request code
param - array holding request parameters (may be null)
off - offset to parameters
len - length of parameters
Returns:
array holding the request response