How can I implement delegate for Object sharing in java card?
Hello everyone,
I work on JCOP31 smart card and I wrote two packages on tha card with eclipse 3.1.2 ,I need share a variable that it is return value of a function between two packages.as far as I know I can do this with delegate but I do not know how can I use and implement delegate,I just see one article in internet ("Secure Object sharing in java card"),it was very useful for me but when I want to implement its code in the eclipse I get some errors . My code is same as below :
public class ABCLoyaltyDelegate extends Delegate {
}
I get an error on Delegate word ,the error is "Delegate can not resolved to a type ",maybe I need to import something but I do not know.
in this article there is "import OSResources" but what is OSResources ?
I'd appriciate for any help about delegate.
yours sincerely,
Orchid.
[870 byte] By [
NewOrchida] at [2007-11-26 17:18:21]

# 2
Dear lexdabear,
thanks alot for your reply.
I have some questions:
First,how can you understand the article is not JC compliant?
Second,I study Shareable Interface but as far as I understand ,I can not return an Object from server to client with this way ,for example I need to share the Pin variable that it is defined with "OwnerPin" type but Shareable Interface cannot do this or I do not know how can do this.
if it is possible for you please describe me how can I share Pin between 2 packages .
I 'd appriciated for your help,
yours sincerely,
Orchid
# 8
Dear lexdabear,
I created 2 applet on different packages ,my code is same as below:
In Applet1:
public class Applet1 extends Applet{
Library1 pin;
private Applet1 (byte[] bArray,short bOffset,byte bLength) {
pin =new Library1(PIN_TRY_LIMIT,MAX_PIN_SIZE);
byte PinTemp[] = new byte[4];
PinTemp[0] = (byte) 0x31;PinTemp[1] = (byte) 0x31;
PinTemp[2] = (byte) 0x31;PinTemp[3] = (byte) 0x31;
pin.update(PinTemp, (short) (0), (byte) PinTemp.length);
register();
}
public Shareable getShareableInterfaceObject(AID clientAID,byte parameter)
{
return this;
}
public void process(APDU apdu) {
..........
}
}
//
In Interface1:
[code]public interface GinaInterface extends Shareable
{
// There is not any method to pass applet firewall except Pin,I leave thisinterface empty
}
//-
in Library1:
public class Library1 extends OwnerPIN implements Interface1{
public Library1(byte tryLimit, byte maxPINSize)
{
super(tryLimit,maxPINSize);
}
}
In Applet2:
import MyPackages1.Library1;
public class Applet2 extends Applet {
private UserCardApplet(byte[] bArray, short bOffset, byte bLength) {
....
public boolean select() {
final byte[] Applet1_AID={(byte)0x47,(byte)0x69,(byte)0x6e,(byte)0x61,(byte)0x41,(byte)0x70,(byte)0x70,(byte)0x6c,(byte)0x65,(byte)0x74};
AID GinaAID = JCSystem.lookupAID( Gina_AID, ( short )0,( byte)Gina_AID.length );
if ( Applet1_AID == null ) // probably not loaded on card
{
ISOException.throwIt( ISO7816.SW_FUNC_NOT_SUPPORTED );//6a 80
}
OwnerPIN ff;
ff = (Library1) JCSystem.getAppletShareableInterfaceObject(Applet1_AID,(byte)0);
if( ff == null )
{
ISOException.throwIt((short)0x0903);
}
}
[/code]
when I debug Applet2 I get an error on the top of package ,it is :
"resolving Constant-pool of clazz LMyPackage2/Applet2;failed:no such clazz LMyPackage1/Library1"
I think it is related to library1 that I cast in this line:
ff = (Library1) JCSystem.getAppletShareableInterfaceObject(Applet1_AID,(byte)0);
I defined ff with OwnerPin type ,is it right ?when I change it to Library1 there is this error again.
as you see in above code I leave empty the body of Interface1 because I do not have any method to pass Applet1 firewal,I want to share just Pin,am I right or no?
I do not know what is my mistake in Sharing Interface Object Pin ,Please help me
Sincerely yours,
Orchid