r1014 - in trunk: . ant-eugene-task eugene eugene/src/main/java/org/nuiton/eugene eugene/src/main/java/org/nuiton/eugene/java eugene/src/main/java/org/nuiton/eugene/models/object eugene/src/main/java/org/nuiton/eugene/models/object/xml eugene/src/test/java/org/nuiton/eugene maven-eugene-plugin
Author: tchemit Date: 2010-11-28 21:13:58 +0100 (Sun, 28 Nov 2010) New Revision: 1014 Url: http://nuiton.org/repositories/revision/eugene/1014 Log: Pass to version 2.3 Evolution #1117: Remove deprecated method isIndexed on ObjectModelAttribute Evolution #1113: Introduce a safe api to manager tag values and stereotypes Depreciate some old stuffs Added: trunk/eugene/src/main/java/org/nuiton/eugene/StereotypeDefinition.java trunk/eugene/src/main/java/org/nuiton/eugene/TagValueDefinition.java Modified: trunk/ant-eugene-task/pom.xml trunk/eugene/pom.xml trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java trunk/eugene/src/main/java/org/nuiton/eugene/EugeneStereoTypes.java trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java trunk/eugene/src/main/java/org/nuiton/eugene/Template.java trunk/eugene/src/main/java/org/nuiton/eugene/Transformer.java trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGeneratorUtil.java trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelAttribute.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelBuilder.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelElement.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelParameter.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelAttributeImpl.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelParameterImpl.java trunk/eugene/src/test/java/org/nuiton/eugene/TestHelper.java trunk/maven-eugene-plugin/pom.xml trunk/pom.xml Modified: trunk/ant-eugene-task/pom.xml =================================================================== --- trunk/ant-eugene-task/pom.xml 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/ant-eugene-task/pom.xml 2010-11-28 20:13:58 UTC (rev 1014) @@ -36,7 +36,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>eugene</artifactId> - <version>2.2.1-SNAPSHOT</version> + <version>2.3-SNAPSHOT</version> </parent> <groupId>org.nuiton.eugene</groupId> Modified: trunk/eugene/pom.xml =================================================================== --- trunk/eugene/pom.xml 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/pom.xml 2010-11-28 20:13:58 UTC (rev 1014) @@ -35,7 +35,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>eugene</artifactId> - <version>2.2.1-SNAPSHOT</version> + <version>2.3-SNAPSHOT</version> </parent> <groupId>org.nuiton.eugene</groupId> Modified: trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -56,14 +56,14 @@ * <p/> * It will replace each time the input model by the generated output model. * - * @since 2.2.1 + * @since 2.3 */ protected Class<? extends Transformer<M, M>>[] transformerTypes; /** * Templates to apply to the model. * - * @since 2.2.1, replace the old transformers field. + * @since 2.3, replace the old transformers field. */ protected Class<? extends Template<M>>[] templateTypes; @@ -72,7 +72,7 @@ /** * @param templateTypes templates to apply on model - * @deprecated since 2.2.1, prefer use the default constructor, the invoke + * @deprecated since 2.3, prefer use the default constructor, the invoke * setters {@link #setTemplateTypes(Class[])} and * {@link #setTransformerTypes(Class[])}. */ @@ -144,7 +144,7 @@ * @param model incoming model to transform * @param transformers list of transformers to apply to the model * @return the final transformed model - * @since 2.2.1 + * @since 2.3 */ protected M applyTransformers(M model, List<? extends Transformer<M, M>> transformers) { @@ -171,7 +171,7 @@ * @param templates templates to apply the incoming model * @param destDir the destination directory where to generate * @throws IOException if any IO errors while generating files - * @since 2.2.1 + * @since 2.3 */ protected void applyTemplates(M model, List<? extends Template<M>> templates, @@ -230,7 +230,7 @@ /** * @return the instances of templates to apply to the model. - * @deprecated since 2.2.1, prefer use the {@link #getInstances(Class[])} + * @deprecated since 2.3, prefer use the {@link #getInstances(Class[])} */ @Deprecated protected List<Template<M>> getTemplates() { @@ -273,7 +273,7 @@ /** * @return the template types to apply - * @deprecated since 2.2.1, use the method {@link #getTemplateTypes()} instead. + * @deprecated since 2.3, use the method {@link #getTemplateTypes()} instead. */ @Deprecated public Class<? extends Template<M>>[] getTransformers() { Modified: trunk/eugene/src/main/java/org/nuiton/eugene/EugeneStereoTypes.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/EugeneStereoTypes.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/EugeneStereoTypes.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -25,6 +25,9 @@ package org.nuiton.eugene; import org.nuiton.eugene.java.JavaBeanTransformer; +import org.nuiton.eugene.java.JavaGeneratorUtil; +import org.nuiton.eugene.models.object.ObjectModelAttribute; +import org.nuiton.eugene.models.object.ObjectModelClassifier; /** * Defines all stereotypes managed by Eugene. @@ -33,14 +36,24 @@ * own stereotypes, to get a unique place where to find stereotypes. * * @author tchemit <chemit@codelutin.com> - * @since 2.2.1 + * @since 2.3 */ public interface EugeneStereoTypes { /** - * Stereotype for JavaBean objects. + * Stereotype for JavaBean objects to place on a classifier. * * @see JavaBeanTransformer + * @see JavaGeneratorUtil#hasBeanStereotype(ObjectModelClassifier) */ + @StereotypeDefinition(target = ObjectModelClassifier.class) String STEREOTYPE_BEAN = "bean"; + + /** + * Stéréotype pour les attributs à indexer en base. + * + * @see GeneratorUtil#hasIndexedStereotype(ObjectModelAttribute) + */ + @StereotypeDefinition(target = ObjectModelAttribute.class) + String STEREOTYPE_INDEXED = "indexed"; } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -25,41 +25,69 @@ package org.nuiton.eugene; import org.nuiton.eugene.java.JavaBeanTransformer; +import org.nuiton.eugene.java.JavaGeneratorUtil; +import org.nuiton.eugene.models.object.ObjectModel; +import org.nuiton.eugene.models.object.ObjectModelClassifier; +import org.nuiton.eugene.models.object.ObjectModelElement; +import org.nuiton.eugene.models.object.ObjectModelReader; /** * Defines all tag values managed by Eugene. - * + * <p/> * In another library using eugene, please extends this contract to put your * own tag values, to get a unique place where to find tag values. * * @author tchemit <chemit@codelutin.com> - * @since 2.2.1 + * @since 2.3 */ public interface EugeneTagValues { /** - * tag value to add on constants enumeration (or other incoming dev) + * Tag value to add the version of the model from outside (says in the + * properties file associated to the model).. + * <p/> + * Actually, the eugene api does not use to modify the model. It is only + * used while reading the properties associated with a model and if found is + * directly set to the {@code version} field of the model. + * + * @see ObjectModelReader#loadModelTagvalue(ObjectModel, String, String) + * @since 2.3 + */ + @TagValueDefinition(target = {ObjectModel.class}) + String TAG_VERSION = "version"; + + /** + * Tag value to add on constants enumeration (or other incoming dev) * a prefix to constant to generate. + * <p/> + * You can globaly use it on the complete model or to a specific classifier. + * + * @see JavaGeneratorUtil#getConstantPrefixTagValue(ObjectModel, ObjectModelClassifier) + * @since 2.3 */ + @TagValueDefinition(target = {ObjectModel.class, ObjectModelClassifier.class}) String TAG_CONSTANT_PREFIX = "constantPrefix"; /** - * tag value to set if do not want any pcs (says PropertyChangeSupport in a generated bean). + * Tag value to set if do not want any pcs (says PropertyChangeSupport in a generated bean). + * <p/> + * You can globaly use it on the complete model or to a specific classifier. + * * @see JavaBeanTransformer + * @see JavaGeneratorUtil#getNoPCSTagValue(ObjectModel, ObjectModelClassifier) + * @since 2.3 */ - String TAG_NO_PCS= "noPCS"; + @TagValueDefinition(target = {ObjectModel.class, ObjectModelClassifier.class}) + String TAG_NO_PCS = "noPCS"; /** - * tag value to add the version of the model from outside (says in the - * properties file associated to the model).. + * Tag value to specify the i18n prefix to use whene generating i18n keys. + * <p/> + * You can globaly use it on the complete model or to a specific classifier. * - * @since 2.2.1 + * @see JavaGeneratorUtil#getI18nPrefixTagValue(ObjectModelElement, ObjectModel) + * @since 2.3 */ - String TAG_VERSION = "version"; - - /** - * Tag pour specfier if i18n must be generated. - * @since 2.2.1 - */ + @TagValueDefinition(target = {ObjectModel.class, ObjectModelClassifier.class}) String TAG_I18N_PREFIX = "i18n"; } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -28,21 +28,33 @@ import org.apache.commons.lang.StringUtils; import org.nuiton.eugene.models.Model; -import org.nuiton.eugene.models.object.*; +import org.nuiton.eugene.models.object.ObjectModel; +import org.nuiton.eugene.models.object.ObjectModelAttribute; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelClassifier; +import org.nuiton.eugene.models.object.ObjectModelElement; +import org.nuiton.eugene.models.object.ObjectModelOperation; +import org.nuiton.eugene.models.object.ObjectModelParameter; +import org.nuiton.util.StringUtil; import java.io.File; -import java.util.*; -import org.nuiton.util.StringUtil; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; /** * GeneratorUtil. - * + * <p/> * Created: 25 aout 2003 * * @author Benjamin Poussin <poussin@codelutin.com> Copyright Code Lutin * @version $Revision$ - * Mise à jour: $Date$ - * By : */ + * Mise à jour: $Date$ + * By : + */ public class GeneratorUtil { /** @@ -50,7 +62,7 @@ * eg : org.nuiton.eugene.models -> org.nuiton.eugene * eg : org -> org * warning : org.nuiton.eugene. -> org.nuiton.eugene - * + * * @param packageName package * @return parent package of given package */ @@ -66,8 +78,8 @@ /** * @param qualifiedName the fully qualified name to test * @return class name fr given fully qualified name (return given name if it is not fully qualified) - * eg : org.nuiton.eugene.models.ObjectClass -> ObjectClass - * eg : ObjectClass-> ObjectClass + * eg : org.nuiton.eugene.models.ObjectClass -> ObjectClass + * eg : ObjectClass-> ObjectClass */ public static String getClassNameFromQualifiedName(String qualifiedName) { String className = qualifiedName; @@ -79,7 +91,6 @@ } /** - * * @param qualifiedName the fully qualified name to test * @return the filename for the given qualified name. */ @@ -90,11 +101,10 @@ /** * return all classifiers belonging to the given package recursively. The Collection may be empty. * - * @param model the model where to look at + * @param model the model where to look at * @param packageName the package name to set for classifiers + * @return a Collection containing all classifiers belonging to the given package recursively. * @see ObjectModelClassifier - * - * @return a Collection containing all classifiers belonging to the given package recursively. */ public static Collection<ObjectModelClassifier> getClassifiers( ObjectModel model, String packageName) { @@ -119,16 +129,16 @@ /** * Retourne le type de l'attribut, c-a-d une List ou une collection * ou le type defini si la cardinalité n'est pas multiple - * - * @param attribute the attribute to test + * + * @param attribute the attribute to test * @param useGenerics {@code true} if the attribute use a generic type * @return attribute type */ public static String getAttributeType(ObjectModelParameter attribute, - boolean useGenerics) { + boolean useGenerics) { String result; if (attribute instanceof ObjectModelAttribute - && isNMultiplicity((ObjectModelAttribute) attribute)) { + && isNMultiplicity((ObjectModelAttribute) attribute)) { if (attribute.isOrdered()) { result = List.class.getName(); } else { @@ -145,6 +155,7 @@ /** * Indicates if the specified attribute has a primitive type (byte, boolean, ...) + * * @param attribute the attribute to test * @return true if the attribute has a primitive type */ @@ -155,13 +166,14 @@ } String type = attribute.getType(); return "byte".equals(type) || "short".equals(type) - || "int".equals(type) || "long".equals(type) - || "float".equals(type) || "double".equals(type) - || "char".equals(type) || "boolean".equals(type); + || "int".equals(type) || "long".equals(type) + || "float".equals(type) || "double".equals(type) + || "char".equals(type) || "boolean".equals(type); } /** * return an init value for the specified attribute + * * @param attribute the attribute to test * @return a String with the corresponding attribute init value */ @@ -269,8 +281,8 @@ /** * @param attribute the attribute to test * @return vrai si la cardinalite de l'attribut est superieur a 1, c-a-d - * si MaxMultiplicity == -1 ou > 1 - */ + * si MaxMultiplicity == -1 ou > 1 + */ public static boolean isNMultiplicity(ObjectModelAttribute attribute) { return isNMultiplicity(attribute.getMaxMultiplicity()); } @@ -285,11 +297,10 @@ */ public static boolean isOneMultiplicity(ObjectModelAttribute attribute) { return attribute != null && attribute.getMinMultiplicity() == 1 && - attribute.getMaxMultiplicity() == 1; + attribute.getMaxMultiplicity() == 1; } /** - * * @param word the word to decapitalize * @return the decapitalized word */ @@ -311,7 +322,7 @@ } public static String getParsingExpression(String type, - String attributeStringName) { + String attributeStringName) { if ("byte".equals(type)) { return "Byte.parseByte(" + attributeStringName + ")"; } @@ -346,7 +357,7 @@ } public static String getFormatingExpression(String type, - String attributeStringName) { + String attributeStringName) { if ("byte".equals(type)) { return "Byte.toString(" + attributeStringName + ")"; } @@ -383,20 +394,20 @@ /** * ToString contract for ObjectModelParameter with type and name. This * contract is used in - * {@link StringUtil#join(Iterable, org.nuiton.util.StringUtil.ToString, String, boolean)} + * {@link StringUtil#join(Iterable, org.nuiton.util.StringUtil.ToString, String, boolean)} */ static final StringUtil.ToString<ObjectModelParameter> OBJECT_MODEL_PARAMETER_TO_STRING_TYPE = - new StringUtil.ToString<ObjectModelParameter>() { + new StringUtil.ToString<ObjectModelParameter>() { - @Override - public String toString(ObjectModelParameter param) { - return new StringBuilder(getAttributeType(param)). + @Override + public String toString(ObjectModelParameter param) { + return new StringBuilder(getAttributeType(param)). append(' '). append(param.getName()). toString(); - } - }; + } + }; /** * ToString contract for ObjectModelParameter with name only. This contract @@ -405,28 +416,28 @@ */ static final StringUtil.ToString<ObjectModelParameter> OBJECT_MODEL_PARAMETER_TO_STRING_NAME = - new StringUtil.ToString<ObjectModelParameter>() { + new StringUtil.ToString<ObjectModelParameter>() { - @Override - public String toString(ObjectModelParameter param) { - return param.getName(); - } - }; + @Override + public String toString(ObjectModelParameter param) { + return param.getName(); + } + }; /** - * Used to return the {@code operation} parameters for its declaration : + * Used to return the {@code operation} parameters for its declaration : * type and name of each parameter will be join as a string separated by a * comma. Usefull for operation parameters declaration in templates writing. * * @param operation to treate * @return the string corresponding to the list of operation parameters - * for declaration syntax. + * for declaration syntax. */ public static String getOperationParametersListDeclaration( ObjectModelOperation operation) { String result = StringUtil.join( - operation.getParameters(), + operation.getParameters(), OBJECT_MODEL_PARAMETER_TO_STRING_TYPE, ", ", false); @@ -439,7 +450,7 @@ * * @param operation to treate * @return the string corresponding to the list of operation parameter - * names separated by a ', '. + * names separated by a ', '. */ public static String getOperationParametersListName( ObjectModelOperation operation) { @@ -473,6 +484,7 @@ /** * Renvoie si l'attribut passé en paramètre est premier lexicographiquement * par rapport à son attribut inverse (si celui ci existe). + * * @param attr L'attribut dont on veut savoir s'il est le premier * @return true, si l'attribut est premier (lexico ou pas de reverse attribute), false dans les autres cas */ @@ -492,7 +504,7 @@ * @return true s'il y a documentation, false sinon */ public static boolean hasDocumentation(ObjectModelElement element) { - return notEmpty(element.getDocumentation()); + return StringUtils.isNotEmpty(element.getDocumentation()); } /** @@ -500,7 +512,9 @@ * * @param s la chaine de caractères à tester * @return true si <code>s</code> n'est pas vide + * @deprecated since 2.3, use the method {@link StringUtils#isNotEmpty(String)} */ + @Deprecated public static boolean notEmpty(String s) { return s != null && !"".equals(s); } @@ -515,25 +529,29 @@ * @return la valeur du tagValue ou null */ public static String findTagValue(String tagName, - ObjectModelElement element, Model model) { + ObjectModelElement element, + Model model) { if (element == null) { if (model != null) { - if (notEmpty(model.getTagValue(tagName))) { - return model.getTagValue(tagName); + String value = model.getTagValue(tagName); + if (!StringUtils.isEmpty(value)) { + return value; } } return null; } - if (notEmpty(element.getTagValue(tagName))) { - return element.getTagValue(tagName); + String value = element.getTagValue(tagName); + if (!StringUtils.isEmpty(value)) { + return value; } //On va chercher sur l'element declarant return findTagValue(tagName, element.getDeclaringElement(), model); } public static boolean hasStereotype(ObjectModelElement element, - String stereotype) { - return element.hasStereotype(stereotype) || element.hasStereotype(stereotype.toLowerCase()); + String stereotype) { + return element.hasStereotype(stereotype) || + element.hasStereotype(stereotype.toLowerCase()); } /** @@ -541,21 +559,24 @@ * serialVersionUID. Exemple, returns "123456789L". * This id will change only if the type or the order of an attribute * changes. + * * @param clazz the class to use * @return the generated serialVersionUID */ public static String computeSerialVersionUID(ObjectModelClass clazz) { - String query = clazz.getQualifiedName() + "#"; - for (ObjectModelAttribute attr : clazz.getAttributes()) { - query += "-" + attr.getType(); - } - String result = query.hashCode() + "L"; - return result; + String query = clazz.getQualifiedName() + "#"; + for (ObjectModelAttribute attr : clazz.getAttributes()) { + query += "-" + attr.getType(); + } + String result = query.hashCode() + "L"; + return result; } /** - * Suppress packageName from a fullQualifiedName, even if it contains List, Map or other generics. + * Suppress packageName from a fullQualifiedName, even if it contains + * List, Map or other generics. + * * See JUnit test for matching expressions. * * @param str FullQualifiedName for an attribute type (for exemple) @@ -567,13 +588,15 @@ } /** - * Suppress packageName from a fullQualifiedName, even if it contains List, Map or other generics. + * Suppress packageName from a fullQualifiedName, even if it contains List, + * Map or other generics. + * * See JUnit test for matching expressions. * - * @param str FullQualifiedName for an attribute type (for exemple) + * @param str fullQualifiedName for an attribute type (for exemple) * @param removeGenericDefinition a flag to remove any generic definition at the beginning of the expression * @return the simple name associated to the str given - * @since 2.2.1 + * @since 2.3 */ public static String getSimpleName(String str, boolean removeGenericDefinition) { if (removeGenericDefinition) { @@ -606,7 +629,7 @@ * * @param str the string to parse * @return the string without any - * @since 2.2.1 + * @since 2.3 */ public static String removeGenericDefinition(String str) { @@ -646,7 +669,7 @@ /** * Parse a fully qualified generic java type, and extract each * imbricated types. - * + * * @param str string to parse * @return set of found types */ @@ -701,7 +724,7 @@ return buffer.toString(); } - /** + /** * Renvoie le nom de l'attribut de classe d'association en fonction des cas: * Si l'attribut porte le même nom que le type (extrémité inverse de * l'association), on lui ajoute le nom de la classe d'association @@ -721,4 +744,16 @@ return result; } + /** + * Check if the given attribute has the + * {@link EugeneStereoTypes#STEREOTYPE_INDEXED} stereotype. + * + * @param attribute attribute to test + * @return {@code true} if stereotype was found, {@code false otherwise} + * @see EugeneStereoTypes#STEREOTYPE_INDEXED + */ + public static boolean hasIndexedStereotype(ObjectModelAttribute attribute) { + return attribute.hasStereotype(EugeneStereoTypes.STEREOTYPE_INDEXED); + } + } // GeneratorUtil Added: trunk/eugene/src/main/java/org/nuiton/eugene/StereotypeDefinition.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/StereotypeDefinition.java (rev 0) +++ trunk/eugene/src/main/java/org/nuiton/eugene/StereotypeDefinition.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -0,0 +1,57 @@ +/* + * #%L + * EUGene :: EUGene + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.eugene; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * To define a stereotype. + * <p/> + * Place this annotation on the constant defining your stereotype. + * <p/> + * <br/> + * Example for stereotype named mystereotype which can be only put on a attribute : + * <pre> + * String STEREOTYPE_MYSTEREOTYPE = "mystereotype"; + * \@StereotypeDefinition(target = ObjectModelAttribute.class) + * </pre + * + * @author tchemit <chemit@codelutin.com> + * @see EugeneTagValues + * @since 2.3 + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface StereotypeDefinition { + /** + * Define the types of object model api which can use this tag value. + * + * @return the array of target object model element which can accept the tag value. + */ + Class<?>[] target(); +} Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/StereotypeDefinition.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/eugene/src/main/java/org/nuiton/eugene/TagValueDefinition.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/TagValueDefinition.java (rev 0) +++ trunk/eugene/src/main/java/org/nuiton/eugene/TagValueDefinition.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -0,0 +1,56 @@ +/* + * #%L + * EUGene :: EUGene + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.eugene; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * To define a tag value. + * <p/> + * Place this annotation on the constant defining your tag-value. + * <p/> + * Example for tag value named mytagvalut which can be only put on a attribute : + * <pre> + * String TAG_VALUE_MYTAGVALUE = "mytagvalue"; + * \@TagValueDefinition(target = ObjectModelAttribute.class) + * </pre + * + * @author tchemit <chemit@codelutin.com> + * @see EugeneTagValues + * @since 2.3 + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface TagValueDefinition { + /** + * Define the types of object model api which can use this tag value. + * + * @return the array of target object model element which can accept the tag value. + */ + Class<?>[] target(); +} Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/TagValueDefinition.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/eugene/src/main/java/org/nuiton/eugene/Template.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/Template.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/Template.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -37,7 +37,7 @@ import java.util.Properties; /** - * Generator. TODO javadoc + * Template. TODO javadoc * <p/> * Created: 5 août 2004 * @@ -140,17 +140,6 @@ } } - /** - * Set the properties configuration. - * - * @param p the configuration - * @deprecated since 2.0.2, prefer use the {@link TemplateConfiguration} api. - */ - @Deprecated - public void setProperties(Properties p) { - getConfiguration().getProperties().putAll(p); - } - protected List<String> getGeneratedPackages() { if (generatedPackages == null) { generatedPackages = new ArrayList<String>(); Modified: trunk/eugene/src/main/java/org/nuiton/eugene/Transformer.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/Transformer.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/Transformer.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -133,11 +133,6 @@ */ protected abstract O initOutputModel(); - @Override - public void setProperties(Properties outputProperties) { - this.outputProperties = outputProperties; - } - /** * Output properties for output generator. Initially set from build configuration. * Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -27,7 +27,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.eugene.EugeneStereoTypes; import org.nuiton.eugene.EugeneTagValues; import org.nuiton.eugene.models.object.ObjectModelAttribute; import org.nuiton.eugene.models.object.ObjectModelClass; @@ -85,14 +84,14 @@ log.debug("will generate " + output.getQualifiedName()); } - String i18nPrefix = JavaGeneratorUtil.getI18nPrefix(input, model); + String i18nPrefix = JavaGeneratorUtil.getI18nPrefixTagValue(input, model); if (!StringUtils.isEmpty(i18nPrefix)) { generateI18nBlock(input, output, i18nPrefix); } ObjectModelClass ouputImpl = generateImpl(input, output); - String noPCSTagValue = input.getTagValue(EugeneTagValues.TAG_NO_PCS); + String noPCSTagValue = JavaGeneratorUtil.getNoPCSTagValue(model, input); boolean usePCS = StringUtils.isEmpty(noPCSTagValue) || !"true".equals(noPCSTagValue.trim()); @@ -560,7 +559,7 @@ } protected boolean canGenerate(ObjectModelClass input) { - return input.hasStereotype(EugeneStereoTypes.STEREOTYPE_BEAN); + return JavaGeneratorUtil.hasBeanStereotype(input); } protected void createPropertyChangeSupport(ObjectModelClass output) { Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGeneratorUtil.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGeneratorUtil.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGeneratorUtil.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -24,6 +24,7 @@ */ package org.nuiton.eugene.java; +import org.nuiton.eugene.EugeneStereoTypes; import org.nuiton.eugene.EugeneTagValues; import org.nuiton.eugene.GeneratorUtil; import org.nuiton.eugene.models.object.ObjectModel; @@ -47,9 +48,10 @@ /** * dependency to add constants in interfaces via an enumeration. - * + * <p/> * The literals of enumeration will be the value, and constant names will * be generated by transformers. + * * @since 2.0.2 */ public static final String DEPENDENCIES_CONSTANTS = "constants"; @@ -58,18 +60,18 @@ * Duplicates in the {@code target} classifier the given {@code operations} * using a {@code transformer} to modify model. * - * @param transformer the transformer to use - * @param operations operations to duplicate - * @param target where to duplicate operations - * @param useVisibility flag to use operation visibilty to compute his - * modifiers - * @param extraModifiers scopes to apply to all operations + * @param transformer the transformer to use + * @param operations operations to duplicate + * @param target where to duplicate operations + * @param useVisibility flag to use operation visibilty to compute his + * modifiers + * @param extraModifiers scopes to apply to all operations */ public static void cloneOperations(ObjectModelTransformerToJava transformer, - Iterable<ObjectModelOperation> operations, - ObjectModelClassifier target, - boolean useVisibility, - ObjectModelModifier... extraModifiers) { + Iterable<ObjectModelOperation> operations, + ObjectModelClassifier target, + boolean useVisibility, + ObjectModelModifier... extraModifiers) { for (ObjectModelOperation op : operations) { ObjectModelOperation resultOp; @@ -113,16 +115,63 @@ } /** + * Check if the given classifier has the + * {@link EugeneStereoTypes#STEREOTYPE_BEAN} stereotype. + * + * @param classifier classifier to test + * @return {@code true} if stereotype was found, {@code false otherwise} + * @see EugeneStereoTypes#STEREOTYPE_BEAN + */ + public static boolean hasBeanStereotype(ObjectModelClassifier classifier) { + return classifier.hasStereotype(EugeneStereoTypes.STEREOTYPE_BEAN); + } + + /** * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur * le model. * * @param element l'élément à tester * @param model le modele utilisé * @return le prefix i18n ou <code>null</code> si non spécifié - * @since 2.2.1 + * @since 2.3 */ - public static String getI18nPrefix(ObjectModelElement element, - ObjectModel model) { + public static String getI18nPrefixTagValue(ObjectModelElement element, + ObjectModel model) { return findTagValue(EugeneTagValues.TAG_I18N_PREFIX, element, model); } + + /** + * Obtain the value of the {@link EugeneTagValues#TAG_NO_PCS} + * tag value on the given model or classifier. + * <p/> + * It will first look on the model, and then in the given classifier. + * + * @param model model to seek + * @param classifier classifier to seek + * @return the none empty value of the found tag value or {@code null} if not found nor empty. + * @see EugeneTagValues#TAG_NO_PCS + * @since 2.3 + */ + public static String getNoPCSTagValue(ObjectModel model, ObjectModelClassifier classifier) { + String value = findTagValue(EugeneTagValues.TAG_NO_PCS, classifier, model); + return value; + } + + /** + * Obtain the value of the {@link EugeneTagValues#TAG_CONSTANT_PREFIX} + * tag value on the given model or classifier. + * <p/> + * It will first look on the model, and then in the given classifier. + * + * @param model model to seek + * @param classifier classifier to seek + * @return the none empty value of the found tag value or {@code null} if not found nor empty. + * @see EugeneTagValues#TAG_CONSTANT_PREFIX + * @since 2.3 + */ + public static String getConstantPrefixTagValue(ObjectModel model, + ObjectModelClassifier classifier) { + String value = findTagValue(EugeneTagValues.TAG_CONSTANT_PREFIX, classifier, model); + return value; + } } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -194,10 +194,9 @@ String defaultPrefix) { // look if there is a constant_prefix tag value - String prefix = JavaGeneratorUtil.findTagValue( - EugeneTagValues.TAG_CONSTANT_PREFIX, - input, - getModel() + String prefix = JavaGeneratorUtil.getConstantPrefixTagValue( + getModel(), + input ); if (StringUtils.isEmpty(prefix)) { @@ -375,7 +374,7 @@ * * @param attribute the attribute on which the navigable flag will be setted * @param navigable the navigable flag to set - * @since 2.2.1 + * @since 2.3 */ public void setNavigable(ObjectModelAttribute attribute, boolean navigable) { builder.setNavigable(attribute, navigable); @@ -538,7 +537,7 @@ * * @param source the source element * @param destination the destination element - * @since 2.2.1 + * @since 2.3 */ protected void cloneTagValues(ObjectModelElement source, ObjectModelElement destination) { @@ -552,7 +551,7 @@ * * @param source * @param destination - * @since 2.2.1 + * @since 2.3 */ protected void cloneStereotypes(ObjectModelClassifier source, ObjectModelClassifier destination) { @@ -576,7 +575,7 @@ * @param destination where to clone the given source one * @param copyDocumentation flag to add documentation if some found in model * @since 2.1.2 - * @deprecated since 2.2.1, prefer use the {@link #cloneClass(ObjectModelClass, boolean)} method + * @deprecated since 2.3, prefer use the {@link #cloneClass(ObjectModelClass, boolean)} method */ @Deprecated protected void copyClassifier(ObjectModelClassifier source, @@ -598,7 +597,7 @@ * @param source the classifier to clone from the source model * @param destination where to clone the given source one * @param copyDocumentation flag to add documentation if some found in model - * @since 2.2.1 + * @since 2.3 */ protected void cloneClassifier(ObjectModelClassifier source, ObjectModelClassifier destination, Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelAttribute.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelAttribute.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelAttribute.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -124,11 +124,7 @@ */ boolean isFinal(); /** - * @return {@code true} if this attribute is navigable + * @return {@code true} if this attribute is navigable. */ boolean isNavigable(); - /** - * @return {@code true} if this attribute is isIndexed - */ - boolean isIndexed(); } //ObjectModelAttribute 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-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelBuilder.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -692,7 +692,7 @@ * * @param attribute where the navigable flag will be setted * @param navigable navigable flag value to set - * @since 2.2.1 + * @since 2.3 */ public void setNavigable(ObjectModelAttribute attribute, boolean navigable) { 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-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelElement.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -120,17 +120,6 @@ */ 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 Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelParameter.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelParameter.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelParameter.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -26,18 +26,18 @@ package org.nuiton.eugene.models.object; /** -* Abstraction for the parameter node of object model trees. -* This object presents all information concerning the given parameter. -* -* Created: 14 janv. 2004 -* -* @author Cédric Pineau <pineau@codelutin.com> -* Copyright Code Lutin -* @version $Revision$ -* -* Last update : $Date$ -* by : $Author$ -*/ + * Abstraction for the parameter node of object model trees. + * This object presents all information concerning the given parameter. + * <p/> + * Created: 14 janv. 2004 + * + * @author Cédric Pineau <pineau@codelutin.com> + * Copyright Code Lutin + * @version $Revision$ + * <p/> + * Last update : $Date$ + * by : $Author$ + */ public interface ObjectModelParameter extends ObjectModelElement { /** Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -101,7 +101,7 @@ * Pattern to define tag values authorized at model level in the model * properties file. * - * @since 2.2.1 + * @since 2.3 */ protected Pattern modelTagValuePattern = Pattern.compile( "^model\\.(?:(tagvalue|tagValue)?)\\.((?:.+))$"); Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelAttributeImpl.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelAttributeImpl.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelAttributeImpl.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -26,6 +26,7 @@ package org.nuiton.eugene.models.object.xml; import org.nuiton.eugene.GeneratorUtil; +import org.nuiton.eugene.java.JavaGeneratorUtil; import org.nuiton.eugene.models.object.ObjectModelAttribute; import org.nuiton.eugene.models.object.ObjectModelClass; import org.nuiton.eugene.models.object.ObjectModelClassifier; @@ -51,7 +52,7 @@ protected String associationClassName; protected boolean isStatic; protected boolean isFinal; - protected boolean isNavigable = true; + protected boolean navigable = true; public ObjectModelAttributeImpl() { } @@ -88,8 +89,8 @@ this.isStatic = isStatic; } - public void setNavigable(boolean isNavigable) { - this.isNavigable = isNavigable; + public void setNavigable(boolean navigable) { + this.navigable = navigable; } /** @@ -183,11 +184,6 @@ return name; } - /* - * (non-Javadoc) - * - * @see org.nuiton.eugene.models.object.ObjectModelAttribute#getReverseMaxMultiplicity() - */ @Override public int getReverseMaxMultiplicity() { return reverseMaxMultiplicity; @@ -237,28 +233,17 @@ return isFinal; } - /* - * @see org.nuiton.eugene.models.object.ObjectModelAttribute#isNavigable() - */ @Override public boolean isNavigable() { - return isNavigable; + return navigable; } - /* - * @see org.nuiton.eugene.models.object.ObjectModelAttribute#isOrdered() + /** + * FIXME tchemit 2010-11-28 Why the ordered flag may be indexed ? This is two distinct concepts ? */ @Override public boolean isOrdered() { - return isIndexed() || super.isOrdered(); + return JavaGeneratorUtil.hasIndexedStereotype(this) || super.isOrdered(); } - /* - * @see org.nuiton.eugene.models.object.ObjectModelAttribute#isIndexed() - */ - @Deprecated - @Override - public boolean isIndexed() { - return hasStereotype("indexed"); - } } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelParameterImpl.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelParameterImpl.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelParameterImpl.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -43,10 +43,17 @@ protected String type; protected int minMultiplicity = 1; protected int maxMultiplicity = 1; - protected String ordering = "unspecified"; - protected boolean isUnique = true; +// protected String ordering = "unspecified"; + + /** + * FIXME tchemit 2010-11-28 Why the default value is true ? + */ + protected boolean unique = true; + protected boolean ordered; protected String defaultValue; + public static final String PROPERTY_ORDERED = "ordered"; + public ObjectModelParameterImpl() { } @@ -62,12 +69,17 @@ this.maxMultiplicity = maxMultiplicity; } + /** + * + * @param ordering + */ public void setOrdering(String ordering) { - this.ordering = ordering; + setOrdered(PROPERTY_ORDERED.equals(ordering)); +// this.ordering = ordering; } - public void setUnique(boolean isUnique) { - this.isUnique = isUnique; + public void setUnique(boolean unique) { + this.unique = unique; } public void setDefaultValue(String defaultValue) { @@ -96,12 +108,17 @@ @Override public boolean isOrdered() { - return "ordered".equals(ordering); + return ordered; +// return "ordered".equals(ordering); } + public void setOrdered(boolean ordered) { + this.ordered = ordered; + } + @Override public boolean isUnique() { - return isUnique; + return unique; } @Override Modified: trunk/eugene/src/test/java/org/nuiton/eugene/TestHelper.java =================================================================== --- trunk/eugene/src/test/java/org/nuiton/eugene/TestHelper.java 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/eugene/src/test/java/org/nuiton/eugene/TestHelper.java 2010-11-28 20:13:58 UTC (rev 1014) @@ -34,7 +34,7 @@ * Helper for all eugene tests. * * @author tchemit <chemit@codelutin.com> - * @since 2.2.1 + * @since 2.3 */ @Ignore // this is not a test :) Modified: trunk/maven-eugene-plugin/pom.xml =================================================================== --- trunk/maven-eugene-plugin/pom.xml 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/maven-eugene-plugin/pom.xml 2010-11-28 20:13:58 UTC (rev 1014) @@ -36,7 +36,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>eugene</artifactId> - <version>2.2.1-SNAPSHOT</version> + <version>2.3-SNAPSHOT</version> </parent> <groupId>org.nuiton.eugene</groupId> @@ -219,6 +219,7 @@ </property> </activation> <build> + <defaultGoal>integration-test</defaultGoal> <plugins> <plugin> <artifactId>maven-invoker-plugin</artifactId> @@ -226,12 +227,13 @@ <pomIncludes> <pomInclude>evol-879/zargo/pom.xml</pomInclude> <pomInclude>evol-879/xmi/pom.xml</pomInclude> - <pomInclude>evol-879/model/pom.xml</pomInclude> <pomInclude>copyVersionFiles/anomalie163/pom.xml</pomInclude> <pomInclude>smart-generate/only-zargo/pom.xml</pomInclude> <pomInclude>smart-generate/only-zargo-xmi/pom.xml</pomInclude> <pomInclude>smart-generate/all/pom.xml</pomInclude> <pomInclude>smart-generate/generators/pom.xml</pomInclude> + <!-- this test used topia and must be move in topia not here --> + <!--<pomInclude>evol-879/model/pom.xml</pomInclude>--> </pomIncludes> <postBuildHookScript>verify</postBuildHookScript> <localRepositoryPath>${basedir}/target/local-repo Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-11-28 12:33:19 UTC (rev 1013) +++ trunk/pom.xml 2010-11-28 20:13:58 UTC (rev 1014) @@ -37,7 +37,7 @@ </parent> <artifactId>eugene</artifactId> - <version>2.2.1-SNAPSHOT</version> + <version>2.3-SNAPSHOT</version> <modules> <module>eugene</module>
participants (1)
-
tchemit@users.nuiton.org