FileDocCategorySizeDatePackage
PlatformCardDevice.javaAPI DocphoneME MR2 API (J2ME)8888Wed May 02 18:00:38 BST 2007com.sun.cardreader

PlatformCardDevice

public class PlatformCardDevice extends CardDevice
Device driver for the real card reader.

Fields Summary
Constructors Summary
Methods Summary
private native intcheckCardMovement0()
Checks if the card in the selected slot was changed since last call or since last reset. Called after any transfer operation, so implementation can check and store that status during this operation.

return
0 if no movements has happened, > 0 if the card was changed, < 0 if an error occured.

public voidclose()
Closes the device. No exceptions thrown to avoid mess in exception handlers trying to clean up and close the device.

        finalize0();
    
public intcmdReset(byte[] atr)
Performs reset of device.

param
atr ATR bytes
return
Length of ATR
throws
IOException If a reset failed.

        int bytes_read;
                
        if ((bytes_read = reset0(atr)) < 0) {
            String err_msg = getErrorMessage0();
            if (err_msg != null)
                throw new IOException(err_msg);
            else
                throw new IOException("reset failed");
        }
        return bytes_read;
    
public intcmdXfer(byte[] request, byte[] response)
Performs data transfer to the device.

param
request Request bytes
param
response Response bytes
return
Length of response
throws
IOException If a data transfer failed.

        int bytes_read;
        
        if ((bytes_read = cmdXfer0(request, response)) < 0) {
            String err_msg = getErrorMessage0();
            if (err_msg != null)
                throw new IOException(err_msg);
            else
                throw new IOException("cmdXfer failed");
        }
        return bytes_read;
    
private native intcmdXfer0(byte[] request, byte[] response)
Performs data transfer to the device.

param
request Request bytes
param
response Response bytes
return
Length of response if successful, < 0 otherwise

private native voidfinalize0()
Finalizes the device.

private native java.lang.StringgetErrorMessage0()
Retrives last error message.

return
Error message as String

public intgetSlotCount()
Gets number of slots on a device.

return
Number of slots on a device. In case of error returns 0.

 
        return getSlotCount0();
    
private native intgetSlotCount0()
Gets number of slots on a device.

return
Number of slots on a device. In case of error returns 0.

public voidinit()
Initializes the device.

throws
IOException If a device initialization failed.
throws
CardDeviceException If a configuration initialization failed.

        
        if (!init0()) {
            String err_msg = getErrorMessage0();
            if (err_msg != null)
                throw new IOException(err_msg);
            else
                throw new IOException("Init failed");
        }
    
private native booleaninit0()
Initializes the device.

return
true if successful, false otherwise
throws
CardDeviceException If a configuration failed.

public booleanisCardChanged()
Checks if the card in the selected slot was changed since last call or since last reset. Always called after any transfer operation, so implementation can check and store that status during this operation.

return
true if was changed, false otherwise.
throws
IOException If something fails.

        int result = checkCardMovement0();
        if (result < 0) {
            String err_msg = getErrorMessage0();
            if (err_msg != null)
                throw new IOException(err_msg);
            else
                throw new IOException("Checking of card movement failed");
        }
        if (result == 0) {
            return false;
        } else {
            return true;
        }
    
public booleanisSatSlot(int slotNumber)
Checks if this slot is SAT slot.

param
slotNumber Slot number
return
true if the slot is dedicated for SAT, false otherwise
throws
IOException If an error occured.

 
        int result = isSatSlot0(slotNumber);
        if (result == -1) {
            String err_msg = getErrorMessage0();
            if (err_msg != null)
                throw new IOException(err_msg);
            else
                throw new IOException("isSAT failed");
        }
        return result != 0; 
    
private native intisSatSlot0(int slotNumber)
Checks if this slot is SAT slot.

param
slotNumber Slot number
return
1 if the slot is dedicated for SAT, 0 if not, -1 if any error occured

public voidlock()
Performs platform lock of the device. This is intended to make sure that no other native application uses the same device during a transaction.

throws
IOException If a device locking failed.

        
        if (!lock0()) {
            String err_msg = getErrorMessage0();
            if (err_msg != null)
                throw new IOException(err_msg);
            else
                throw new IOException("Lock failed");
        }
    
private native booleanlock0()
Locks the device.

return
true if successful, false otherwise

private native intreset0(byte[] atr)
Performs reset of device. Fills diven array with ATR bytes.

param
atr ATR bytes
return
Length of ATR if successful, < 0 otherwise

public voidselectSlot(int slot)
Selects the current slot for the subsequent transfer operations. For the one-slot devices the default slot number is 0.

param
slot Slot number
throws
IOException If a slot selection failed.

        
        if (!selectSlot0(slot)) {
            String err_msg = getErrorMessage0();
            if (err_msg != null)
                throw new IOException(err_msg);
            else
                throw new IOException("SelectSlot failed");
        }
    
private native booleanselectSlot0(int slotIndex)
Selects the current slot for the subsequent transfer operations. For the one-slot devices the default slot number is 0.

param
slotIndex Slot number
return
true if successful, false otherwise

public voidunlock()
Unlocks the device.

throws
IOException If a device unlocking failed.

        
        if (!unlock0()) {
            String err_msg = getErrorMessage0();
            if (err_msg != null)
                throw new IOException(err_msg);
            else
                throw new IOException("Unlock failed");
        }
    
private native booleanunlock0()
Unlocks the device.

return
true if successful, false otherwise