如何在Java卡小程序中使用可共享接口?
我为我的java卡编写了两个名为App1和App2的简单小程序,如下所示: App1:如何在Java卡小程序中使用可共享接口?,java,javacard,Java,Javacard,我为我的java卡编写了两个名为App1和App2的简单小程序,如下所示: App1: public class App1 extends Applet { private App1() { } public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException { new App1().register();
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
}
}
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);
}
}
App2:
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
}
}
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的过程
方法中调用App2的ThisMethod
方法。据我所知,我必须实现可共享
接口。但我对此有点困惑:
问题:
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
}
}
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);
}
}
1-我应该在两个小程序中都实现此方法吗?或者我需要在App1或App2中实现它
2-如果App1和App2在一个包或两个单独的包中,它会改变什么吗
3-我是否需要Shareable
接口来共享阵列?还是仅仅为了共享方法而强制
Shareable
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
访问共享的方法/对象我遵循上述步骤,但出现了一个新问题,如果您看一下,我将不胜感激:对不起,我以一种对我有效的方式更改了答案。若你们发现有什么不对劲,请告诉我。答案部分是错的。参考后续帖子:@PaulBastian我编辑了这个答案,如果你认为它是正确的,也许你想删除你的评论。(稍后我将删除此评论。)