In a Flex application that uses LiveCycle Data Services or the previous Flex Data Services to manage data from a remote server there is the requirement that Flex domain model classes have to match Java domain model, in structure, properties and types. Usually it means that for each Java class that is supposed to be configured as a remote alias one should write down an ActionScript class with the same properties, just as described in the Adobe livedocs at Livedocs
The documentation provides a mapping for ActionScript data types and Java data types and specifies that Java classes are dealt with through the Java Beans specification, that can be downloaded here: Javabeans
The Java class is serialized and all of its public properties and the ones with getter and setter methods are serialized. All other properties are not, including the ones without a getter. There is one thing related to the Java beans that worths a bit of attention, and it is bean attribute names that start with a lower case character followed by a upper case character: their getter and setter methods will have get/set followed by at least two upper case characters, for example "aFoo" will have "getAFoo" and "setAFoo". When the Java introspection mechanism, described in the above specification, finds these kind of properties, it will infer that the property is called "AFoo". That implies that inside the ActionScript class that matches the Java bean the property has to be called "AFoo", otherwise it will not be recognized. This usually translates on the flash log in a "ReferenceError: Error #1056: Cannot create property AFoo on [...]".
Consider the case where all of the properties of a class are declared in Java with a lower case followed by an upper case, one could easily convert into an ActionScript class that follows the same naming convention and, at runtime, there will be an empty object, with the right type but no contents; the ReferenceErrors in the flashlog will point out the problem and the solution, in this case, is to call ActionScript properties starting with two upper case characters: "AFoo".
Iin an enterprise application there can be many Java bean classes to be converted to ActionScript counterparts, a simpler way of solving this and possibly other problems related to Java to ActionScript conversion would be the use of an automatic tool. At the time of writing this blog post I personally did not find a tool that performs the conversion, a tool that can be easily integrated into an IDE, like Eclipse, or used as an Ant task, thus I'm considering writing one myself. The backend of this tool would use java.beans.Introspector to get the java.beans.PropertyDescriptor for each property of the bean, map the Java types to the ActionScript ones and generate the required imports. I'll keep the blog updated with progress on the tool, as well as interesting parts of the source code.
Comments (8)
Check this link: http://www.graniteds.org/confluence/display/DOC04/2.5.+Gas3+Code+Generator
Posted by David | October 30, 2007 8:27 PM
Posted on October 30, 2007 20:27
Hey
Check xdoclet actionscript plugin.
Posted by faisal | November 15, 2007 12:32 PM
Posted on November 15, 2007 12:32
I've already written one. Maybe I'll put it out there some day, it's nothing too fancy but it works perfectly...
Posted by Yep | February 1, 2008 6:42 AM
Posted on February 1, 2008 06:42
There is now a tool for doing this and it can be found at http://www.graniteds.org/confluence/display/DOC/2.5.+Gas3+Code+Generator
It's ready as an ANT task so easily fits into build scripts.
Posted by Landon | April 29, 2008 2:46 PM
Posted on April 29, 2008 14:46
I was wondering if you ever made progress on this code generation project or have heard of projects that do this?
We're about to use LCDS and realized the same things you did.
I started investigating and got names such as GraniteDS Gas3, WebORB for Java has one, R1-RPC/J, VASGen, J2AS BUT I don't know if they do what I want. Do they convert domain objects or are they gear towars service object conversion.
Any guidance would be appreciated.
Posted by Eric Gravel | February 7, 2009 1:02 AM
Posted on February 7, 2009 01:02
hello,
did you find this kind of tools now?
regards
Posted by Olivier | February 7, 2009 3:28 PM
Posted on February 7, 2009 15:28
I've had success using Gas3, then modifying the templates .gsp files not to be GraniteDS specific.
http://www.graniteds.org/confluence/display/DOC/2.+Gas3+Code+Generator
Posted by Derek | February 11, 2009 5:51 AM
Posted on February 11, 2009 05:51
I have also used J2AS and GAS3, they both convert domain objects. GAS3 generated classes do include some extra code that LCDS / BlazeDS do not need, such as the IExternalizable interface.
Derek, how did you modify the .gsp templates? Would you share them?
Thanks
Posted by Constantin Moldovanu | February 17, 2009 12:30 PM
Posted on February 17, 2009 12:30