Author: tchemit Date: 2010-08-12 17:22:56 +0200 (Thu, 12 Aug 2010) New Revision: 954 Url: http://nuiton.org/repositories/revision/eugene/954 Log: add addOperation method + add javadocs Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelBuilder.java Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java 2010-08-12 15:04:52 UTC (rev 953) +++ trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java 2010-08-12 15:22:56 UTC (rev 954) @@ -163,7 +163,7 @@ /** * Adds a tag value to the model. * - * @param name name of the tag value + * @param name name of the tag value * @param value value of the tag value */ public void addTagValue(String name, String value) { @@ -174,8 +174,8 @@ * Adds a tag value to the given {@code element}. * * @param element the element on which the tag value is attached. - * @param name the name of the tag value - * @param value the value of the tag value + * @param name the name of the tag value + * @param value the value of the tag value */ public void addTagValue(ObjectModelElement element, String name, String value) { builder.addTagValue(element, name, value); @@ -202,7 +202,7 @@ } return prefix.trim(); } - + protected ObjectModelAttribute addConstant( ObjectModelClassifier classifier, String name, @@ -280,6 +280,20 @@ return builder.addOperation(classifier, name, type == null ? null : type.getName(), modifiers); } + /** + * Adds an operation to the given classifier. + * + * @param classifier the classifier on which the operation will be added + * @param operation the operation to add + * @return the added operation + * @since 2.1.2 + */ + protected ObjectModelOperation addOperation( + ObjectModelClassifier classifier, + ObjectModelOperation operation) { + return builder.addOperation(classifier, operation); + } + protected void addLiteral(ObjectModelEnumeration classifier, String name) { builder.addLiteral(classifier, name); } @@ -329,14 +343,35 @@ builder.setDocumentation(element, documentation); } + /** + * Adds a min multiplicity to the given {@code attribute}. + * + * @param attribute the attribute on which the min multiplicty will be setted + * @param multiplicity the multiplicity to set + * @since 2.1.2 + */ public void setMinMultiplicity(ObjectModelAttribute attribute, int multiplicity) { builder.setMinMultiplicity(attribute, multiplicity); } + /** + * Adds a max multiplicity to the given {@code attribute}. + * + * @param attribute the attribute on which the min multiplicty will be setted + * @param multiplicity the multiplicity to set + * @since 2.1.2 + */ public void setMaxMultiplicity(ObjectModelAttribute attribute, int multiplicity) { builder.setMaxMultiplicity(attribute, multiplicity); } + /** + * Adds a comment to the given {@code element}. + * + * @param element the element on which the comment will be added. + * @param comment the comment to add + * @since 2.1.2 + */ public void addComment(ObjectModelElement element, String comment) { builder.addComment(element, comment); } @@ -352,6 +387,13 @@ return builder.addBlock(classifier, modifiers); } + /** + * Add a stereotype to the given {@code element}. + * + * @param element the element on which the stereotype will be added + * @param stereotype the stereotype to add + * @since 2.1.2 + */ public void addStereotype(ObjectModelElement element, String stereotype) { builder.addStereotype(element, stereotype); } @@ -473,7 +515,7 @@ } protected URL getFileInClassPath(String fqn) { - String resourceName = fqn.replaceAll("\\.", "/") + ".java"; + String resourceName = fqn.replaceAll("\\.", "/") + ".java"; URL fileLocation = getClassLoader().getResource(resourceName); if (log.isDebugEnabled()) { log.debug("Look for resource : " + resourceName + " = " + fileLocation); Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelBuilder.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelBuilder.java 2010-08-12 15:04:52 UTC (rev 953) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelBuilder.java 2010-08-12 15:22:56 UTC (rev 954) @@ -97,7 +97,9 @@ * @param name tagValue name * @param value tagValue value */ - public void addTagValue(ObjectModelElement element, String name, String value) { + public void addTagValue(ObjectModelElement element, + String name, + String value) { ObjectModelElementImpl impl = (ObjectModelElementImpl) element; ObjectModelImplTagValue tagValue = new ObjectModelImplTagValue(); @@ -115,12 +117,17 @@ * @param modifiers class modifiers * @return the new ObjectModelClass added to the model */ - public ObjectModelClass createClass(String name, String packageName, ObjectModelModifier... modifiers) { + public ObjectModelClass createClass(String name, + String packageName, + ObjectModelModifier... modifiers) { ObjectModelClassImpl result = new ObjectModelClassImpl(); return createClass(result, name, packageName, modifiers); } - protected ObjectModelClass createClass(ObjectModelClassImpl clazz, String name, String packageName, ObjectModelModifier... modifiers) + protected ObjectModelClass createClass(ObjectModelClassImpl clazz, + String name, + String packageName, + ObjectModelModifier... modifiers) throws IllegalArgumentException { clazz.setName(name); clazz.setPackage(packageName); @@ -162,7 +169,8 @@ * @param packageName interface package * @return the new ObjectModelInterface added to the model */ - public ObjectModelInterface createInterface(String name, String packageName) { + public ObjectModelInterface createInterface(String name, + String packageName) { ObjectModelInterfaceImpl result = new ObjectModelInterfaceImpl(); result.setName(name); result.setPackage(packageName); @@ -177,7 +185,8 @@ * @param packageName interface package * @return the new ObjectModelInterface added to the model */ - public ObjectModelEnumeration createEnumeration(String name, String packageName) { + public ObjectModelEnumeration createEnumeration(String name, + String packageName) { ObjectModelEnumerationImpl result = new ObjectModelEnumerationImpl(); result.setName(name); result.setPackage(packageName); @@ -195,7 +204,9 @@ * @param type attribute type (full qualified name) * @return the new ObjectModelAttribute added */ - public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, String name, String type) { + public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, + String name, + String type) { return addAttribute(classifier, name, type, ""); } @@ -213,8 +224,12 @@ * @throws IllegalArgumentException illegal Modifier * @see ObjectModelModifier#isVisibility() */ - public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, String name, String type, String value, - ObjectModelModifier... modifiers) throws IllegalArgumentException { + public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, + String name, + String type, + String value, + ObjectModelModifier... modifiers) + throws IllegalArgumentException { ObjectModelAttributeImpl attribute = new ObjectModelAttributeImpl(); attribute.setName(name); attribute.setType(type); @@ -238,7 +253,8 @@ attribute.setUnique(true); break; default: - throw new IllegalArgumentException("Unsupported modifier type '" + modifier.name() + "'"); + throw new IllegalArgumentException( + "Unsupported modifier type '" + modifier.name() + "'"); } } } @@ -264,8 +280,12 @@ * @return the attribute corresponding to the association for classifierA * @throws IllegalArgumentException illegal modifier */ - public ObjectModelAttribute addAssociation(ObjectModelClassifier classifierA, ObjectModelClassifier classifierB, String roleName, - int minMultiplicity, int maxMultiplicity, ObjectModelModifier... modifiers) + public ObjectModelAttribute addAssociation(ObjectModelClassifier classifierA, + ObjectModelClassifier classifierB, + String roleName, + int minMultiplicity, + int maxMultiplicity, + ObjectModelModifier... modifiers) throws IllegalArgumentException { ObjectModelAttributeImpl attribute = new ObjectModelAttributeImpl(); @@ -296,7 +316,8 @@ attribute.setNavigable(true); break; default: - throw new IllegalArgumentException("Unsupported modifier type '" + modifier.name() + "'"); + throw new IllegalArgumentException( + "Unsupported modifier type '" + modifier.name() + "'"); } } } @@ -318,8 +339,11 @@ * @return the attribute corresponding to the association for classifierB * @see #addAssociation(ObjectModelClassifier, ObjectModelClassifier, String, int, int, ObjectModelModifier...) */ - public ObjectModelAttribute addReverseAssociation(ObjectModelAttribute attrAssociation, String roleName, - int minMultiplicity, int maxMultiplicity, ObjectModelModifier... modifiers) { + public ObjectModelAttribute addReverseAssociation(ObjectModelAttribute attrAssociation, + String roleName, + int minMultiplicity, + int maxMultiplicity, + ObjectModelModifier... modifiers) { ObjectModelAttributeImpl associationA = (ObjectModelAttributeImpl) attrAssociation; // Add reverse parameters @@ -335,8 +359,12 @@ // Create reverse association ObjectModelAttributeImpl associationB = - (ObjectModelAttributeImpl) addAssociation(classifierB, classifierA, roleName, - minMultiplicity, maxMultiplicity, modifiers); + (ObjectModelAttributeImpl) addAssociation(classifierB, + classifierA, + roleName, + minMultiplicity, + maxMultiplicity, + modifiers); associationB.setReverseAttributeName(associationA.getName()); associationB.setReverseMaxMultiplicity(associationA.getMaxMultiplicity()); @@ -356,18 +384,23 @@ * @param modifiers for the association class * @return the new association class created with participants A and B */ - public ObjectModelAssociationClass createAssociationClass(String name, String packageName, ObjectModelAttribute attrAssociationA, - ObjectModelAttribute attrAssociationB, ObjectModelModifier... modifiers) { + public ObjectModelAssociationClass createAssociationClass(String name, + String packageName, + ObjectModelAttribute attrAssociationA, + ObjectModelAttribute attrAssociationB, + ObjectModelModifier... modifiers) { ObjectModelAssociationClassImpl associationClass = new ObjectModelAssociationClassImpl(); createClass(associationClass, name, packageName, modifiers); // Add associationClass in attrAssociationA - ObjectModelAttributeImpl attrA = (ObjectModelAttributeImpl) attrAssociationA; + ObjectModelAttributeImpl attrA = + (ObjectModelAttributeImpl) attrAssociationA; attrA.setAssociationClassName(associationClass.getQualifiedName()); // Add associationClass in attrAssociationB - ObjectModelAttributeImpl attrB = (ObjectModelAttributeImpl) attrAssociationB; + ObjectModelAttributeImpl attrB = + (ObjectModelAttributeImpl) attrAssociationB; attrB.setAssociationClassName(associationClass.getQualifiedName()); // Create participantA @@ -375,7 +408,8 @@ new ObjectModeImplAssociationClassParticipant(); participantA.setAttribute(attrA.getName()); - ObjectModelClassifier classifierA = (ObjectModelClassifier) attrA.getDeclaringElement(); + ObjectModelClassifier classifierA = + (ObjectModelClassifier) attrA.getDeclaringElement(); participantA.setName(classifierA.getQualifiedName()); associationClass.addParticipant(participantA); @@ -385,7 +419,8 @@ new ObjectModeImplAssociationClassParticipant(); participantB.setAttribute(attrB.getName()); - ObjectModelClassifier classifierB = (ObjectModelClassifier) attrB.getDeclaringElement(); + ObjectModelClassifier classifierB = + (ObjectModelClassifier) attrB.getDeclaringElement(); participantB.setName(classifierB.getQualifiedName()); associationClass.addParticipant(participantB); @@ -406,13 +441,16 @@ * @throws IllegalArgumentException illegal Modifier */ public ObjectModelOperation addOperation(ObjectModelClassifier classifier, - String name, String returnType, ObjectModelModifier... modifiers) + String name, + String returnType, + ObjectModelModifier... modifiers) throws IllegalArgumentException { ObjectModelOperationImpl result = new ObjectModelOperationImpl(); result.setName(name); if (returnType != null) { - ObjectModelParameterImpl returnParameter = new ObjectModelParameterImpl(); + ObjectModelParameterImpl returnParameter = + new ObjectModelParameterImpl(); returnParameter.setType(returnType); result.setReturnParameter(returnParameter); } @@ -439,13 +477,32 @@ } /** + * Add an operation to a classifier. + * Modifiers allowed : STATIC, ABSTRACT, PUBLIC, PRIVATE, PROTECTED, PACKAGE. + * The last visibility set will be keeped. + * + * @param classifier where the operation will be added + * @param operation operation to add + * @return the added operation (says the given parameter) + * @since 2.1.2 + */ + public ObjectModelOperation addOperation(ObjectModelClassifier classifier, + ObjectModelOperation operation) { + + ((ObjectModelClassifierImpl) classifier).addOperation( + (ObjectModelOperationImpl) operation); + return operation; + } + + /** * Set the body code for an Operation. * * @param operation where the code will be added * @param body code to add to the operation */ public void setOperationBody(ObjectModelOperation operation, String body) { - ObjectModelOperationImpl operationImpl = (ObjectModelOperationImpl) operation; + ObjectModelOperationImpl operationImpl = + (ObjectModelOperationImpl) operation; operationImpl.setBodyCode(body); } @@ -455,7 +512,8 @@ * @param classifier where the interface will be added * @param interfaceQualifiedName interface qualified name */ - public void addInterface(ObjectModelClassifier classifier, String interfaceQualifiedName) { + public void addInterface(ObjectModelClassifier classifier, + String interfaceQualifiedName) { ObjectModelClassifierImpl impl = (ObjectModelClassifierImpl) classifier; ObjectModelImplRef interfacez = new ObjectModelImplRef(); @@ -470,10 +528,12 @@ * @param clazz where the superclass will be added * @param superclassQualifiedName superclass qualified name */ - public void addSuperclass(ObjectModelClass clazz, String superclassQualifiedName) { + public void addSuperclass(ObjectModelClass clazz, + String superclassQualifiedName) { ObjectModelClassImpl impl = (ObjectModelClassImpl) clazz; - ObjectModelImplSuperClassRef superclass = new ObjectModelImplSuperClassRef(); + ObjectModelImplSuperClassRef superclass = + new ObjectModelImplSuperClassRef(); superclass.setName(superclassQualifiedName); impl.addSuperclass(superclass); @@ -519,7 +579,8 @@ inner.setObjectModelImpl(impl.getModel()); if (log.isDebugEnabled()) { - log.debug("Add inner classifier for " + clazz.getQualifiedName() + " : " + inner.getQualifiedName()); + log.debug("Add inner classifier for " + clazz.getQualifiedName() + + " : " + inner.getQualifiedName()); } return inner; @@ -533,7 +594,9 @@ * @param name parameter name * @return the new ObjectModelParameter added */ - public ObjectModelParameter addParameter(ObjectModelOperation operation, String type, String name) { + public ObjectModelParameter addParameter(ObjectModelOperation operation, + String type, + String name) { ObjectModelOperationImpl impl = (ObjectModelOperationImpl) operation; ObjectModelParameterImpl param = new ObjectModelParameterImpl(); param.setType(type); @@ -561,7 +624,8 @@ * @param element where the documentation will be setted * @param documentation String documentation for the element */ - public void setDocumentation(ObjectModelElement element, String documentation) { + public void setDocumentation(ObjectModelElement element, + String documentation) { ObjectModelElementImpl impl = (ObjectModelElementImpl) element; impl.setDocumentation(documentation); } @@ -604,7 +668,8 @@ * @param attribute where the multiplicity will be setted * @param multiplicity String description for the element */ - public void setMinMultiplicity(ObjectModelAttribute attribute, int multiplicity) { + public void setMinMultiplicity(ObjectModelAttribute attribute, + int multiplicity) { ObjectModelAttributeImpl impl = (ObjectModelAttributeImpl) attribute; impl.setMinMultiplicity(multiplicity); } @@ -615,7 +680,8 @@ * @param attribute where the multiplicity will be setted * @param multiplicity String description for the element */ - public void setMaxMultiplicity(ObjectModelAttribute attribute, int multiplicity) { + public void setMaxMultiplicity(ObjectModelAttribute attribute, + int multiplicity) { ObjectModelAttributeImpl impl = (ObjectModelAttributeImpl) attribute; impl.setMaxMultiplicity(multiplicity); }
participants (1)
-
tchemit@users.nuiton.org