Java Reference
In-Depth Information
understanding of how RMI works in Java). Instead of working at the level of individual bits
and bytes, you can connect to a Java smart card application on the card, receive a stub
interface to the application, and invoke its methods remotely, as shown in Listing 15-2.
Listing 15-2. Using JCRMI to Connect with a Java Smart Card
try {
String url = "jcrmi:0;AID=A0.0.0.67.4.7.1F.3.2C.3";
JavaCardRMIConnection jc =
(JavaCardRMIConnection)Connector.open(url);
Wallet wallet = (Wallet)jc.getInitialReference();
currentBalance = wallet.getBalance();
jc.close();
} catch (Exception e) {
}
In essence, the combination of the GCF Connector class and the AID you specify acts
as the registry for a remote Java object; you use the JavaCardRMIConnection instance's
getInitialReference method to obtain a reference to the stub representing the remote
application on the card.
As with an APDUConnection , exceptions can occur; this can happen if the card is not
inserted, if the smart card application does not exist, or if the Java ME application is not
permitted to use the smart card interface at all. Note that if the card is ejected while the
remote object is in use, access to the remote object of course fails; reinserting the card
requires the Java ME application to reconnect to the smart card application.
The JCRMI interface is significantly more limited in the following ways than either
Java RMI or Java RMI OP:
• Remote classes can only implement a maximum of 15 interfaces.
• Only primitive Java types ( boolean , byte , short , int , and single-dimensional arrays
of these types) can be returned by remote methods.
• Parameters and return values are exchanged by value, except for remote object
references.
As with the APDUConnection , using a JavaCardRMIConnection instance requires
permission; you'll want to assert the javax.microedition.jcrmi permission in your appli-
cation's JAD file or manifest. As with the APDUConnection , use of this privilege is restricted
to applications in the operator, manufacturer, or third-party trusted domains.
 
Search WWH ::




Custom Search