org.nuiton.eugene.java
Class ObjectModelTransformerToJava

java.lang.Object
  extended by org.nuiton.eugene.Template<I>
      extended by org.nuiton.eugene.Transformer<ObjectModel,O>
          extended by org.nuiton.eugene.models.object.ObjectModelTransformer<ObjectModel>
              extended by org.nuiton.eugene.java.ObjectModelTransformerToJava
All Implemented Interfaces:
TemplateConfiguration
Direct Known Subclasses:
JavaBeanTransformer, JavaEnumerationTransformer, JavaInterfaceTransformer

public abstract class ObjectModelTransformerToJava
extends ObjectModelTransformer<ObjectModel>

Created: 28 oct. 2009

Author:
fdesbois

Field Summary
protected  JavaBuilder builder
          internal builder
 
Fields inherited from class org.nuiton.eugene.Transformer
outputModel, outputProperties, outputTemplate, previousTransformer
 
Fields inherited from class org.nuiton.eugene.Template
configuration, excludeTemplates, generatedPackages, model
 
Fields inherited from interface org.nuiton.eugene.TemplateConfiguration
PROP_CLASS_LOADER, PROP_DEFAULT_PACKAGE, PROP_ENCODING, PROP_EXCLUDE_TEMPLATES, PROP_GENERATED_PACKAGES, PROP_LAST_MODIFIED_SOURCE, PROP_OVERWRITE, PROP_VERBOSE, PROP_WRITER_REPORT
 
Constructor Summary
ObjectModelTransformerToJava()
           
 
Method Summary
 void addAnnotation(ObjectModelClassifier classifier, ObjectModelElement element, String annotation)
           
protected  ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, ObjectModelAttribute attribute)
           
protected  ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, String name, Class<?> type, String value, ObjectModelModifier... modifiers)
           
 ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, String name, String type)
           
protected  ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, String name, String type, String value, ObjectModelModifier... modifiers)
           
 ObjectModelOperation addBlock(ObjectModelClassifier classifier, ObjectModelModifier... modifiers)
          add an operation to the classifier with the form of a simple block of code.
 void addComment(ObjectModelElement element, String comment)
          Adds a comment to the given element.
protected  ObjectModelAttribute addConstant(ObjectModelClassifier classifier, String name, Class<?> type, String value, ObjectModelModifier visibility)
           
protected  ObjectModelAttribute addConstant(ObjectModelClassifier classifier, String name, String type, String value, ObjectModelModifier visibility)
           
protected  Set<String> addConstantsFromDependency(ObjectModelClassifier input, ObjectModelClassifier output)
          Search in input model, for a enumeration dependency named JavaGeneratorUtil.DEPENDENCIES_CONSTANTS.
protected  ObjectModelOperation addConstructor(ObjectModelClass clazz, ObjectModelModifier visibility)
           
protected  ObjectModelOperation addConstructor(ObjectModelEnumeration clazz, ObjectModelModifier visibility)
           
protected  void addException(ObjectModelOperation operation, Class<?> exception)
           
protected  void addException(ObjectModelOperation operation, String exception)
           
protected  void addI18n(StringBuilder buffer, String i18nPrefix, String suffix)
           
protected  void addImport(ObjectModelClassifier classifier, Class<?> imports)
           
protected  void addImport(ObjectModelClassifier classifier, ObjectModelClass imports)
           
protected  void addImport(ObjectModelClassifier classifier, String imports)
           
 ObjectModelClassifier addInnerClassifier(ObjectModelClass clazz, ObjectModelType type, String name, ObjectModelModifier... modifiers)
           
protected  void addInterface(ObjectModelClassifier classifier, Class<?> interfaceQualifiedName)
           
protected  void addInterface(ObjectModelClassifier classifier, String interfaceQualifiedName)
           
protected  void addLiteral(ObjectModelEnumeration classifier, String name)
           
protected  ObjectModelOperation addOperation(ObjectModelClassifier classifier, ObjectModelOperation operation)
          Adds an operation to the given classifier.
protected  ObjectModelOperation addOperation(ObjectModelClassifier classifier, String name, Class<?> type, ObjectModelModifier... modifiers)
           
protected  ObjectModelOperation addOperation(ObjectModelClassifier classifier, String name, String type, ObjectModelModifier... modifiers)
           
protected  ObjectModelParameter addParameter(ObjectModelOperation operation, Class<?> type, String name)
           
protected  ObjectModelParameter addParameter(ObjectModelOperation operation, String type, String name)
           
 void addStereotype(ObjectModelElement element, String stereotype)
          Add a stereotype to the given element.
 void addTagValue(ObjectModelElement element, String name, String value)
          Adds a tag value to the given element.
 void addTagValue(String name, String value)
          Adds a tag value to the model.
protected  ObjectModelAttribute cloneAttribute(ObjectModelAttribute source, ObjectModelClassifier destination, boolean cloneDocumentation, ObjectModelModifier... modifiers)
          clone a given attribute into a classifier of the output model
 ObjectModelClass cloneClass(ObjectModelClass source, boolean cloneDocumentation)
          creates a clone of the given source class in the output model and clones attributes, inheritence declarations and operations into the clone
 ObjectModelClassifier cloneClassifier(ObjectModelClassifier source, boolean cloneDocumentation)
          creates a clone of the given source classifier in the output model and clones attributes, inheritence declaration and operations

class-specific, enumeration-specific and interface-specific features of the given classifier will be present in the clone

protected  void cloneClassifier(ObjectModelClassifier source, ObjectModelClassifier destination, boolean copyDocumentation)
          copy attributes, interfaces declartion and operation of a given classifier into another classifier.
 ObjectModelEnumeration cloneEnumeration(ObjectModelEnumeration source, boolean cloneDocumentation)
          creates a clone of the given source enumeration in the output model and clones attributes, inheritence declaration, operations and literals into the clone
 ObjectModelInterface cloneInterface(ObjectModelInterface source, boolean cloneDocumentation)
          creates a clone of the given source interface in the output model and clones attributes, inheritence declaration and operations into the clone
 ObjectModelOperation cloneOperation(ObjectModelOperation source, ObjectModelClassifier destination, boolean cloneDocumentation, ObjectModelModifier... modifiers)
          Clone the source operation into the destination classifier.
 ObjectModelOperation cloneOperationSignature(ObjectModelOperation source, ObjectModelClassifier destination, boolean cloneDocumentation, ObjectModelModifier... modifiers)
          Clone the source operation into the destination classifier.
protected  void cloneStereotypes(ObjectModelClassifier source, ObjectModelClassifier destination)
           
protected  void cloneTagValues(ObjectModelElement source, ObjectModelElement destination)
          Copy all tag values fro the given source to the given destination.
protected  void copyClassifier(ObjectModelClassifier source, ObjectModelClassifier destination, boolean copyDocumentation)
          Deprecated. since 2.3, prefer use the cloneClass(ObjectModelClass, boolean) method
protected  ObjectModelClass createAbstractClass(String name, String packageName)
           
protected  ObjectModelClass createClass(String name, String packageName)
           
 ObjectModelEnumeration createEnumeration(String name, String packageName)
           
protected  ObjectModelInterface createInterface(String name, String packageName)
           
protected  void debugOutputModel()
           
protected  void generateI18nBlock(ObjectModelClassifier input, ObjectModelClassifier output, String i18nPrefix)
          Generates a static block with I18n keys for each navigable attributes prefixed by the given i18nPrefix.
 String getConstantName(String propertyName)
           
 String getConstantPrefix()
           
protected  String getConstantPrefix(ObjectModelClassifier input, String defaultPrefix)
           
protected  URL getFileInClassPath(String fqn)
           
protected  String getJavaBeanMethodName(String methodPrefix, String propertyName)
           
 void initConstantPrefixFromModel()
          Used to initialize constant prefix depends on model tagvalue EugeneTagValues.TAG_CONSTANT_PREFIX.
protected  ObjectModel initOutputModel()
          Initialization of the Output model.
protected  Template<ObjectModel> initOutputTemplate()
          Initialization of the Output generator.
protected  boolean isInClassPath(ObjectModelClassifier classifier)
          Checks if the classifier fully qualified name is in class-path and log a message that fqn will not generated if found
protected  boolean isInClassPath(String fqn)
          Checks if the given fully qualified name is in class-path and log a message that fqn will not generated if found.
 void setConstantPrefix(String constantPrefix)
           
 void setDocumentation(ObjectModelElement element, String documentation)
           
 void setMaxMultiplicity(ObjectModelAttribute attribute, int multiplicity)
          Adds a max multiplicity to the given attribute.
 void setMinMultiplicity(ObjectModelAttribute attribute, int multiplicity)
          Adds a min multiplicity to the given attribute.
 void setNavigable(ObjectModelAttribute attribute, boolean navigable)
          Adds a navigable flag to the given attribute.
protected  void setOperationBody(ObjectModelOperation operation, String body)
           
protected  void setSuperClass(ObjectModelClass classifier, Class<?> superclassQualifiedName)
           
protected  void setSuperClass(ObjectModelClass classifier, String superclassQualifiedName)
           
 
Methods inherited from class org.nuiton.eugene.models.object.ObjectModelTransformer
transform, transformFromClass, transformFromClassifier, transformFromElement, transformFromEnumeration, transformFromInterface, transformFromModel
 
Methods inherited from class org.nuiton.eugene.Transformer
applyTemplate, getOutputModel, getOutputProperties, getOutputTemplate, init, initPreviousTransformer, transform
 
Methods inherited from class org.nuiton.eugene.Template
getClassLoader, getConfiguration, getEncoding, getExcludeTemplates, getGeneratedPackages, getLastModifiedSource, getModel, getOverwrite, getProperties, getProperty, getProperty, getWriterReport, isOverwrite, isVerbose, setConfiguration, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

builder

protected JavaBuilder builder
internal builder

Constructor Detail

ObjectModelTransformerToJava

public ObjectModelTransformerToJava()
Method Detail

initOutputTemplate

protected Template<ObjectModel> initOutputTemplate()
Description copied from class: Transformer
Initialization of the Output generator. Must be override to instanciate the Generator that will make the generation of the Output model.

Specified by:
initOutputTemplate in class Transformer<ObjectModel,ObjectModel>
Returns:
the output generator

initOutputModel

protected ObjectModel initOutputModel()
Description copied from class: Transformer
Initialization of the Output model. Must be override to instanciate and initialize the output model. For ObjectModel you can use, ObjectModelBuilder to build easily an empty ObjectModel.

Specified by:
initOutputModel in class Transformer<ObjectModel,ObjectModel>
Returns:
the output model

debugOutputModel

protected void debugOutputModel()
Specified by:
debugOutputModel in class ObjectModelTransformer<ObjectModel>

createClass

protected ObjectModelClass createClass(String name,
                                       String packageName)

createEnumeration

public ObjectModelEnumeration createEnumeration(String name,
                                                String packageName)

createAbstractClass

protected ObjectModelClass createAbstractClass(String name,
                                               String packageName)

createInterface

protected ObjectModelInterface createInterface(String name,
                                               String packageName)

setSuperClass

protected void setSuperClass(ObjectModelClass classifier,
                             String superclassQualifiedName)

setSuperClass

protected void setSuperClass(ObjectModelClass classifier,
                             Class<?> superclassQualifiedName)

addInterface

protected void addInterface(ObjectModelClassifier classifier,
                            String interfaceQualifiedName)

addInterface

protected void addInterface(ObjectModelClassifier classifier,
                            Class<?> interfaceQualifiedName)

addImport

protected void addImport(ObjectModelClassifier classifier,
                         String imports)

addImport

protected void addImport(ObjectModelClassifier classifier,
                         ObjectModelClass imports)

addImport

protected void addImport(ObjectModelClassifier classifier,
                         Class<?> imports)

addTagValue

public void addTagValue(String name,
                        String value)
Adds a tag value to the model.

Parameters:
name - name of the tag value
value - value of the tag value

addTagValue

public void addTagValue(ObjectModelElement element,
                        String name,
                        String value)
Adds a tag value to the given element.

Parameters:
element - the element on which the tag value is attached.
name - the name of the tag value
value - the value of the tag value

getConstantName

public String getConstantName(String propertyName)

getConstantPrefix

protected String getConstantPrefix(ObjectModelClassifier input,
                                   String defaultPrefix)

addConstant

protected ObjectModelAttribute addConstant(ObjectModelClassifier classifier,
                                           String name,
                                           String type,
                                           String value,
                                           ObjectModelModifier visibility)
                                    throws IllegalArgumentException
Throws:
IllegalArgumentException

addConstant

protected ObjectModelAttribute addConstant(ObjectModelClassifier classifier,
                                           String name,
                                           Class<?> type,
                                           String value,
                                           ObjectModelModifier visibility)
                                    throws IllegalArgumentException
Throws:
IllegalArgumentException

addAttribute

protected ObjectModelAttribute addAttribute(ObjectModelClassifier classifier,
                                            String name,
                                            String type,
                                            String value,
                                            ObjectModelModifier... modifiers)

addAttribute

protected ObjectModelAttribute addAttribute(ObjectModelClassifier classifier,
                                            String name,
                                            Class<?> type,
                                            String value,
                                            ObjectModelModifier... modifiers)

addAttribute

protected ObjectModelAttribute addAttribute(ObjectModelClassifier classifier,
                                            ObjectModelAttribute attribute)

addAttribute

public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier,
                                         String name,
                                         String type)

addConstructor

protected ObjectModelOperation addConstructor(ObjectModelClass clazz,
                                              ObjectModelModifier visibility)
                                       throws IllegalArgumentException
Throws:
IllegalArgumentException

addConstructor

protected ObjectModelOperation addConstructor(ObjectModelEnumeration clazz,
                                              ObjectModelModifier visibility)
                                       throws IllegalArgumentException
Throws:
IllegalArgumentException

addOperation

protected ObjectModelOperation addOperation(ObjectModelClassifier classifier,
                                            String name,
                                            String type,
                                            ObjectModelModifier... modifiers)

addOperation

protected ObjectModelOperation addOperation(ObjectModelClassifier classifier,
                                            String name,
                                            Class<?> type,
                                            ObjectModelModifier... modifiers)

addOperation

protected ObjectModelOperation addOperation(ObjectModelClassifier classifier,
                                            ObjectModelOperation operation)
Adds an operation to the given classifier.

Parameters:
classifier - the classifier on which the operation will be added
operation - the operation to add
Returns:
the added operation
Since:
2.1.2

addLiteral

protected void addLiteral(ObjectModelEnumeration classifier,
                          String name)

addParameter

protected ObjectModelParameter addParameter(ObjectModelOperation operation,
                                            String type,
                                            String name)

addParameter

protected ObjectModelParameter addParameter(ObjectModelOperation operation,
                                            Class<?> type,
                                            String name)

addException

protected void addException(ObjectModelOperation operation,
                            String exception)

addException

protected void addException(ObjectModelOperation operation,
                            Class<?> exception)

setOperationBody

protected void setOperationBody(ObjectModelOperation operation,
                                String body)
                         throws IllegalArgumentException
Throws:
IllegalArgumentException

addInnerClassifier

public ObjectModelClassifier addInnerClassifier(ObjectModelClass clazz,
                                                ObjectModelType type,
                                                String name,
                                                ObjectModelModifier... modifiers)
                                         throws IllegalArgumentException
Throws:
IllegalArgumentException

setDocumentation

public void setDocumentation(ObjectModelElement element,
                             String documentation)

setMinMultiplicity

public void setMinMultiplicity(ObjectModelAttribute attribute,
                               int multiplicity)
Adds a min multiplicity to the given attribute.

Parameters:
attribute - the attribute on which the min multiplicty will be setted
multiplicity - the multiplicity to set
Since:
2.1.2

setMaxMultiplicity

public void setMaxMultiplicity(ObjectModelAttribute attribute,
                               int multiplicity)
Adds a max multiplicity to the given attribute.

Parameters:
attribute - the attribute on which the min multiplicty will be setted
multiplicity - the multiplicity to set
Since:
2.1.2

setNavigable

public void setNavigable(ObjectModelAttribute attribute,
                         boolean navigable)
Adds a navigable flag to the given attribute.

Parameters:
attribute - the attribute on which the navigable flag will be setted
navigable - the navigable flag to set
Since:
2.3

addComment

public void addComment(ObjectModelElement element,
                       String comment)
Adds a comment to the given element.

Parameters:
element - the element on which the comment will be added.
comment - the comment to add
Since:
2.1.2

addAnnotation

public void addAnnotation(ObjectModelClassifier classifier,
                          ObjectModelElement element,
                          String annotation)

addBlock

public ObjectModelOperation addBlock(ObjectModelClassifier classifier,
                                     ObjectModelModifier... modifiers)
add an operation to the classifier with the form of a simple block of code.

use it to add a "static {}" block into an classifier, then use setOperationBody with the returned value of this method to complete the creation of the static block

Parameters:
classifier - the classifier where the block will be added
modifiers - modifiers for the block
Returns:
the block added

addStereotype

public void addStereotype(ObjectModelElement element,
                          String stereotype)
Add a stereotype to the given element.

Parameters:
element - the element on which the stereotype will be added
stereotype - the stereotype to add
Since:
2.1.2

cloneOperationSignature

public ObjectModelOperation cloneOperationSignature(ObjectModelOperation source,
                                                    ObjectModelClassifier destination,
                                                    boolean cloneDocumentation,
                                                    ObjectModelModifier... modifiers)
Clone the source operation into the destination classifier. name, returnType, parameters, exceptions and tagValues will be cloned. You can specify modifiers for the result operation.

Parameters:
source - operation to clone
destination - classifier where result operation will be added
cloneDocumentation - flag to add documentation if some found in model
modifiers - extra modifiers
Returns:
the new operation created in destination classifier
Since:
2.1.2

cloneOperation

public ObjectModelOperation cloneOperation(ObjectModelOperation source,
                                           ObjectModelClassifier destination,
                                           boolean cloneDocumentation,
                                           ObjectModelModifier... modifiers)
Clone the source operation into the destination classifier. whole signature, tagValues and body code will be cloned. You can specify modifiers for the result operation.

Parameters:
source - operation to clone
destination - classifier where result operation will be added
cloneDocumentation - flag to add documentation if some found in model
modifiers - extra modifiers
Returns:
the new operation created in destination classifier
Since:
2.1.2

cloneAttribute

protected ObjectModelAttribute cloneAttribute(ObjectModelAttribute source,
                                              ObjectModelClassifier destination,
                                              boolean cloneDocumentation,
                                              ObjectModelModifier... modifiers)
clone a given attribute into a classifier of the output model

Parameters:
source - the original attribute
destination - classifier where the clone will be added
cloneDocumentation - flag to add documentation if some found in model
modifiers - extra modifiers
Returns:
the clone attribute
Since:
2.1.2

cloneTagValues

protected void cloneTagValues(ObjectModelElement source,
                              ObjectModelElement destination)
Copy all tag values fro the given source to the given destination.

Parameters:
source - the source element
destination - the destination element
Since:
2.3

cloneStereotypes

protected void cloneStereotypes(ObjectModelClassifier source,
                                ObjectModelClassifier destination)
Parameters:
source -
destination -
Since:
2.3

copyClassifier

@Deprecated
protected void copyClassifier(ObjectModelClassifier source,
                                         ObjectModelClassifier destination,
                                         boolean copyDocumentation)
Deprecated. since 2.3, prefer use the cloneClass(ObjectModelClass, boolean) method

copy attributes, interfaces declartion and operation of a given classifier into another classifier.

class-specific, enumeration-specific and interface-specific features of the given classifier will not be present in the clone. To copy those specific elements, use

Parameters:
source - the classifier to clone from the source model
destination - where to clone the given source one
copyDocumentation - flag to add documentation if some found in model
Since:
2.1.2

cloneClassifier

protected void cloneClassifier(ObjectModelClassifier source,
                               ObjectModelClassifier destination,
                               boolean copyDocumentation)
copy attributes, interfaces declartion and operation of a given classifier into another classifier.

class-specific, enumeration-specific and interface-specific features of the given classifier will not be present in the clone. To copy those specific elements, use

Parameters:
source - the classifier to clone from the source model
destination - where to clone the given source one
copyDocumentation - flag to add documentation if some found in model
Since:
2.3

cloneClass

public ObjectModelClass cloneClass(ObjectModelClass source,
                                   boolean cloneDocumentation)
creates a clone of the given source class in the output model and clones attributes, inheritence declarations and operations into the clone

Parameters:
source - the class to clone from the source model
cloneDocumentation - flag to add documentation if some found in model
Returns:
the clone of the given class
Since:
2.1.2

cloneInterface

public ObjectModelInterface cloneInterface(ObjectModelInterface source,
                                           boolean cloneDocumentation)
creates a clone of the given source interface in the output model and clones attributes, inheritence declaration and operations into the clone

Parameters:
source - the interface to clone from the source model
cloneDocumentation - flag to add documentation if some found in model
Returns:
the clone of the given interface
Since:
2.1.2

cloneEnumeration

public ObjectModelEnumeration cloneEnumeration(ObjectModelEnumeration source,
                                               boolean cloneDocumentation)
creates a clone of the given source enumeration in the output model and clones attributes, inheritence declaration, operations and literals into the clone

Parameters:
source - the enumeration to clone from the source model
cloneDocumentation - flag to add documentation if some found in model
Returns:
the clone of the given enumeration
Since:
2.1.2

cloneClassifier

public ObjectModelClassifier cloneClassifier(ObjectModelClassifier source,
                                             boolean cloneDocumentation)
creates a clone of the given source classifier in the output model and clones attributes, inheritence declaration and operations

class-specific, enumeration-specific and interface-specific features of the given classifier will be present in the clone

Parameters:
source - the classifier to clone from the source model
cloneDocumentation - flag to add documentation if some found in model
Returns:
the clone of the given classifier
Since:
2.1.2

addConstantsFromDependency

protected Set<String> addConstantsFromDependency(ObjectModelClassifier input,
                                                 ObjectModelClassifier output)
Search in input model, for a enumeration dependency named JavaGeneratorUtil.DEPENDENCIES_CONSTANTS.

If found, add all literals on output model as constants.

You can add a EugeneTagValues.TAG_CONSTANT_PREFIX to your enumeration to prefix constant names.

Parameters:
input - the input model
output - the ouput model
Returns:
the set of constants names generated

getConstantPrefix

public String getConstantPrefix()

setConstantPrefix

public void setConstantPrefix(String constantPrefix)

getJavaBeanMethodName

protected String getJavaBeanMethodName(String methodPrefix,
                                       String propertyName)

initConstantPrefixFromModel

public void initConstantPrefixFromModel()
Used to initialize constant prefix depends on model tagvalue EugeneTagValues.TAG_CONSTANT_PREFIX. If no tagvalue found, the default value will be an empty prefix.


getFileInClassPath

protected URL getFileInClassPath(String fqn)

generateI18nBlock

protected void generateI18nBlock(ObjectModelClassifier input,
                                 ObjectModelClassifier output,
                                 String i18nPrefix)
Generates a static block with I18n keys for each navigable attributes prefixed by the given i18nPrefix.

Parameters:
input - the input classifier
output - the output classifier (to generate)
i18nPrefix - the i81n prefix to use

addI18n

protected void addI18n(StringBuilder buffer,
                       String i18nPrefix,
                       String suffix)

isInClassPath

protected boolean isInClassPath(ObjectModelClassifier classifier)
Checks if the classifier fully qualified name is in class-path and log a message that fqn will not generated if found

Parameters:
classifier - classifier to test
Returns:
true if fqn of classifier was found in class-path, false otherwise.
Since:
2.5

isInClassPath

protected boolean isInClassPath(String fqn)
Checks if the given fully qualified name is in class-path and log a message that fqn will not generated if found.

Parameters:
fqn - fully qualified name to test
Returns:
true if fqn was found in class-path, false otherwise.
Since:
2.5


Copyright © 2004-2012 CodeLutin. All Rights Reserved.