| |
使用JavaCard RMI接口 |
|
时间: 2003-11-25 来自:yesky |
 |
|
Java Card小应用程序
Java
Card小应用程序是JCRMI服务器,并且是主机(客户端)应用程序可用的远程对象的所有者。一个典型的Java Card
RMI小应用程序的结构在下面的图表中说明:
 Figure 4. 典型的JavaCard
RMI应用程序结构
当和明确地处理APDU消息的小应用程序相比,基于JCRMI的小应用程序更像一个对象容器。如图4所示,基于JCRMI的小应用程序有一个或多个远程对象,一个APDU
Dispatcher和一个接收APDU并且把它们转化为远程方法调用的RMIService。Java
Card远程类可以扩展CardRemoteObject类,自动导出对象,使之可用于远程使用。
JCRMI小应用程序必须扩展javacard.framework.Applet,遵循标准的小应用程序结构,并且定义适当的生命周期方法。它必须安装并且登记本身,并且分配APDU。下面这一代码片断说明一个基于JCRMI的小应用程序的典型结构:
public class MyApplet extends javacard.framework.Applet
{
private Dispatcher disp; private RemoteService
serv; private Remote myRemoteInterface;
/** * Construct the
applet. Here instantiate the remote * implementation(s), the APDU
Dispatcher, and the * RMIService. Before returning, register the
applet. */ public MyApplet () { // Create the implementation for
my applet. myRemoteInterface = new MyRemoteInterfaceImpl(); //
Create a new Dispatcher that can hold a maximum of 1 // service, the
RMIService. disp = new Dispatcher((short)1); // Create the
RMIService serv = new
RMIService(myRemoteInterface); disp.addService(serv,
Dispatcher.PROCESS_COMMAND); // Complete the registration
process register(); } ...
| 小应用程序创建一个Dispatcher和一个处理输入的JCRMI
APDU的RMIService。
... /** * Installs the Applet. Creates an instance of MyApplet.
* The JCRE calls this static method during applet *
installation. * @param bArray install parameter array. * @param
bOffset where install data begins. * @param bLength install parameter
data length. */ public static void install(byte[] aid, short s, byte
b) { new
MyApplet(); } | 在JavaCard环境中,JVM的生命周期是物理卡片的生命周期,而不是提供垃圾收集器的所有的Java
Card实现的,所以你需要最小化内存分配。在安装时间创建对象,这样内存只被分配给它们一次。
/** * Called by the JCRE to process an incoming APDU command. An
* applet is expected to perform the action requested and * return
response data, if any. * * This JCRMI version of the applet
dispatches remote * invocation APDUs by invoking the
Dispatcher. * * Upon normal return from this method the JCRE sends
the ISO- * 7816-4-defined success status (90 00) in the APDU response.
* If this method throws an ISOException, the JCRE sends the *
associated reason code as the response status instead. * @param apdu is
the incoming APDU. * @throw ISOException if the install method
fails. */ public void process(APDU apdu) throws ISOException { //
Dispatch the incoming command APDU to the
RMIService. disp.process(apdu); } | 代码列表13.Java
Card
RMI小应用程序
小应用程序的process()方法接收一个APDU命令并且把它发送到RMIService,RMIService通过把它转化为一个RMI调用和后续响应处理这条命令。
|
|
|
|
|
|
|
|