Author: bpoussin Date: 2009-09-04 16:54:57 +0200 (Fri, 04 Sep 2009) New Revision: 626 Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/JavaClassBuilder.java Modified: trunk/eugene/changelog.txt trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelClass.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelClassifier.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelElement.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelOperation.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassImpl.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassifierImpl.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelOperationImpl.java trunk/eugene/src/site/rst/Todo.rst Log: - ajout du support de static sur tout type d'element (manque le support dans le xsl) - une interface peu avoir des attributs (s'ils sont statics) donc deplacement des attributs dans classifier - debut d'implantation du JavaClassBuilder - ajout du support du contenu (bodyCode) pour les operations - le changelog est en avance sur ce qui est fait, mais j'espere que ca va changer :) Modified: trunk/eugene/changelog.txt =================================================================== --- trunk/eugene/changelog.txt 2009-08-25 22:40:23 UTC (rev 625) +++ trunk/eugene/changelog.txt 2009-09-04 14:54:57 UTC (rev 626) @@ -1,3 +1,10 @@ +1.0.1 + * 20090903 [poussin] move attribute from class to classifier, interface can have static attribute + * 20090903 [poussin] add JavaClassBuilder + * 20090903 [poussin] add new generator type JavaClassGenerator + * 20090903 [poussin] add bodyCode to ObjectModelOperation + * 20090903 [poussin] add static declaration to ObjectModelElement + 1.0.0 xxx xxx * Add multiple models loading and restricted package generation * Add Enumeration support Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/JavaClassBuilder.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/JavaClassBuilder.java (rev 0) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/JavaClassBuilder.java 2009-09-04 14:54:57 UTC (rev 626) @@ -0,0 +1,60 @@ +/* *##% + * Copyright (c) 2009 poussin. All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + *##%*/ + +package org.nuiton.eugene.models.object; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.eugene.models.object.xml.ObjectModelClassImpl; +import org.nuiton.eugene.models.object.xml.ObjectModelClassifierImpl; +import org.nuiton.eugene.models.object.xml.ObjectModelInterfaceImpl; +import org.nuiton.eugene.models.object.xml.ObjectModelOperationImpl; + +/** + * class that help to build java class or interface object. + * + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class JavaClassBuilder { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(JavaClassBuilder.class); + + public ObjectModelClass createClass(String name) { + ObjectModelClassImpl result = new ObjectModelClassImpl(); + return result; + } + + public ObjectModelInterface createInterface(String name) { + ObjectModelInterfaceImpl result = new ObjectModelInterfaceImpl(); + return result; + } + + public ObjectModelOperation addOperation(ObjectModelClassifier clazz, + String name, String failbackName) { + ObjectModelOperationImpl result = new ObjectModelOperationImpl(); + result.setName(name); + ((ObjectModelClassifierImpl)clazz).addOperation(result); + return result; + } +} Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelClass.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelClass.java 2009-08-25 22:40:23 UTC (rev 625) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelClass.java 2009-09-04 14:54:57 UTC (rev 626) @@ -69,22 +69,6 @@ String discriminator); /** - * Returns all attributes defined on this class. - * @see ObjectModelAttribute - * - * @return a Collection containing all ObjectModelAttribute for this class. - */ - public Collection<ObjectModelAttribute> getAttributes(); - - /** - * Returns the attribute corresponding to the given name, or null if the class contains no attribute for this name. - * - * @param attributeName attribute name - * @return the ObjectModelAttribute of the found attribute, or null if the class contains no attribute for this name. - */ - public ObjectModelAttribute getAttribute(String attributeName); - - /** * Returns whether this class is abstract or not. * * @return a boolean indicating whether this class is abstract or not. @@ -102,11 +86,4 @@ public Collection<ObjectModelOperation> getAllSuperclassOperations( boolean distinct); - /** - * Returns all attributes defined on all super class extended by this - * classifier, directly or indirectly. - * @return a Collection of ObjectModelAttribute - */ - public Collection<ObjectModelAttribute> getAllOtherAttributes(); - } //ObjectModelClass Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelClassifier.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelClassifier.java 2009-08-25 22:40:23 UTC (rev 625) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelClassifier.java 2009-09-04 14:54:57 UTC (rev 626) @@ -95,8 +95,37 @@ public Collection<ObjectModelOperation> getAllOtherOperations( boolean distinct); + /** + * Returns all attributes defined on this class. + * @see ObjectModelAttribute + * + * @return a Collection containing all ObjectModelAttribute for this class. + */ + public Collection<ObjectModelAttribute> getAttributes(); /** + * Returns the attribute corresponding to the given name, or null if the class contains no attribute for this name. + * + * @param attributeName attribute name + * @return the ObjectModelAttribute of the found attribute, or null if the class contains no attribute for this name. + */ + public ObjectModelAttribute getAttribute(String attributeName); + + /** + * Returns all attributes defined on all interfaces implemented by this + * classifier, directly or indirectly. + * @return a Collection of ObjectModelAttribute + */ + public Collection<ObjectModelAttribute> getAllInterfaceAttributes(); + + /** + * Returns all attributes defined on all super class extended by this + * classifier, directly or indirectly. + * @return a Collection of ObjectModelAttribute + */ + public Collection<ObjectModelAttribute> getAllOtherAttributes(); + + /** * Returns all dependencies of this client classifier * * @return a Collection of ObjectModelDependency Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelElement.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelElement.java 2009-08-25 22:40:23 UTC (rev 625) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelElement.java 2009-09-04 14:54:57 UTC (rev 626) @@ -62,10 +62,12 @@ public String getDescription(); /** - * Returns the source documentation part associated with this element. - * - * @return the source documentation part associated with this element. - */ + * Returns the source documentation part associated with this element. + * Source documentation is at end of documentation and are separated of + * over documentation by "--" + * + * @return the source documentation part associated with this element. + */ public String getSourceDocumentation(); /** @@ -108,6 +110,13 @@ public boolean hasTagValue(String tagValue); /** + * Return if this element has static declaration, only valid when + * getDeclaringElement is classifier + * @return true if element is static + */ + public boolean isStatic(); + + /** * Returns all comments lied to this particular model element * * @return a List containing all comments for this element as Strings. Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelOperation.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelOperation.java 2009-08-25 22:40:23 UTC (rev 625) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelOperation.java 2009-09-04 14:54:57 UTC (rev 626) @@ -84,4 +84,10 @@ */ public Set<String> getExceptions(); + /** + * Return body of the operation (source code) + * @return body of the operation (source code) + */ + public String getBodyCode(); + } //ObjectModelOperation Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassImpl.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassImpl.java 2009-08-25 22:40:23 UTC (rev 625) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassImpl.java 2009-09-04 14:54:57 UTC (rev 626) @@ -51,8 +51,6 @@ protected Map<ObjectModelClass, String> superclassesDiscriminators = new HashMap<ObjectModelClass, String>(); protected List<ObjectModelImplRef> superclassesRefs = new ArrayList<ObjectModelImplRef>(); protected List<ObjectModelClass> specialisations = null; - protected Map<String, ObjectModelAttribute> attributes = new HashMap<String, ObjectModelAttribute>(); - protected List<ObjectModelAttribute> orderedAttributes = new ArrayList<ObjectModelAttribute>(); protected boolean abstractz = false; public ObjectModelClassImpl() { @@ -60,22 +58,11 @@ } public void addSuperclass(ObjectModelImplRef ref) { - //if (ref == null) - //return new ObjectModelImplSuperClassRef(); superclassesRefs.add(ref); - //return ref; + // superclassesRefs is modified, superclasses must be reset + superclasses = null; } - public void addAttribute(ObjectModelAttributeImpl attribute) { - //if (attribute == null) - //return new ObjectModelAttributeImpl(objectModelImpl, this); - attribute.postInit(); - attribute.setDeclaringElement(this); - attributes.put(attribute.getName(), attribute); - orderedAttributes.add(attribute); - //return attribute; - } - public void setAbstract(boolean abstractz) { this.abstractz = abstractz; } @@ -154,24 +141,7 @@ return discriminatedSpecialisations; } - @Override - public Collection<ObjectModelAttribute> getAttributes() { - return orderedAttributes; - } - /** - * Returns the attribute corresponding to the given name, or null if the - * class contains no attribute for this name. - * - * @return the ObjectModelAttribute of the found attribute, or null if the - * class contains no attribute for this name. - */ - @Override - public ObjectModelAttribute getAttribute(String attributeName) { - return (attributeName == null ? null : attributes.get(attributeName)); - } - - /** * Returns whether this class is abstract or not. * * @return a boolean indicating whether this class is abstract or not. @@ -215,7 +185,7 @@ @Override public Collection<ObjectModelAttribute> getAllOtherAttributes() { - Collection<ObjectModelAttribute> result = new LinkedList<ObjectModelAttribute>(); + Collection<ObjectModelAttribute> result = getAllInterfaceAttributes(); getAllOtherAttributes(result); return result; } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassifierImpl.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassifierImpl.java 2009-08-25 22:40:23 UTC (rev 625) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassifierImpl.java 2009-09-04 14:54:57 UTC (rev 626) @@ -19,11 +19,14 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import org.nuiton.eugene.models.object.ObjectModelAttribute; import org.nuiton.eugene.models.object.ObjectModelClassifier; import org.nuiton.eugene.models.object.ObjectModelDependency; import org.nuiton.eugene.models.object.ObjectModelInterface; @@ -49,6 +52,8 @@ protected List<ObjectModelInterface> interfaces = null; protected List<ObjectModelImplRef> interfacesRefs = new ArrayList<ObjectModelImplRef>(); protected List<ObjectModelOperation> operations = new ArrayList<ObjectModelOperation>(); + protected Map<String, ObjectModelAttribute> attributes = new HashMap<String, ObjectModelAttribute>(); + protected List<ObjectModelAttribute> orderedAttributes = new ArrayList<ObjectModelAttribute>(); protected List<ObjectModelDependency> dependencies = new ArrayList<ObjectModelDependency>(); protected String type = null; @@ -90,6 +95,13 @@ //return operation; } + public void addAttribute(ObjectModelAttributeImpl attribute) { + attribute.postInit(); + attribute.setDeclaringElement(this); + attributes.put(attribute.getName(), attribute); + orderedAttributes.add(attribute); + } + public void addDependency(ObjectModelDependencyImpl dependency) { dependency.postInit(); dependency.setClient(this); @@ -138,11 +150,13 @@ return operations; } + @Override public Collection<ObjectModelOperation> getAllOtherOperations( boolean distinct) { return getAllInterfaceOperations(distinct); } + @Override public Collection<ObjectModelOperation> getAllInterfaceOperations( boolean distinct) { Collection<ObjectModelOperation> result = null; @@ -165,6 +179,46 @@ } @Override + public Collection<ObjectModelAttribute> getAttributes() { + return orderedAttributes; + } + + /** + * Returns the attribute corresponding to the given name, or null if the + * class contains no attribute for this name. + * + * @return the ObjectModelAttribute of the found attribute, or null if the + * class contains no attribute for this name. + */ + @Override + public ObjectModelAttribute getAttribute(String attributeName) { + return (attributeName == null ? null : attributes.get(attributeName)); + } + + @Override + public Collection<ObjectModelAttribute> getAllInterfaceAttributes() { + Collection<ObjectModelAttribute> result = new LinkedList<ObjectModelAttribute>(); + getAllInterfaceAttributes(result); + return result; + } + + @Override + public Collection<ObjectModelAttribute> getAllOtherAttributes() { + Collection<ObjectModelAttribute> result = getAllInterfaceAttributes(); + return result; + } + + protected Collection<ObjectModelAttribute> getAllInterfaceAttributes( + Collection<ObjectModelAttribute> result) { + for (Iterator<?> i = getInterfaces().iterator(); i.hasNext();) { + ObjectModelClassifierImpl clazz = (ObjectModelClassifierImpl) i.next(); + result.addAll(clazz.getAttributes()); + clazz.getAllInterfaceAttributes(result); + } + return result; + } + + @Override public Collection<ObjectModelDependency> getDependencies() { return this.dependencies; } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java 2009-08-25 22:40:23 UTC (rev 625) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java 2009-09-04 14:54:57 UTC (rev 626) @@ -43,6 +43,7 @@ protected ObjectModelElement declaringElement; protected String name = null; + protected boolean isStatic = false; protected String documentation = null; protected List<String> stereotypes = new ArrayList<String>(); protected Map<String, String> tagValues = new HashMap<String, String>(); @@ -106,10 +107,15 @@ return tagValue; } + public void setStatic(boolean isStatic) { + this.isStatic = isStatic; + } + public void addComment(String comment) { this.comments.add(comment); } + @Override public String getName() { return name; } @@ -119,6 +125,7 @@ * * @return the ObjectModelElement in which this element is defined, or null if there's none. */ + @Override public ObjectModelElement getDeclaringElement() { return declaringElement; } @@ -128,6 +135,7 @@ * * @return the whole documentation associated with this element. */ + @Override public String getDocumentation() { if (documentation == null && hasTagValue("documentation")) { return getTagValue("documentation"); @@ -140,6 +148,7 @@ * * @return the description associated with this element. */ + @Override public String getDescription() { return getDocumentation().substring(0, getDocumentation().indexOf("--")); } @@ -149,6 +158,7 @@ * * @return the source documentation part associated with this element. */ + @Override public String getSourceDocumentation() { return getDocumentation().substring(getDocumentation().indexOf("--") + 2); } @@ -158,6 +168,7 @@ * * @return a Collection containing all stereotypes names associated with this element as String. */ + @Override public Collection<String> getStereotypes() { return stereotypes; } @@ -167,6 +178,7 @@ * * @return a boolean indicating whether this element has a stereotype corresponding to the given name, or not. */ + @Override public boolean hasStereotype(String stereotypeName) { return stereotypes.contains(stereotypeName); } @@ -177,6 +189,7 @@ * * @return a Map containing all tagValues associated with this element */ + @Override public Map<String, String> getTagValues() { return tagValues; } @@ -186,6 +199,7 @@ * * @return the value of the found tagValue, or null if the element has no associated tagValue for this name. */ + @Override public String getTagValue(String tagValue) { return (tagValue == null ? null : (String) tagValues.get(tagValue)); } @@ -195,15 +209,22 @@ * * @return a boolean indicating whether this element has a tagValue corresponding to the given name, or not. */ + @Override public boolean hasTagValue(String tagValue) { return tagValues.containsKey(tagValue); } + @Override + public boolean isStatic() { + return isStatic; + } + /** * Returns all comments lied to this particular model element * * @return a List containing all comments for this element as Strings. */ + @Override public List<String> getComments() { return comments; } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelOperationImpl.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelOperationImpl.java 2009-08-25 22:40:23 UTC (rev 625) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelOperationImpl.java 2009-09-04 14:54:57 UTC (rev 626) @@ -53,6 +53,8 @@ protected Set<String> exceptions = new HashSet<String>(); + protected String bodyCode = ""; + public ObjectModelOperationImpl() { super(); } @@ -111,11 +113,24 @@ this.returnParameter = returnParameter; } + public void setBodyCode(String bodyCode) { + this.bodyCode = bodyCode; + } + + /** + * Add some code to current body + * @param bodyCode code to add + */ + public void addBodyCode(String bodyCode) { + this.bodyCode += bodyCode; + } + @Override public ObjectModelParameter getReturnParameter() { return this.returnParameter; } + @Override public String getReturnType() { if (returnParameter != null) { return returnParameter.getType(); @@ -123,6 +138,7 @@ return "void"; } + @Override public String getVisibility() { return visibility; } @@ -132,10 +148,12 @@ * * @return a boolean indicating whether this operation is abstract or not. */ + @Override public boolean isAbstract() { return abstractz; } + @Override public Collection<ObjectModelParameter> getParameters() { return parameters; } @@ -152,8 +170,14 @@ this.exceptions.add(raisedParameter.getType()); } + @Override public Set<String> getExceptions() { return exceptions; } + @Override + public String getBodyCode() { + return bodyCode; + } + } Modified: trunk/eugene/src/site/rst/Todo.rst =================================================================== --- trunk/eugene/src/site/rst/Todo.rst 2009-08-25 22:40:23 UTC (rev 625) +++ trunk/eugene/src/site/rst/Todo.rst 2009-09-04 14:54:57 UTC (rev 626) @@ -10,8 +10,12 @@ Idées ou choses à faire ======================= +- support des InnerClasses (en xmi argo: la classe est declarer dans une classe + dans un element UML:Namespace.ownedElement) -- Création d'un plugin Eclipse pour la coloration syntaxique des templates +- support des static (tout element declarer dans une class/interface: methode, + attribut, enumeration, class, ...) + (en xmi argo: ownerScope='classifier' ou ownerScope='instance') - peut-etre faire des tests unitaires avec http://juxy.tigris.org/ pour le xls