|
Download Sources | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.liguorien.flex.generator.FlexGenerator
public class FlexGenerator
Main class of FlexGenerator.
The purpose of this class is to generate classes based on the properties defined on a JavaBean.
The generator can easily be customized by creating a
FlexGeneratorHandler for each new type of generated classes.
Here is a little exemple on how to use this class :
FlexGenerator generator = new FlexGenerator();
// add an handler to generate code which will
// read and create dom4j element from Java entities
g.addHandler(new Dom4jBuilderHandler());
// add an handler to generate code which will be
// the ActionScript version of the JavaEntity
g.addHandler(new FlexModelHandler());
// add an handler to generated code which will
// read and create XML object from an ActionScript entities
g.addHandler(new FlexModelBuilderHandler());
// set formatting options
generator.setNewLineBeforeCurlyBrace(false);
generator.setUsingUnderscore(true);
// indicate to the generator where generate the actionscript and java files
generator.setOutputMode(OutputMode.FILE);
generator.setFlexOutputDirectory("./src/flex/");
generator.setJavaOutputDirectory("./src/java/");
// add a single class
generator.addClass(MyEntity.class);
// add an entire package
generator.addPackage("com.liguorien.myproject.entities");
// proceed to generation
generator.generate();
FlexBindable,
FlexDefault,
FlexTransient,
FlexLazy,
FlexMap,
FlexNode,
FlexSet,
FlexTransient,
OutputMode,
FlexGeneratorHandler,
AbstractGeneratorHandler,
Dom4jBuilderHandler,
FlexModelHandler,
FlexModelBuilderHandler| Constructor Summary | |
|---|---|
FlexGenerator()
Creates a new instance of FlexGenerator |
|
| Method Summary | ||
|---|---|---|
void |
addClass(java.lang.Class<?> clazz)
Add a single class |
|
void |
addHandler(FlexGeneratorHandler handler)
Add an handler to this generator. |
|
void |
addPackage(java.lang.String packageName)
Add an entire package. |
|
void |
generate()
Proceed to generation. |
|
java.lang.String |
getClassPrefix()
Get the class prefix |
|
java.lang.String |
getClassSuffix()
Get the class suffix |
|
static GeneratorContext |
getContext()
|
|
java.io.File |
getFlexOutputDirectory()
Returns the Flex output directory |
|
java.lang.String |
getIndentation(int count)
Get the indentation string for a given indentation count |
|
java.lang.String |
getIndentationString()
Getter for property indentationString. |
|
java.io.File |
getJavaOutputDirectory()
Getter for property javaOutputDirectory. |
|
java.util.Locale |
getLocale()
Getter for property locale. |
|
java.lang.String |
getMethodName(java.lang.Class<?> clazz,
java.lang.Object... params)
Writes the result of writeMethodName(java.io.Writer, java.lang.Class>, java.lang.Object...) into a StringWriter
and return the result as a String. |
|
static java.lang.String |
getNodeName(java.lang.Class<?> clazz)
Return the node name of an entity class. |
|
static java.lang.String |
getNodeName(java.beans.PropertyDescriptor prop)
Return the node name of a property. |
|
OutputMode |
getOutputMode()
Return the current output mode. |
|
java.lang.String |
getPackageName(java.lang.Class<?> clazz)
Returns the package name of the generated class. |
|
boolean |
isGeneratedClass(java.lang.Class<?> clazz)
Determine if the class sent is a generated class. |
|
static boolean |
isLazy(java.beans.PropertyDescriptor prop,
LazyMode mode)
Determines if a property is lazy. |
|
boolean |
isNewLineBeforeCurlyBrace()
Indicates if a new line should be added between package/class/method declaration and the curly brace. |
|
boolean |
isUsingUnderscore()
Indicates if an underscore(_) should be added to the private field name. |
|
void |
setClassPrefix(java.lang.String classPrefix)
Assign a prefix which will be added to the AS3 class name. |
|
void |
setClassSuffix(java.lang.String classSuffix)
Assign a suffix which will be added to the AS3 class name. |
|
void |
setFlexOutputDirectory(java.io.File dir)
Set the output directory used by the generator. |
|
void |
setFlexOutputDirectory(java.lang.String dir)
Set the output directory used by the generator. |
|
void |
setIndentationString(java.lang.String indentationString)
Setter for property indentationString. |
|
void |
setJavaOutputDirectory(java.io.File dir)
Setter for property javaOutputDirectory. |
|
void |
setJavaOutputDirectory(java.lang.String dir)
Setter for property javaOutputDirectory. |
|
void |
setLocale(java.util.Locale locale)
Setter for property locale. |
|
void |
setNewLineBeforeCurlyBrace(boolean newLineBeforeCurlyBrace)
Indicates if a new line should be added between package/class/method declaration and the curly brace. |
|
void |
setOutputMode(OutputMode outputMode)
Set the output mode that will be used by the generator. |
|
void |
setPackage(ClassType type,
java.lang.String path)
Set the destination package for a given ClassType. |
|
void |
setUsingUnderscore(boolean usingUnderscore)
Indicates if an underscore(_) should be added to the private field name. |
|
void |
writeComment(java.io.Writer w,
java.lang.String comment,
int indentation)
Write a JavaDoc-styled comment. |
|
void |
writeCurlyBrace(java.io.Writer w,
int indentationCount)
Write an opening curly brace. |
|
void |
writeDocumentation(java.io.Writer w,
java.lang.Class<?> clazz,
int indentation,
java.lang.Object... params)
Write internationalized document for a given class. |
|
void |
writeIndentation(java.io.Writer w,
int indentationCount)
Write indentation to a writer |
|
void |
writeMethodName(java.io.Writer w,
java.lang.Class<?> clazz,
java.lang.Object... params)
Write the name of the method of a given class. |
|
|
writeMethods(java.io.Writer w,
T handler,
java.util.Collection<MethodWriter<T>> methods,
java.lang.Class<?> clazz)
Iterates over a List of MethodWriter and let them write
code if they accept to class sent in parameters. |
|
static
|
writeProperties(java.io.Writer w,
FlexGenerator g,
T handler,
java.lang.String varName,
java.util.List<java.beans.PropertyDescriptor> props,
java.util.List<PropertyWriter<T>> writers,
LazyMode mode)
Write a List of properties to a given Writer. |
|
static
|
writeProperty(java.io.Writer w,
FlexGenerator g,
T handler,
java.lang.String varName,
java.beans.PropertyDescriptor prop,
java.util.List<PropertyWriter<T>> writers,
LazyMode mode)
Write a single property to a given Writer. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FlexGenerator()
| Method Detail |
|---|
public void setPackage(ClassType type,
java.lang.String path)
Set the destination package for a given ClassType.
By default, the path will be the same as the Java entity class. If the path begins with a slash(/), then the output package will be to this absolute path. If the slash is omitted, the package is relative to the Java entity package.
Exemple :
Let's supose that we are generating classes for the entity
com.liguorien.myapp.entities.MyEntity
| g.setPackage(ClassType.CLIENT_BUILDERS, "builder") | com.mycompany.myapp.entities.builder.MyEntityBuilder |
| g.setPackage(ClassType.CLIENT_BUILDERS, "../builder") | com.mycompany.myapp.builder.MyEntityBuilder |
| g.setPackage(ClassType.CLIENT_BUILDERS, "/org.otherproject.builder") | org.otherproject.builder.MyEntityBuilder |
type - A ClassTypepath - The path used to generated the classes.public void addHandler(FlexGeneratorHandler handler)
Add an handler to this generator.
handler - A FlexGeneratorHandler instance.public boolean isGeneratedClass(java.lang.Class<?> clazz)
Determine if the class sent is a generated class.
clazz - A class
public void generate()
Proceed to generation.
public void addClass(java.lang.Class<?> clazz)
clazz - A class which represents a Java entitypublic void addPackage(java.lang.String packageName)
Add an entire package. Every classes in the package will be processed
Classes can be excluded with the FlexTransient annotation.
packageName - The name of the package
(ie. "com.liguorien.myproject.entities")FlexTransientpublic void setFlexOutputDirectory(java.io.File dir)
Set the output directory used by the generator. It should be the classpath of your flex projet.
dir - A File object which represents the classpath
of your flex projectpublic void setFlexOutputDirectory(java.lang.String dir)
Set the output directory used by the generator. It should be the classpath of your flex projet.
dir - A String which represents the classpath of your flex projectpublic java.io.File getFlexOutputDirectory()
Returns the Flex output directory
public boolean isUsingUnderscore()
Indicates if an underscore(_) should be added to the private field name.
public void setUsingUnderscore(boolean usingUnderscore)
Indicates if an underscore(_) should be added to the private field name.
The default value is true.
usingUnderscore - New value of property usingUnderscore.public boolean isNewLineBeforeCurlyBrace()
Indicates if a new line should be added between package/class/method declaration and the curly brace.
public void setNewLineBeforeCurlyBrace(boolean newLineBeforeCurlyBrace)
Indicates if a new line should be added between package/class/method declaration and the curly brace.
The default value is false.
newLineBeforeCurlyBrace - New value of property newLineBeforeCurlyBrace.public OutputMode getOutputMode()
public void setOutputMode(OutputMode outputMode)
Set the output mode that will be used by the generator.
The default value is OutputMode.CONSOLE.
outputMode - The output mode.OutputModepublic java.lang.String getClassPrefix()
public void setClassPrefix(java.lang.String classPrefix)
Assign a prefix which will be added to the AS3 class name.
For example, if you have a class "Person" and the prefix is "Model", the AS3 class will be named "ModelPerson".
classPrefix - The prefix.public java.lang.String getClassSuffix()
public void setClassSuffix(java.lang.String classSuffix)
Assign a suffix which will be added to the AS3 class name.
For example, if you have a class "Person" and the suffix is "Model", the AS3 class will be named "PersonModel".
classSuffix - The suffix.public java.io.File getJavaOutputDirectory()
public void setJavaOutputDirectory(java.io.File dir)
dir - New value of property javaOutputDirectory.public void setJavaOutputDirectory(java.lang.String dir)
dir - New value of property javaOutputDirectory.
public static boolean isLazy(java.beans.PropertyDescriptor prop,
LazyMode mode)
Determines if a property is lazy.
prop - The property to checkmode - The LazyMode expected
FlexLazy,
LazyModepublic java.lang.String getPackageName(java.lang.Class<?> clazz)
Returns the package name of the generated class.
clazz - The current generated class.
java.lang.IllegalArgumentException - If the generator is misconfigurated.
public static <T extends FlexGeneratorHandler> void writeProperties(java.io.Writer w,
FlexGenerator g,
T handler,
java.lang.String varName,
java.util.List<java.beans.PropertyDescriptor> props,
java.util.List<PropertyWriter<T>> writers,
LazyMode mode)
throws java.io.IOException
Write a List of properties to a given Writer.
w - The Writer used to write the properties.g - The current FlexGenerator instance.handler - The current FlexGeneratorHandler.varName - The name of the instance where the properties are accessed.props - A List of PropertyDescriptorwriters - A List of PropertyWriter used to write the code to
access the property.mode - The LazyMode for the context where properties will be
accessed.
java.io.IOException - If an IO error occurs.
public static <T extends FlexGeneratorHandler> void writeProperty(java.io.Writer w,
FlexGenerator g,
T handler,
java.lang.String varName,
java.beans.PropertyDescriptor prop,
java.util.List<PropertyWriter<T>> writers,
LazyMode mode)
throws java.io.IOException
Write a single property to a given Writer.
w - The Writer used to write the property.g - The current FlexGenerator instance.handler - The current FlexGeneratorHandler.varName - The name of the instance where the property is accessed.prop - A PropertyDescriptorwriters - A List of PropertyWriter used to write the code to
access the property.mode - The LazyMode for the context where the property will be
accessed.
java.io.IOException - If an IO error occurs.
public <T extends FlexGeneratorHandler> void writeMethods(java.io.Writer w,
T handler,
java.util.Collection<MethodWriter<T>> methods,
java.lang.Class<?> clazz)
throws java.io.IOException
Iterates over a List of MethodWriter and let them write
code if they accept to class sent in parameters.
w - The writer used to write the generated code.handler - The current handler.methods - A List of MethodWriter.clazz - The current class.
java.io.IOException - If an IO error occurs.
public void writeIndentation(java.io.Writer w,
int indentationCount)
throws java.io.IOException
w - A Writer instanceindentationCount - The indentation count.
java.io.IOException - If an IO error occurs.public java.lang.String getIndentation(int count)
count - The indentation count.
public void writeCurlyBrace(java.io.Writer w,
int indentationCount)
throws java.io.IOException
Write an opening curly brace. It check in config if a new line must be added before the curly.
w - A WriterindentationCount - The current indentation level
java.io.IOException - If an IO error occurs.setNewLineBeforeCurlyBrace(boolean)public static java.lang.String getNodeName(java.beans.PropertyDescriptor prop)
Return the node name of a property.
prop - A PropertyDescriptor.
public static java.lang.String getNodeName(java.lang.Class<?> clazz)
Return the node name of an entity class.
clazz - An entity class.
public java.lang.String getIndentationString()
public void setIndentationString(java.lang.String indentationString)
indentationString - New value of property indentationString.
public void writeComment(java.io.Writer w,
java.lang.String comment,
int indentation)
w - A Writercomment - The comment to writeindentation - The current indentation levelpublic static GeneratorContext getContext()
public void writeDocumentation(java.io.Writer w,
java.lang.Class<?> clazz,
int indentation,
java.lang.Object... params)
Write internationalized document for a given class.
w - A Writerclazz - The target classindentation - The current indentation levelparams - String params sent to the MessageFormat
public void writeMethodName(java.io.Writer w,
java.lang.Class<?> clazz,
java.lang.Object... params)
throws java.io.IOException
w - A Writerclazz - The target classparams - The parameters sent to the MessageFormat
java.io.IOException
public java.lang.String getMethodName(java.lang.Class<?> clazz,
java.lang.Object... params)
Writes the result of writeMethodName(java.io.Writer, java.lang.Class>, java.lang.Object...) into a StringWriter
and return the result as a String.
clazz - The target classparams - The parameters sent to the MessageFormat
public java.util.Locale getLocale()
public void setLocale(java.util.Locale locale)
locale - New value of property locale.
|
FlexGenerator | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||