From: Gergely K. <ger...@ma...> - 2010-05-05 19:30:27
|
Hi, It is pretty straightforward to add a new Java wrapper for an Objective-C class 1. Check out the XMLVM source in Eclipse 2. You need to add 3 files - src/xmlvm2objc/compat-lib/java/org/xmlvm/iphone/WrappedClassName.java In this file you implement the method stubs that will mirror the Objective-C interface in Java - src/xmlvm2objc/compat-lib/org_xmlvm_iphone_WrappedClassName.h - src/xmlvm2objc/compat-lib/org_xmlvm_iphone_WrappedClassName.m These 2 files implement the wrapper in the Objective-C side. In the basic case you will use an Objective-C category to add the Java wrapper methods. in the .h: typedef OrigWrappedClassName org_xmlvm_iphone_WrappedClassName @interface OrigWrappedClassName (cat_org_xmlvm_iphone_WrappedClassName) // Java specific constructor -(void) __init__org_xmlvm_iphone_WrappedClassName__; // This is an example method declaration of Java getX(String, int) // Check the other files to see the pattern // This name mangling is required to support polymorphism in ObjC -(int) getX___java_lang_String_int: (java_lang_String*) s : (int) i; @end In the .m file @implementation OrigWrappedClassName (cat_org_xmlvm_iphone_WrappedClassName) - (void) __init_org_xmlvm_iphone_WrappedClassName { } - (int) getX___java_lang_String_int: (java_lang_String*) s : (int) i { // Here we implement the wrapper -> call the hypothetical original getX method int res = [self getX: s : i]; return res; } @end Now, in your Java code you can write WrappedClassName x = new WrappedClassName(); int i = x.getX("foobar", 99); If you run your modified XMLVM on the above code, in your cross compiled project you will have - your org_xmlvm_iphone_WrappedClassName.* files - the cross compiled code from above It will _not_ include the stubs from the xmlvm2objc/compat-lib/java folder in any form The cross compiled code will instantiate the org_xmlvm_iphone_WrappedClassName, which is just a typedef for the OrigWrappedClassName. So there is no wrapping overhead, you use the same objc class. The cross compiler generated the call for the wrapper method, which we defined in the category. In ObjC categories are used to extend already existing classes. Hope this helps. Best Regards, Gergely 2010/5/5 Charlie McIver <Cha...@s1...> > Ok – its time I tried to do something cool with XMLVM. > > > > Has anyone done any location based functionality yet? > > > > Although I’m new to iPhone development and XML VM (got the demos to work > and a new app based on the demo building!), and I don’t have the iPhone SDK > / XCode stuff, looking at the Apple Web site, I think I need to implement > the CLLocation class, which I think means I need to do it in the java > compatibility layer, and probably something down in the objective C stuff > (eesh) and maybe in the simulator in some fashion. > > > > This is probably wishful thinking, but is there any simple examples of > someone doing this I can learn from, without having to understand the whole > of XMLVM? > > > > Maybe I should be starting simpler… > > > > Cheers, > > > > Charlie > > > > > > > > > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > > -- Kis Gergely MattaKis Consulting Email: ger...@ma... Web: http://www.mattakis.com Phone: +36 70 408 1723 Fax: +36 27 998 622 |