| |
使用JavaCard RMI接口 |
|
时间: 2003-11-25 来自:yesky |
 |
|
实现远程对象
实现一个JCRMI远程对象类似于实现标准的J2SE RMI远程对象。主要区别是在JCRMI中你的远程对象有扩展CardRemoteObject的选择(除了实现你的远程接口之外)。
CardRemoteObject定义两个方法export()和unexport(),分别允许或者禁止从卡外到对象的访问。通过扩展CardRemoteObject,你自动地导出你的远程对象所有的方法。如果你决定不扩展CardRemoteObject,你将要负责通过调用CardRemoteObject.export()导出它们。
import java.rmi.RemoteException; import javacard.framework.service.CardRemoteObject; import javacard.framework.Util; import javacard.framework.UserException; /** * Provides the implementation for MyRemoteInterface. */ public class MyRemoteImpl extends CardRemoteObject implements MyRemoteInterface { /** The balance. */ private short balance = 0;
/** * The Constructor invokes the superclass constructor, * which exports this remote implementation. */ public MyRemoteImpl() { super(); // make this remote object visible }
/** * This method returns the balance. * @return the stored balance. * @throws RemoteException if a JCRMI exception is * encountered */ public short getBalance() throws RemoteException { return balance; }
// Other methods ... } | 列表⒕远程对象实现
一个完整的Java Card RMI应用程序的流程
让我们概述一个JCRMI应用程序的流程。客户端(主机)应用程序通过传递RMI APDU到卡上的JCRE来产生RMI调用,依次转送这些APDU到相应的JCRMI小应用程序。这个小应用程序分配接收的APDU到RMIService,依次处理APDU并且转化它为一个RMI调用。一个JCRMI小应用程序的典型流程在下面说明:
 Figure 5. 基于JavaCard RMI模型的应用程序流程
简言之,JCRMI提供一个基于APDU的消息传递模型的分布式对象模型机制。JCRMI消息被封装到传送到RMIService的APDU消息中,负责解码APDU命令,并且转化这些命名到方法调用和响应。这允许服务器和客户端通信,来回传送方法信息、参数和返回值。
|
|
|
|
|
|
|
|