Package org.nuiton.eugene.java
Class JavaBuilder
- java.lang.Object
-
- org.nuiton.eugene.models.object.ObjectModelBuilder
-
- 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.- Author:
- Florian Desbois - desbois@codelutin.com, Tony Chemit - chemit@codelutin.com
-
-
Field Summary
Fields Modifier and Type Field Description protected AnnotationsManagerExtension
annotationsManagerExtension
ObjectModel extension to manage imports : one ImportsManager by classifierprotected CodesManagerExtension
codesManagerExtension
ObjectModel extension to manage operation boby codesprotected ConstantsManagerExtension
constantsManagerExtension
ObjectModel extension to manage constants : one ConstantsManager for allprotected ImportsManagerExtension
importsManagerExtension
ObjectModel extension to manage imports : one ImportsManager by classifier-
Fields inherited from class org.nuiton.eugene.models.object.ObjectModelBuilder
model
-
-
Constructor Summary
Constructors Constructor Description JavaBuilder(String modelName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectModelAnnotation
addAnnotation(ObjectModelClassifier classifier, ObjectModelElement element, String annotationType)
Add an annotation on an element of a classifier.ObjectModelAnnotation
addAnnotationParameter(ObjectModelAnnotation annotation, String parameterName, Object parameterValue)
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.ObjectModelAttribute
addAttribute(ObjectModelClassifier classifier, ObjectModelAttribute attribute)
Add a new attribute to a classifier from an existing attribute.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 givenpropertyName
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
-
-
-
-
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 classObjectModelBuilder
- Parameters:
classifier
- the classifier on which to add the interfaceinterfaceQualifiedName
- 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 classObjectModelBuilder
- Parameters:
clazz
- where the superclass will be addedsuperclassQualifiedName
- 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 classObjectModelBuilder
- Parameters:
classifier
- the classifier on which to add the attributename
- name of attributetype
- type of attributevalue
- initializer value of attributemodifiers
- 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 classObjectModelBuilder
- Parameters:
classifier
- the classifier on which add the attributename
- name of the attributetype
- 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 classObjectModelBuilder
- Parameters:
classifier
- the classifier on which to add the operationname
- the name of the operationtype
- the return type of the operationmodifiers
- 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 classObjectModelBuilder
- Parameters:
operation
- the operation on which to add a parametertype
- the type of the parametername
- 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 classObjectModelBuilder
- Parameters:
operation
- the operation on which to add a execeptionexception
- the exception to add
-
setOperationBody
public void setOperationBody(ObjectModelOperation operation, String body) throws IllegalArgumentException
Set the operation body code.- Overrides:
setOperationBody
in classObjectModelBuilder
- Parameters:
operation
- the operation on which to add the body codebody
- 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 createpackageName
- 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<org.chorem.bonzoms.Role>() --> two imports 'java.util.List' and 'org.chorem.bonzoms.Role' - java.util.Collection<T extends org.nuiton.topia.TopiaEntity> --> 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 ObjectModelAnnotation addAnnotation(ObjectModelClassifier classifier, ObjectModelElement element, String annotationType)
Add an annotation on an element of a classifier.- Parameters:
classifier
- where the annotation will be added.element
- element on which add annotationannotationType
- type of annotation to add- Returns:
- the instanciated annotation
-
addAnnotationParameter
public ObjectModelAnnotation addAnnotationParameter(ObjectModelAnnotation annotation, String parameterName, Object parameterValue)
-
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 classsuperclassQualifiedName
- 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 fieldname
- name of the constant fieldtype
- type of the constant fieldvalue
- initializer value of the constant fieldvisibility
- 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 codecode
- code to add
-
getConstantName
public String getConstantName(String propertyName)
Converts the givenpropertyName
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 attributeattribute
- 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 blockmodifiers
- 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.- Parameters:
clazz
- the classifier on which to add the constructorvisibility
- 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.- Parameters:
enumeration
- the enumeration on which to add the constructorvisibility
- 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)
-
-