org.nuiton.eugene.java
Class JavaBuilder

java.lang.Object
  extended by org.nuiton.eugene.models.object.ObjectModelBuilder
      extended by org.nuiton.eugene.java.JavaBuilder

public class JavaBuilder
extends ObjectModelBuilder

JavaBuilder

Created: 29 oct. 2009

Builder to fill an empty ObjectModel with java specificities (imports, only one inheritance, constructor, ...).

JavaBuilder uses some extensions to manage imports , constants, annotations, ...in the model.

JavaBuilder is also based on ObjectModelBuilder for the simple filling of the model.

Version:
$Id: JavaBuilder.java 1079 2011-06-28 09:15:23Z tchemit $
Author:
fdesbois , tchemit

Field Summary
protected  AnnotationsManagerExtension annotationsManagerExtension
          ObjectModel extension to manage imports : one ImportsManager by classifier
protected  CodesManagerExtension codesManagerExtension
          ObjectModel extension to manage operation boby codes
protected  ConstantsManagerExtension constantsManagerExtension
          ObjectModel extension to manage constants : one ConstantsManager for all
protected  ImportsManagerExtension importsManagerExtension
          ObjectModel extension to manage imports : one ImportsManager by classifier
 
Fields inherited from class org.nuiton.eugene.models.object.ObjectModelBuilder
model
 
Constructor Summary
JavaBuilder(String modelName)
           
 
Method Summary
 void addAnnotation(ObjectModelClassifier classifier, ObjectModelElement element, String annotation)
          Add an annotation on an element of a classifier.
 ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, ObjectModelAttribute attribute)
          Add a new attribute to a classifier from an existing attribute.
 ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, String name, String type)
          Add a new attribute to a classifier with no default value.
 ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, String name, String type, String value, ObjectModelModifier... modifiers)
          Add a new attribute to a classifier.
 ObjectModelOperation addBlock(ObjectModelClassifier classifier, ObjectModelModifier... modifiers)
          Add a new block to a classifier.
 void addBodyCode(ObjectModelClassifier classifier, ObjectModelOperation operation, String code)
          Add a body code to the operation of a classifier.
 ObjectModelAttribute addConstant(ObjectModelClassifier classifier, String name, String type, String value, ObjectModelModifier visibility)
          Add a new constant to a classifier.
 ObjectModelOperation addConstructor(ObjectModelClass clazz, ObjectModelModifier visibility)
          Add a constructor to a class.
 ObjectModelOperation addConstructor(ObjectModelEnumeration enumeration, ObjectModelModifier visibility)
          Add a constructor to a enumeration.
protected  ObjectModelOperation addConstructorForClassifier(ObjectModelClassifier classifier, ObjectModelModifier visibility)
           
 void addException(ObjectModelOperation operation, String exception)
          Add an exception to an operation.
 void addImport(ObjectModelClassifier classifier, String imports)
          Add an import to a classifier.
 void addInterface(ObjectModelClassifier classifier, String interfaceQualifiedName)
          Add an interface to a classifier (interface, class, enum).
 ObjectModelOperation addOperation(ObjectModelClassifier classifier, String name, String type, ObjectModelModifier... modifiers)
          Add a new operation to a classifier.
 ObjectModelParameter addParameter(ObjectModelOperation operation, String type, String name)
          Add a new parameter to an existing operation.
 void addSuperclass(ObjectModelClass clazz, String superclassQualifiedName)
          Add a superclass to an other class.
 ObjectModelClass createAbstractClass(String name, String packageName)
          Create a new abstract class in the model.
 String getConstantName(String propertyName)
          Converts the given propertyName to a constant name.
 void setOperationBody(ObjectModelOperation operation, String body)
          Set the operation body code.
 void setSuperClass(ObjectModelClass classifier, String superclassQualifiedName)
          Set the superclass of an other class.
 
Methods inherited from class org.nuiton.eugene.models.object.ObjectModelBuilder
addAssociation, addComment, addInnerClassifier, addLiteral, addOperation, addReverseAssociation, addStereotype, addTagValue, addTagValue, createAssociationClass, createClass, createClass, createEnumeration, createInterface, getModel, setClassModifiers, setDocumentation, setMaxMultiplicity, setMinMultiplicity, setNavigable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

importsManagerExtension

protected ImportsManagerExtension importsManagerExtension
ObjectModel extension to manage imports : one ImportsManager by classifier


annotationsManagerExtension

protected AnnotationsManagerExtension annotationsManagerExtension
ObjectModel extension to manage imports : one ImportsManager by classifier


constantsManagerExtension

protected ConstantsManagerExtension constantsManagerExtension
ObjectModel extension to manage constants : one ConstantsManager for all


codesManagerExtension

protected CodesManagerExtension codesManagerExtension
ObjectModel extension to manage operation boby codes

Constructor Detail

JavaBuilder

public JavaBuilder(String modelName)
Method Detail

addInterface

public void addInterface(ObjectModelClassifier classifier,
                         String interfaceQualifiedName)
Add an interface to a classifier (interface, class, enum). IMPORTS interfaceQualifiedName.

Overrides:
addInterface in class ObjectModelBuilder
Parameters:
classifier - the classifier on which to add the interface
interfaceQualifiedName - fully qualified name of the interface

addSuperclass

public void addSuperclass(ObjectModelClass clazz,
                          String superclassQualifiedName)
                   throws UnsupportedOperationException
Description copied from class: ObjectModelBuilder
Add a superclass to an other class. The superclass may not exist in model.

Overrides:
addSuperclass in class ObjectModelBuilder
Parameters:
clazz - where the superclass will be added
superclassQualifiedName - superclass qualified name
Throws:
UnsupportedOperationException

addAttribute

public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier,
                                         String name,
                                         String type,
                                         String value,
                                         ObjectModelModifier... modifiers)
Add a new attribute to a classifier. IMPORTS type.

Overrides:
addAttribute in class ObjectModelBuilder
Parameters:
classifier - the classifier on which to add the attribute
name - name of attribute
type - type of attribute
value - initializer value of attribute
modifiers - modifiers of the attribute
Returns:
a new ObjectModelAttribute
See Also:
ObjectModelModifier.isVisibility()

addAttribute

public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier,
                                         String name,
                                         String type)
Add a new attribute to a classifier with no default value. Default visibility is set to PROTECTED. IMPORTS type.

Overrides:
addAttribute in class ObjectModelBuilder
Parameters:
classifier - the classifier on which add the attribute
name - name of the attribute
type - type of the attribute
Returns:
a new ObjectModelAttribute

addOperation

public ObjectModelOperation addOperation(ObjectModelClassifier classifier,
                                         String name,
                                         String type,
                                         ObjectModelModifier... modifiers)
Add a new operation to a classifier.

Overrides:
addOperation in class ObjectModelBuilder
Parameters:
classifier - the classifier on which to add the operation
name - the name of the operation
type - the return type of the operation
modifiers - the modifiers of the operation
Returns:
a new ObjectModelOperation

addParameter

public ObjectModelParameter addParameter(ObjectModelOperation operation,
                                         String type,
                                         String name)
Add a new parameter to an existing operation.

Overrides:
addParameter in class ObjectModelBuilder
Parameters:
operation - the operation on which to add a parameter
type - the type of the parameter
name - the name of the parameter
Returns:
a new ObjectModelParameter

addException

public void addException(ObjectModelOperation operation,
                         String exception)
Add an exception to an operation.

Overrides:
addException in class ObjectModelBuilder
Parameters:
operation - the operation on which to add a exeception
exception - the exception to add

setOperationBody

public void setOperationBody(ObjectModelOperation operation,
                             String body)
                      throws IllegalArgumentException
Set the operation body code.

Overrides:
setOperationBody in class ObjectModelBuilder
Parameters:
operation - the operation on which to add the body code
body - the body code to set on the operation
Throws:
IllegalArgumentException - if operation is abstract

createAbstractClass

public ObjectModelClass createAbstractClass(String name,
                                            String packageName)
Create a new abstract class in the model.

Parameters:
name - the name of the abstract class to create
packageName - package's name of the class to create
Returns:
a new ObjectModelClass
See Also:
ObjectModelBuilder.createClass(String, String, ObjectModelModifier...)

addImport

public void addImport(ObjectModelClassifier classifier,
                      String imports)
Add an import to a classifier. Imports are automatic for lots of JavaBuilder's methods except body code of operations.
 You can have some complex imports like :
 - new java.util.List()
  --> two imports 'java.util.List' and 'org.chorem.bonzoms.Role'
 - java.util.Collection
  --> two imports 'java.util.Collection' and 'org.nuiton.topia.TopiaEntity'
 

Parameters:
classifier - where the imports will be added.
imports - to add
See Also:
GeneratorUtil.getTypesList(String)

addAnnotation

public void addAnnotation(ObjectModelClassifier classifier,
                          ObjectModelElement element,
                          String annotation)
Add an annotation on an element of a classifier.

Parameters:
classifier - where the annotation will be added.
element - element on which add annotation
annotation - annotation to add

setSuperClass

public void setSuperClass(ObjectModelClass classifier,
                          String superclassQualifiedName)
Set the superclass of an other class. Only one superclass can be set to the class. IMPORTS superclassQualifiedName.

Parameters:
classifier - the classifier on which to set the super class
superclassQualifiedName - fully qualified name of the super class

addConstant

public ObjectModelAttribute addConstant(ObjectModelClassifier classifier,
                                        String name,
                                        String type,
                                        String value,
                                        ObjectModelModifier visibility)
                                 throws IllegalArgumentException
Add a new constant to a classifier. A constant is static and final and have a value. IMPORTS type, value.

Parameters:
classifier - the classifier on which to add the constant field
name - name of the constant field
type - type of the constant field
value - initializer value of the constant field
visibility - modifier allowed : PUBLIC, PRIVATE, PROTECTED, PACKAGE
Returns:
a new ObjectModelAttribute
Throws:
IllegalArgumentException - if the modifier is not a visibility

addBodyCode

public void addBodyCode(ObjectModelClassifier classifier,
                        ObjectModelOperation operation,
                        String code)
Add a body code to the operation of a classifier.

Parameters:
classifier - where the body code will be added.
operation - operation on which add body code
code - code to add

getConstantName

public String getConstantName(String propertyName)
Converts the given propertyName to a constant name.

For example :

 "CONSTANT_A" = getConstantName("constantA");
 

Parameters:
propertyName - the name of the property to convert
Returns:
the constant name

addAttribute

public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier,
                                         ObjectModelAttribute attribute)
Add a new attribute to a classifier from an existing attribute. IMPORTS attribute.getType() and attribute.getDefaultValue().

Parameters:
classifier - the classifier on which to add the attribute
attribute - the attribute to add
Returns:
a new ObjectModelAttribute

addBlock

public ObjectModelOperation addBlock(ObjectModelClassifier classifier,
                                     ObjectModelModifier... modifiers)
Add a new block to a classifier.

Parameters:
classifier - the classifier on which to add the block
modifiers - the modifiers of the operation
Returns:
a new ObjectModelOperation
See Also:
ObjectModelBuilder.addOperation(ObjectModelClassifier, String, String, ObjectModelModifier...)

addConstructor

public ObjectModelOperation addConstructor(ObjectModelClass clazz,
                                           ObjectModelModifier visibility)
                                    throws IllegalArgumentException
Add a constructor to a class. FIXME-fdesbois-2010-06-23 : need to take care of generic case

Parameters:
clazz - the classifier on which to add the constructor
visibility - the visibility of the operation
Returns:
a new ObjectModelOperation
Throws:
IllegalArgumentException - if the modifier is not a visibility

addConstructor

public ObjectModelOperation addConstructor(ObjectModelEnumeration enumeration,
                                           ObjectModelModifier visibility)
                                    throws IllegalArgumentException
Add a constructor to a enumeration. FIXME-fdesbois-2010-06-23 : need to take care of generic case

Parameters:
enumeration - the enumeration on which to add the constructor
visibility - the visibility of the constructor (should always to private...)
Returns:
the new constructor
Throws:
IllegalArgumentException - if visibility is not ok

addConstructorForClassifier

protected ObjectModelOperation addConstructorForClassifier(ObjectModelClassifier classifier,
                                                           ObjectModelModifier visibility)


Copyright © 2004-2012 CodeLutin. All Rights Reserved.