RMIPurse Sample

A Java Card RMI application consists of two parts: a card applet and a client program communicating with it. In this sample, the RMIPurse applet is installed in EEPROM image. For further details see Programming to the Java Card RMI Client-Side API.

The RMIPurse sample uses the card applet PurseApplet, the Purse interface and its implementation PurseImpl. These classes reside in the package com.sun.javacard.samples.RMIDemo. The client-side program PurseClient resides in the package com.sun.javacard.clientsamples.purseclient.

The Purse interface describes the supported functionality: methods for obtaining the account balance, debiting and crediting the account, and obtaining and setting an account number. The interface also defines the constants used for error reporting. The PurseImpl class implements Purse.

The card applet, PurseApplet, creates and registers instances of the dispatcher and the Java Card RMI service.

The client-side program, PurseClient, represents a simple Java Card RMI client. The program opens a connection with a card, creates the Java Card RMI Connect instance, and selects the Java Card applet (in this case, the PurseApplet). The program then gets the initial reference from PurseApplet (the reference to an instance of PurseImpl) and casts it to the Purse interface type. This allows PurseImpl to be treated as a local object. The program can then exercise the card by debiting and crediting different amounts, and by setting and getting the account number. The program demonstrates error handling by intentionally attempting to set an account number of incorrect size. This causes a UserException to be thrown with the appropriate error code.

The client part of the RMIDemo can be run without parameters or with the -i parameter:

  • If the sample is run without parameters, remote references are identified using the class name of the remote object.

  • If the sample is run with the -i parameter, remote references are identified using the list of remote interfaces implemented by the remote object.

Follow one of these sets of instructions to run this sample: