FileDocCategorySizeDatePackage
AccessSATImpl.javaAPI DocphoneME MR2 API (J2ME)8593Wed May 02 18:00:40 BST 2007com.sun.satsa.gsmapplet

AccessSATImpl

public class AccessSATImpl extends Object implements sim.toolkit.AccessSAT
A class that implements the AccessSAT interface which allows the toolkit classes to access the APDUBuffer and do other functions on objects in the GSMApplet's context.

Fields Summary
static final short
MAX_BUFFER_LENGTH
Maximum length of in and out buffers
static final byte
MAX_LISTENERS
Maximum number of listeners allowed
short
outDataSize
Size used by the GSM applet to send data when responding to GET RESPONSE
public byte[]
inBuffer
Buffer that holds the data received from the terminal.
public byte[]
outBuffer
Buffer that holds the data to be sent to the terminal.
private byte[]
apduBuffer
Buffer that holds the APDU data.
private short
apduBufferLength
Length of APDU buffer.
public sim.toolkit.ToolkitInterface[]
tiList
A list of listeners for EVENT_SMS_PP_DATA_DOWNLOAD.
Constructors Summary
AccessSATImpl()
Constructor

    
          
     
        inBuffer = JCSystem.makeTransientByteArray(MAX_BUFFER_LENGTH, 
                                              JCSystem.CLEAR_ON_DESELECT);
        outBuffer = JCSystem.makeTransientByteArray(MAX_BUFFER_LENGTH, 
                                              JCSystem.CLEAR_ON_DESELECT);
        apduBuffer = JCSystem.makeTransientByteArray(MAX_BUFFER_LENGTH, 
                                              JCSystem.CLEAR_ON_DESELECT);
        tiList = new ToolkitInterface[MAX_LISTENERS];
    
Methods Summary
public voidclearEventListener(javacard.framework.AID aid)
Removes the event listener from the list of listeners.

param
aid applet AID

        ToolkitInterface ti = (ToolkitInterface)
                    JCSystem.getAppletShareableInterfaceObject(aid, (byte)0);
        if (ti == null) {
            return;
        }
        byte index = findListener(ti);
        if (index != (byte)-1) {
            // remove listener
            tiList[index] = null;
        }
    
private bytefindListener(sim.toolkit.ToolkitInterface ti)
Finds a listener in the list of listener

param
ti toolkit interface
return
index in the listener table

        for (byte i = 0; i < MAX_LISTENERS; i++) {
            if (tiList[i] != null) {
                if (tiList[i].equals(ti)) 
		    return i;
            }            
        }
        return (byte)-1;
    
public byte[]getAPDUBuffer()
Returns the APDUBuffer.

return
apdu buffer

        return apduBuffer;
    
public bytegetAPDUBufferByte(short index)
Gets one byte from the APDUBuffer.

param
index Index of requested byte in the buffer
return
requested byte

        if (index >= MAX_BUFFER_LENGTH || index >= apduBufferLength) {
            return (byte)0;
        } else {
            return apduBuffer[index];
        }
    
public shortgetAPDUBufferLength()
Gets the length of the APDUBuffer.

return
requested length

        return apduBufferLength;
    
public shortgetAPDUBufferMax()
Gets the maximum length of the APDUBuffer.

return
requested length

        return MAX_BUFFER_LENGTH;
    
public shortgetOutDataLength()
Returns the length of Data that has been set in the out buffer.

return
length of data

        return outDataSize;
    
public booleanisEventListenerSet(javacard.framework.AID aid)
Returns true if the applet corresponding to the AID passed to this method is found in the list of listeners.

param
aid applet AID
return
true if the applet is a listener and false otherwise

        ToolkitInterface ti = (ToolkitInterface)
                    JCSystem.getAppletShareableInterfaceObject(aid, (byte)0);
        if (ti == null) {
            return false;
        }
        byte index = findListener(ti);
        if (index != (byte)-1) {
            return true;
        }
        return false;
    
voidresetBuffers()
Resets the buffers and fields when a new envelope is received

        Util.arrayFillNonAtomic(inBuffer, (short)0, 
                                MAX_BUFFER_LENGTH, (byte)0);
        Util.arrayFillNonAtomic(outBuffer, (short)0, 
                                MAX_BUFFER_LENGTH, (byte)0);
        outDataSize = (short)0;         
        apduBufferLength = (short)0;
                       
    
public voidsetAPDUBuffer(byte[] buffer, short length)
Sets the APDUBuffer.

param
buffer apdu buffer
param
length length of apdu buffer

        Util.arrayCopyNonAtomic(buffer, (short)0, apduBuffer, (short)0, length);
        Util.arrayCopyNonAtomic(buffer, (short)0, inBuffer, (short)0, length);
        apduBufferLength = length;
    
public voidsetAPDUBufferByte(short index, byte value)
Sets one byte from the APDUBuffer.

param
index Index of byte in the buffer
param
value The value to be set

        if (index < MAX_BUFFER_LENGTH) {
            if (index > apduBufferLength) {
                apduBufferLength = index;
            }
            apduBuffer[index] = value;
        }
    
public voidsetEventListener(javacard.framework.AID aid)
Sets the event listener applet.

param
aid applet AID

        ToolkitInterface ti = (ToolkitInterface)
                    JCSystem.getAppletShareableInterfaceObject(aid, (byte)0);
        if (ti == null) {
            ToolkitException.throwIt(ToolkitException.BAD_INPUT_PARAMETER);
        }
        // if listener hasn't already registered, register it for this event
        if (findListener(ti) == (byte)-1) {
            for (short i = 0; i < MAX_LISTENERS; i++) {
                if (tiList[i] == null) {
                    tiList[i] = ti;
                    break;
                }
            }
        }
    
public voidsetOutBufferData(short length)
Sets the data in the out buffer.

param
length length of data

        byte[] buffer = apduBuffer;
        outDataSize = Util.arrayCopy(buffer, (short)0, 
                                                outBuffer, 
                                                outDataSize,
                                                length);
        // restore the bytes from the original command APDU in
        // the APDU buffer because the data recieved in the 
        // envelope is suppose to be available while
        // in processToolkit method
        Util.arrayCopy(inBuffer, (short)0, buffer, 
                        (short)0, (short)length);
    
public voidsetOutgoingAPDU()
This method is called by GSMApplet to set the data in the APDU buffer so that it can be sent to the terminal in response to a GET RESPONSE APDU.

        // this will be called when there is data to be sent
        byte[] buffer = apduBuffer;
        Util.arrayCopy(outBuffer, (short)0, buffer, (short)0, outDataSize);