[英]How to use Shareable interface in Java Card applets?
我為我的 java 卡編寫了兩個名為App1和App2 的簡單小程序,如下所示:
應用程序1:
public class App1 extends Applet {
private App1() {
}
public static void install(byte bArray[], short bOffset, byte bLength)
throws ISOException {
new App1().register();
}
public void process(APDU arg0) throws ISOException {
if(selectingApplet()){
return;
}
//I want to call "ThisMethod()" of App2 here
}
}
應用程序2:
public class App2 extends Applet {
private App2() {
}
public static void install(byte bArray[], short bOffset, byte bLength)
throws ISOException {
new App2().register();
}
public void process(APDU arg0) throws ISOException {
}
public void ThisMethod(){
ISOException.throwIt((short)0x9001);
}
}
正如我在 App1 程序中指出的那樣(作為注釋),我想在 App1 的Process
方法中調用 App2 的ThisMethod
方法。 據我所知,我必須實現Shareable
接口。 但我對此有點困惑:
問題 :
1- 我應該在兩個小程序中都實現這個方法嗎? 或者我只需要在 App1 或 App2 中實現它?
2- 如果 App1 和 App2 在一個包中或在兩個單獨的包中,它會改變什么嗎?
3- 我是否需要Shareable
接口來共享數組? 或者只是共享方法是強制性的?
不,您只需創建一個擴展 Shareable 的接口,然后您的 app2 必須實現該接口。
沒關系。
是的,如果您想共享您的陣列,您還需要實現Shareable
但是,在您可以使用從其他小程序實例共享的方法/對象之前,您必須首先將您的接口實例存儲在 App1 中。 你可以這樣做
AID aid = JCSystem.lookupAid({App2 AID byte array}, {offset}, {length}); // provide the instance AID of App2
{yourInterface} app2Instance = ({yourInterface})JCSystem.getAppletShareableInterfaceObject(aid, (byte)0);
然后使用app2Instance
訪問共享方法/對象
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.