Saturday, October 11, 2008

AS Model generator : XDoclet2 plugin to generate the Flex model AS file for the respective java server side value objects

My previous post gave an introduction to this plugin for xdoclet2 by writing a tutorial on xdoclet2 and velocity with this plugin as an example. Now, I will explain what this plugin can do.

First download the latest plugin(as3-plugin.jar) from dist folder at github project:

The supported annotations are:

1. as3.class - A class level tag.

1.a. name - The name of the generated AS class. Should be same as the java class name. Required.
1.b. generate - On false, does not generate the AS file for the java class. Default: true.
1.c. generate-bindable-metadata - Generates [Bindable] at class level in AS. Default value: true.
1.d. generate-remote-class-metadata - Generates [RemoteClass(alias="..")] on true. Default value: false.

2. as3.field - A Field level tag.


2.a. type - The fully qualified flex type to be generated in the AS file. Required.
2.b. import - Imports the flex type defined above. Default: false.
2.c. generate-bindable-field-metadata - Generate field level [Bindable] in the AS file. Default: false.
2.d. generate - Controls generation of the field in as files. Default: true.

The Java-Flex mapping supported are:

1. int - Number
2. double - Number
3. long - Number
4. java.lang.Short - Number
5. java.lang.Byte - Number
6. java.lang.Integer - Number
7. java.lang.Double - Number
8. java.lang.Long - Number
9. java.lang.Float - Number
10. java.lang.String - String
11. java.lang.Character - String
12. java.util.Collection - mx.collection.ArrayCollection
13. java.util.Map - Object
14. java.util.Dictionary - Object

For any other type define the as3.field with the flex type, and if the import is necessary. If that does not solve the problem, define it as Object, then cast it in the flex code when necessary. If this too does not solve the problem contact me on my blog. Will add the feature and release the next version.


Write a ant build script and invoke xdoclet with target:

<target name="generate">
        <fileset dir="${basedir}/src">
             <include name="**/*.java"/>          
        <component classname="com.ssb.plugin.as3.As3Plugin"

Please look at my previous post for the sample model class which uses all these annotations.
Download or browse the latest sample from the github sample folder and see the build file for details.

1 comment:

  1. Nice solution with XDoclet!

    I'm working on a generator, Paddle, which not only generator the Flex AS objects, but also the Java representation. A XSD model is used for input.

    See for the Paddle generator.

    - Martijn