|
Download Sources | |||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||
See:
Description
| Class Summary | |
|---|---|
| FlexGenerator | Main class of FlexGenerator. |
| Annotation Types Summary | |
|---|---|
| FlexBindable | Used to define a bindable property. |
| FlexDefault | Used to define the default value of a property. |
| FlexLazy | Used to define a property as lazy. |
| FlexList | Used to define the Generics type on a List property. |
| FlexMap | Used to define the Generics type on a Map property. |
| FlexNode | Used to define property's node name in the generated XML. |
| FlexPackage | Used to define the package of generated classes. |
| FlexSet | Used to define the Generics type on a Set property. |
| FlexTransient | Used to indicates to the generator that a class or a property should not be convert to actionscript. |
Provides annotations and the generator class.
Now let's supose that you have a 'Person' class. By default you want that each properties of the class to be bindable. So we will put the @FlexBindable annotation at the class level.
Now you want to set a custom event for the binding of a particular property, we will put the @FlexBindable annotation on the getter of this property.
You want to assign a default value to the property ? No problem, you can add the @FlexDefault annotation on the getter of the property to indicate the default value.
You can use the @FlexTransient annotation to keep a class or a property on the java side.
Here is the code for the Person class :
package com.mycompany.myapp.entities;
import com.liguorien.flex.generator.*;
import java.util.*;
@FlexBindable
public class Person {
private int _id;
private String _name;
private int _serverSideOnlyProperty;
private List<Person> _contacts = new ArrayList<Person>();
private SessionHistory _sessionHistory = new SessionHistory();
@FlexDefault("-1")
public int getId() {
return _id;
}
public void setId(int id) {
_id = id;
}
@FlexBindable(event="change")
public String getName() {
return _name;
}
public void setName(String name) {
_name = name;
}
@FlexList(Person.class)
@FlexBindable(event="contactsChange")
public List<Person> getContacts(){
return _contacts;
}
public void setContacts(List<Person> contacts){
_contacts = contacts;
}
@FlexTransient
public int getServerSideOnlyProperty(){
return _serverSideOnlyProperty;
}
public void setServerSideOnlyProperty(int value){
_serverSideOnlyProperty = value;
}
@FlexDefault("new")
@FlexBindable(event="historyChange")
public SessionHistory getSessionHistory(){
return _sessionHistory;
}
}
Then create a "main class" in your project which will configure and run the generator :
public static void main(String[] args) {
FlexModelGenerator generator = new FlexModelGenerator();
generator.addHandler(new FlexModelHandler());
generator.addHandler(new FlexModelBuilderHandler());
generator.addHandler(new Dom4jBuilderHandler());
generator.setNewLineBeforeCurlyBrace(true);
generator.setUsingUnderscore(true);
generator.setClassSuffix("Model");
generator.setOutputMode(OutputMode.FILE);
generator.setFlexOutputDirectory("/dev/myproject/myapp/src/flex/");
generator.setJavaOutputDirectory("/dev/myproject/myapp/src/java/");
generator.addClass(Person.class);
generator.generate();
}
Then this ActionScript 3 class will be generated :
package com.mycompany.myapp.entities
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.utils.Dictionary;
public class PersonModel extends EventDispatcher
{
private var _contacts:Array = new Array();
[Bindable(event="contactsChange")]
public function get contacts():Array
{
return _contacts;
}
public function set contacts(value:Array):void
{
_contacts = value;
dispatchEvent(new Event("contactsChange"));
}
private var _id:int = -1;
[Bindable()]
public function get id():int
{
return _id;
}
public function set id(value:int):void
{
_id = value;
}
private var _name:String;
[Bindable()]
public function get name():String
{
return _name;
}
public function set name(value:String):void
{
_name = value;
}
private var _sessionHistory:SessionHistory = new SessionHistory();
[Bindable(event="historyChange")]
public function get sessionHistory():SessionHistory
{
return _sessionHistory;
}
}
}
|
FlexGenerator | |||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||