问题
In a Flex / Java app stack using remoting (via BlazeDS), classes to hold data passed back and forth between client and server need to be maintained in both the client (in ActionScript) and server (in Java).
I want a way to maintain theses classes in Java only, and have the corresponding ActionScript value object classes generated by the build process.
回答1:
Check out the AS3 generator from the Granite Data Services project:
http://www.graniteds.org
If I recall correctly it's an Eclipse plugin which should be quite easy to use. Just remember that if you exclude a property from the ActionScript class that it will still be serialized by Blaze when it's sent back to the Flex client.
回答2:
XDoclet2 includes an ActionScript plugin that can generate ActionScript classes from Javadoc comments in Java code.
The downside is that it's based on Javadoc rather than Java annotations, and does not appear to be well-documented or very widely used.
回答3:
There are a couple of free Java to AS3 converters out there of varying quality:
- http://osflash.org/projects/j2as3
- http://osflash.org/j2as (this one is AS2, but may be OK for your purposes)
I cannot vouch for their quality but they claim to do what you are looking for.
Personally I take the overhead of maintaining the two code bases manually because once the objects settle there is not much to do and it means I don't have complex rules around the rest of the code which is in the objects.
Plus my Java objects all have getters and setters whereas the AS3 equivalents do not, which means the public/private accessors are different in any case.
HTH
回答4:
If you're going to be doing a Flex RIA app of any degree of sophistication, then you'll probably be implementing the MVC pattern - ala Cairngorm, Mate, or PureMVC.
Take a look at this Flex code generator as it anticipates your use of MVC in the Flex client and generates code suitably to deliver an even higher degree of leverage:
FCG : a Flex Code Generator
来源:https://stackoverflow.com/questions/222359/generating-actionscript-value-objects-from-middle-tier-java-classes