Preparing and Registering the Remote Object

The PurseApplet constructor contains the initialization code for the remote object.

First, a javacard.framework.service.RMIService object must be allocated. This service is an object that knows how to handle all the incoming APDU commands related to the Java Card RMI protocol. The service must be initialized to allow remote methods on an instance of the PurseImpl class. A new instance of PurseImpl is created, and is specified as the initial reference parameter to the RMIService constructor as shown in the following code snippet. The initial reference is the reference that is made public by an applet to all its clients. It is used as a bootstrap for a client session, and is similar to that registered by a Java RMI server to the Java Card RMI registry.

RemoteService rmi = new RMIService(new PurseImpl());

Then, a dispatcher is created and initialized. A dispatcher is the glue among several services. In this example, the initialization is quite simple, because there is a single service to initialize:

dispatcher = new Dispatcher((short)1);
dispatcher.addService(rmi, Dispatcher.PROCESS_COMMAND);

Finally, the applet must register itself to the Java Card RE to be made selectable. This is done in the install method, where the applet constructor is invoked and immediately registered:

(new PurseApplet()).register();