r949 - in trunk/eugene/src/main/java/org/nuiton/eugene: java models models/object models/object/xml models/state/xml
Author: tchemit Date: 2010-08-11 20:26:10 +0200 (Wed, 11 Aug 2010) New Revision: 949 Url: http://nuiton.org/repositories/revision/eugene/949 Log: Evolution #807: make possible to add a tagValue to ObjectElement and ObjectModel by programation in Transformer Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java trunk/eugene/src/main/java/org/nuiton/eugene/models/Model.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelElement.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelTransformer.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/ObjectModelImpl.java trunk/eugene/src/main/java/org/nuiton/eugene/models/state/xml/StateModelImpl.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-11 14:46:08 UTC (rev 948) +++ trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java 2010-08-11 18:26:10 UTC (rev 949) @@ -48,7 +48,6 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.List; import java.util.Set; /** @@ -161,6 +160,14 @@ builder.addImport(classifier, imports.getName()); } + public void addTagValue(String name, String value) { + builder.addTagValue(name, value); + } + + public void addTagValue(ObjectModelElement element, String name, String value) { + builder.addTagValue(element, name, value); + } + public String getConstantName(String propertyName) { return getConstantPrefix() + builder.getConstantName(propertyName); } @@ -327,6 +334,7 @@ * * @param source operation to clone * @param destination classifier where result operation will be added + * @param documentation flag to add documentation if some found in model * @param modifiers extra modifiers * @return the new operation created in destination classifier */ Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/Model.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/Model.java 2010-08-11 14:46:08 UTC (rev 948) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/Model.java 2010-08-11 18:26:10 UTC (rev 949) @@ -72,4 +72,15 @@ */ String getTagValue(String tagValue); + /** + * Adds the given {@code value} associated to the {@code tagValue}. + * + * Note: If a previous tag value was definied, then it will be replaced. + * + * @param tagValue the name of the tag value + * @param value the value to associate + * @since 2.1.2 + */ + void addTagValue(String tagValue, String value); + } //Model 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 2010-08-11 14:46:08 UTC (rev 948) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelElement.java 2010-08-11 18:26:10 UTC (rev 949) @@ -117,6 +117,17 @@ boolean hasTagValue(String tagValue); /** + * Adds the given {@code value} associated to the {@code tagValue}. + * + * Note: If a previous tag value was definied, then it will be replaced. + * + * @param tagValue the name of the tag value + * @param value the value to associate + * @since 2.1.2 + */ + void addTagValue(String tagValue, String value); + + /** * Return if this element has static declaration, only valid when * getDeclaringElement is classifier. Not possible for the moment * to have static innerClass (from XMI 1.2 and 2.1). Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelTransformer.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelTransformer.java 2010-08-11 14:46:08 UTC (rev 948) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelTransformer.java 2010-08-11 18:26:10 UTC (rev 949) @@ -44,7 +44,7 @@ /** * Le model associé au transformer est le model d'entree. Le modele de sortie - * peut etre initialiser via la methode {@link org.nuiton.eugene.Transformer#initOutputModel()}. + * peut etre initialiser via la methode {@link Transformer#initOutputModel()}. * Il est également possible de surcharger la methode {@link #debugOutputModel()} * pour verifier le resultat de la transformation. * Par defaut la methode appelle la methode 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 2010-08-11 14:46:08 UTC (rev 948) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java 2010-08-11 18:26:10 UTC (rev 949) @@ -31,6 +31,9 @@ import java.util.List; import java.util.Map; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.eugene.models.object.ObjectModelElement; /** @@ -44,17 +47,23 @@ * By : */ public class ObjectModelElementImpl implements ObjectModelElement { + /** logger */ + private static final Log log = LogFactory.getLog(ObjectModelElementImpl.class); + protected ObjectModelImpl objectModelImpl; protected ObjectModelElement declaringElement; protected String name; protected boolean isStatic; protected String documentation; - protected List<String> stereotypes = new ArrayList<String>(); - protected Map<String, String> tagValues = new HashMap<String, String>(); - protected List<String> comments = new ArrayList<String>(); + protected List<String> stereotypes; + protected Map<String, String> tagValues; + protected List<String> comments; public ObjectModelElementImpl() { + tagValues = new HashMap<String, String>(); + stereotypes = new ArrayList<String>(); + comments = new ArrayList<String>(); } /** @@ -107,7 +116,7 @@ if (tagValue == null) { return new ObjectModelImplTagValue(); } - tagValues.put(tagValue.getName(), tagValue.getValue()); + addTagValue(tagValue.getName(), tagValue.getValue()); return tagValue; } @@ -124,21 +133,11 @@ return name; } - /** - * Returns the element in which this element is defined, or null if there's none. - * - * @return the ObjectModelElement in which this element is defined, or null if there's none. - */ @Override public ObjectModelElement getDeclaringElement() { return declaringElement; } - /** - * Returns the whole documentation associated with this element (description + source documentation). - * - * @return the whole documentation associated with this element. - */ @Override public String getDocumentation() { if (documentation == null && hasTagValue("documentation")) { @@ -147,87 +146,55 @@ return documentation; } - /** - * Returns the description associated with this element. - * - * @return the description associated with this element. - */ @Override public String getDescription() { return getDocumentation().substring(0, getDocumentation().indexOf("--")); } - /** - * Returns the source documentation part associated with this element. - * - * @return the source documentation part associated with this element. - */ @Override public String getSourceDocumentation() { return getDocumentation().substring(getDocumentation().indexOf("--") + 2); } - /** - * Returns the stereotypes names associated with this element. - * - * @return a Collection containing all stereotypes names associated with this element as String. - */ @Override public Collection<String> getStereotypes() { return stereotypes; } - /** - * Returns whether this element has a stereotype corresponding to the given name, or not. - * - * @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); } - /** - * Returns the tagValues associated with this element. - * For each entry, the key is the name of the tagValue, the value is the value of the tagValue :-) - * - * @return a Map containing all tagValues associated with this element - */ @Override public Map<String, String> getTagValues() { return tagValues; } - /** - * Returns the tagValue corresponding to the given name, or null if the element has no associated tagValue for this name. - * - * @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 : tagValues.get(tagValue); } - /** - * Returns whether this element has a tagValue corresponding to the given name, or not. - * - * @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 void addTagValue(String tagValue, String value) { + String oldValue = getTagValue(tagValue); + if (StringUtils.isNotEmpty(oldValue)) { + log.warn("Replace tagValue '" + tagValue + "' (old:" + oldValue + ", new: " + value + ")"); + } + tagValues.put(tagValue,value); + } + + @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/ObjectModelImpl.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java 2010-08-11 14:46:08 UTC (rev 948) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java 2010-08-11 18:26:10 UTC (rev 949) @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.eugene.models.object.ObjectModel; @@ -59,9 +60,8 @@ * @plexus.component role="org.nuiton.eugene.models.Model" role-hint="objectmodel" */ public class ObjectModelImpl implements ObjectModel { - /** - * logger - */ + + /** logger */ private static final Log log = LogFactory.getLog(ObjectModelImpl.class); protected String name; protected String version; @@ -469,30 +469,25 @@ return tagValue; } - /** - * Returns the tagValues associated with this element. For each entry, the - * key is the name of the tagValue, the value is the value of the tagValue - * :-) - * - * @return a Map containing all tagValues associated with this element - */ @Override public Map<String, String> getTagValues() { return tagValues; } - /** - * Returns the tagValue corresponding to the given name, or null if the - * element has no associated tagValue for this name. - * - * @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 : tagValues.get(tagValue); } + @Override + public void addTagValue(String tagValue, String value) { + String oldValue = getTagValue(tagValue); + if (StringUtils.isNotEmpty(oldValue)) { + log.warn("Replace tagValue '" + tagValue + "' (old:" + oldValue + ", new: " + value + ")"); + } + tagValues.put(tagValue,value); + } + /** * Get the extension associated to the reference (unique). Create it if not exist. * @param <O> object type returned Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/state/xml/StateModelImpl.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/state/xml/StateModelImpl.java 2010-08-11 14:46:08 UTC (rev 948) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/state/xml/StateModelImpl.java 2010-08-11 18:26:10 UTC (rev 949) @@ -41,7 +41,7 @@ * @version $Revision$ * * Last update : $Date$ - * By : * + * * @plexus.component role="org.nuiton.eugene.models.Model" role-hint="statemodel" */ public class StateModelImpl implements StateModel { @@ -121,22 +121,11 @@ return modelTagValues; } - /** - * Add a tag value - * - * @param key key - * @param value value - */ + @Override public void addTagValue(String key, String value) { modelTagValues.put(key, value); } - /** - * Get a tag value - * - * @return the value of the found tagValue, or null if the element has no - * associated tagValue for this name. - */ @Override public String getTagValue(String key) { return key == null ? null : modelTagValues.get(key); @@ -151,11 +140,6 @@ this.version = version; } - /** - * Get model version. - * - * @return model version - */ @Override public String getVersion() { return version;
participants (1)
-
tchemit@users.nuiton.org