Author: tchemit Date: 2010-11-27 17:02:36 +0100 (Sat, 27 Nov 2010) New Revision: 536 Url: http://nuiton.org/repositories/revision/wikitty/536 Log: - use the new MetaTransformer api - make works the full eugene chain (transformer then templates, no ore use of the previousTransformer in templates only transformer in the metaTransformer) - improve with my two cents some dirty codes in generator api (but a lot still has to be done, the generator module is not very clean (I know tastes and colors... about dirty pigs!) Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyAbstractGenerator.java trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyContractGenerator.java trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyDTOGenerator.java trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyHelperGenerator.java trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyImplementationGenerator.java trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyMetaTransformer.java trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyPurifierTransformer.java trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyTransformerUtil.java Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyAbstractGenerator.java =================================================================== --- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyAbstractGenerator.java 2010-11-27 15:57:22 UTC (rev 535) +++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyAbstractGenerator.java 2010-11-27 16:02:36 UTC (rev 536) @@ -37,10 +37,15 @@ import org.nuiton.eugene.models.object.ObjectModelOperation; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -151,13 +156,13 @@ addImport(clazz, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNode"); addImport(clazz, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeAbstract"); addImport(clazz, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeImpl"); - addImport(clazz, java.util.List.class); - addImport(clazz, java.util.ArrayList.class); - addImport(clazz, java.util.Collection.class); - addImport(clazz, java.util.Collections.class); - addImport(clazz, java.util.Set.class); - addImport(clazz, java.util.Date.class); - addImport(clazz, java.util.LinkedHashSet.class); + addImport(clazz, List.class); + addImport(clazz, ArrayList.class); + addImport(clazz, Collection.class); + addImport(clazz, Collections.class); + addImport(clazz, Set.class); + addImport(clazz, Date.class); + addImport(clazz, LinkedHashSet.class); } protected void addSerialVersionUID(ObjectModelClass clazz) { @@ -419,6 +424,8 @@ * we B need to import CHelper and A need to import BHelper. But, since A * has C attributes too, it needs CHelper too. So when we will process B, * we will save needed imports, A will get them thus import CHelper. + * @param businessEntity + * @param abstractClass */ protected void addInheritedOperations(ObjectModelClass businessEntity, ObjectModelClass abstractClass) { @@ -491,6 +498,8 @@ * * will try to replace first {...} by name field value for extension Person. * if this information is not available, will do unknow. + * @param businessEntity + * @param abstractClass */ protected void addToString(ObjectModelClass businessEntity, ObjectModelClass abstractClass) { Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyContractGenerator.java =================================================================== --- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyContractGenerator.java 2010-11-27 15:57:22 UTC (rev 535) +++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyContractGenerator.java 2010-11-27 16:02:36 UTC (rev 536) @@ -24,16 +24,20 @@ */ package org.nuiton.wikitty.generator; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.eugene.Transformer; import org.nuiton.eugene.java.ObjectModelTransformerToJava; import org.nuiton.eugene.models.object.ObjectModel; import org.nuiton.eugene.models.object.ObjectModelAttribute; @@ -53,15 +57,16 @@ private static final Log log = LogFactory.getLog(WikittyContractGenerator.class); - @Override - protected Transformer<ObjectModel, ObjectModel> initPreviousTransformer() { - return new WikittyPurifierTransformer(); - } +// @Override +// protected Transformer<ObjectModel, ObjectModel> initPreviousTransformer() { +// return new WikittyPurifierTransformer(); +// } - /** will permet to get the result of a processed class + /** + * Will permet to get the result of a processed class * it is useful for dealing with inheritence : when an extension depend * of another. In this case the child can find the processed class of the parent - * and then look into it to find methods and data to copy + * and then look into it to find methods and data to copy. */ protected Map<ObjectModelClass, ObjectModelInterface> processedClasses = new HashMap<ObjectModelClass, ObjectModelInterface>(); @@ -86,7 +91,12 @@ processedEntities.clear(); } - /** contains code commons to entities and meta-extensions */ + /** + * Contains code commons to entities and meta-extensions. + * + * @param businessEntity + * @return + */ protected ObjectModelInterface prepareOutputClass(ObjectModelClass businessEntity) { ObjectModelInterface contract = processedClasses.get(businessEntity); @@ -112,13 +122,13 @@ addImport(contract, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNode"); addImport(contract, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeAbstract"); addImport(contract, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeImpl"); - addImport(contract, java.util.List.class); - addImport(contract, java.util.ArrayList.class); - addImport(contract, java.util.Collection.class); - addImport(contract, java.util.Collections.class); - addImport(contract, java.util.Set.class); - addImport(contract, java.util.Date.class); - addImport(contract, java.util.LinkedHashSet.class); + addImport(contract, List.class); + addImport(contract, ArrayList.class); + addImport(contract, Collection.class); + addImport(contract, Collections.class); + addImport(contract, Set.class); + addImport(contract, Date.class); + addImport(contract, LinkedHashSet.class); String documentation = businessEntity.getDocumentation(); if (businessEntity.hasTagValue(WikittyTransformerUtil.TAG_DOCUMENTATION)) { @@ -268,7 +278,11 @@ processedEntities.add(businessEntity); } - /** add stuff if input model element is stereotyped as "meta" */ + /** + * Add stuff if input model element is stereotyped as "meta". + * + * @param metaExtension + */ protected void processMetaExtension(ObjectModelClass metaExtension) { // nothing to do } Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyDTOGenerator.java =================================================================== --- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyDTOGenerator.java 2010-11-27 15:57:22 UTC (rev 535) +++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyDTOGenerator.java 2010-11-27 16:02:36 UTC (rev 536) @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Random; @@ -78,10 +79,10 @@ */ protected Map<String, String> attributeToGetterName = new HashMap<String, String>(); - @Override - protected Transformer<ObjectModel, ObjectModel> initPreviousTransformer() { - return new WikittyPurifierTransformer(); - } +// @Override +// protected Transformer<ObjectModel, ObjectModel> initPreviousTransformer() { +// return new WikittyPurifierTransformer(); +// } protected List<ObjectModelClass> entitiesWithInheritedOperations = new ArrayList<ObjectModelClass>(); @@ -98,6 +99,7 @@ for (ObjectModelClass clazz : model.getClasses()) { if (WikittyTransformerUtil.isBusinessEntity(clazz) || WikittyTransformerUtil.isMetaExtension(clazz)) { + log.info("will treate class "+clazz.getQualifiedName()); modelBoth.add(clazz); } } @@ -191,14 +193,14 @@ String attributeTypeInSet = WikittyTransformerUtil.generateResultType(attribute, true); String attributeTypeInSetImpl = null; String collectionType = WikittyTransformerUtil.getCollectionTypeName(attribute); - if (collectionType.equals("Set")){ + if (Set.class.getSimpleName().equals(collectionType)){ addImport(abstractClass, Set.class); - addImport(abstractClass, "java.util.HashSet"); + addImport(abstractClass, HashSet.class); attributeTypeInSetImpl = "HashSet<String>"; } - if (collectionType.equals("List")){ + if (List.class.getSimpleName().equals(collectionType)){ addImport(abstractClass, List.class); - addImport(abstractClass, "java.util.ArrayList"); + addImport(abstractClass, ArrayList.class); attributeTypeInSetImpl = "ArrayList<String>"; } @@ -318,6 +320,8 @@ * we B need to import CHelper and A need to import BHelper. But, since A * has C attributes too, it needs CHelper too. So when we will process B, * we will save needed imports, A will get them thus import CHelper. + * @param businessEntity + * @param abstractClass */ protected void addInheritedOperations(ObjectModelClass businessEntity, ObjectModelClass abstractClass) { @@ -346,6 +350,8 @@ * <p/> * will try to replace first {...} by name field value for extension Person. * if this information is not available, will do unknow. + * @param businessEntity + * @param abstractClass */ protected void addToString(ObjectModelClass businessEntity, ObjectModelClass abstractClass) { @@ -408,6 +414,8 @@ /** * Method to get the generated class name + * @param clazz + * @return */ protected String businessEntityToDTOName(ObjectModelClass clazz) { return clazz.getName() + "DTO"; @@ -609,10 +617,10 @@ String attributeName = attribute.getName(); String attributeTypeInSetImpl = null; String collectionType = WikittyTransformerUtil.getCollectionTypeName(attribute); - if (collectionType.equals("Set")) { + if (Set.class.getSimpleName().equals(collectionType)) { attributeTypeInSetImpl = "HashSet<String>"; } - if (collectionType.equals("List")) { + if (List.class.getSimpleName().equals(collectionType)) { attributeTypeInSetImpl = "ArrayList<String>"; } Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyHelperGenerator.java =================================================================== --- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyHelperGenerator.java 2010-11-27 15:57:22 UTC (rev 535) +++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyHelperGenerator.java 2010-11-27 16:02:36 UTC (rev 536) @@ -31,6 +31,14 @@ import org.nuiton.eugene.models.object.ObjectModelModifier; import org.nuiton.eugene.models.object.ObjectModelOperation; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + /*{generator option: writeString = }*/ /*{generator option: parentheses = false}*/ /*{generator option: writeString = +}*/ @@ -45,7 +53,7 @@ @Override public void transformFromClass(ObjectModelClass clazz) { - if (WikittyTransformerUtil.isBusinessEntity(clazz) ||(WikittyTransformerUtil.isMetaExtension(clazz))) { + if (WikittyTransformerUtil.isBusinessEntity(clazz) || WikittyTransformerUtil.isMetaExtension(clazz)) { ObjectModelClass helper = createClass(WikittyTransformerUtil.businessEntityToHelperName(clazz), clazz.getPackageName()); @@ -62,13 +70,13 @@ addImport(helper, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNode"); addImport(helper, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeAbstract"); addImport(helper, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeImpl"); - addImport(helper, java.util.List.class); - addImport(helper, java.util.ArrayList.class); - addImport(helper, java.util.Collection.class); - addImport(helper, java.util.Collections.class); - addImport(helper, java.util.Set.class); - addImport(helper, java.util.Date.class); - addImport(helper, java.util.LinkedHashSet.class); + addImport(helper, List.class); + addImport(helper, ArrayList.class); + addImport(helper, Collection.class); + addImport(helper, Collections.class); + addImport(helper, Set.class); + addImport(helper, Date.class); + addImport(helper, LinkedHashSet.class); // making constructor for helper class (empty and private) ObjectModelOperation constructor = addConstructor(helper, ObjectModelModifier.PRIVATE); @@ -86,7 +94,12 @@ } } - /** add operation if input model element has stereotype "entity" */ + /** + * Add operation if input model element has stereotype "entity". + * + * @param entity + * @param helper + * */ protected void createOperationsForBusinessEntity(ObjectModelClass entity, ObjectModelClass helper) { @@ -233,10 +246,6 @@ }*/; setOperationBody(equals, equalsBody); - - - - // finally, adding isExtension, hasExtension and addExtension ObjectModelOperation isExtension = addOperation(helper, "isExtension", "boolean", ObjectModelModifier.STATIC); @@ -268,7 +277,12 @@ }*/); } - /** add needed operations if input model element has stereotype "meta" */ + /** + * Add needed operations if input model element has stereotype "meta". + * + * @param metaExtension + * @param helper + */ protected void createOperationForMetaExtension(ObjectModelClass metaExtension, ObjectModelClass helper) { Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyImplementationGenerator.java =================================================================== --- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyImplementationGenerator.java 2010-11-27 15:57:22 UTC (rev 535) +++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyImplementationGenerator.java 2010-11-27 16:02:36 UTC (rev 536) @@ -24,9 +24,16 @@ */ package org.nuiton.wikitty.generator; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Set; import org.nuiton.eugene.java.ObjectModelTransformerToJava; import org.nuiton.eugene.models.object.ObjectModelClass; @@ -82,13 +89,13 @@ addImport(implementation, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNode"); addImport(implementation, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeAbstract"); addImport(implementation, WikittyTransformerUtil.ENTITY_PACKAGE + ".WikittyTreeNodeImpl"); - addImport(implementation, java.util.List.class); - addImport(implementation, java.util.ArrayList.class); - addImport(implementation, java.util.Collection.class); - addImport(implementation, java.util.Collections.class); - addImport(implementation, java.util.Set.class); - addImport(implementation, java.util.Date.class); - addImport(implementation, java.util.LinkedHashSet.class); + addImport(implementation, List.class); + addImport(implementation, ArrayList.class); + addImport(implementation, Collection.class); + addImport(implementation, Collections.class); + addImport(implementation, Set.class); + addImport(implementation, Date.class); + addImport(implementation, LinkedHashSet.class); setSuperClass(implementation, WikittyTransformerUtil.businessEntityToAbstractName(clazz)); Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyMetaTransformer.java =================================================================== --- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyMetaTransformer.java 2010-11-27 15:57:22 UTC (rev 535) +++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyMetaTransformer.java 2010-11-27 16:02:36 UTC (rev 536) @@ -31,22 +31,20 @@ import org.nuiton.eugene.models.object.ObjectModelClass; /** - * * Wikitty generation steps : * <ol> - * <li>transform user model to wikitty intermediate model</li> - * <li>generate from wikitty intermediate model : - * <ul> - * <li>a contract;</li> - * <li>an abstract class;</li> - * <li>an implementation;</li> - * <li>a helper</li> - * </ul> - * </li> + * <li>transform user model to wikitty intermediate model</li> + * <li>generate from wikitty intermediate model : + * <ul> + * <li>a contract;</li> + * <li>an abstract class;</li> + * <li>an implementation;</li> + * <li>a helper</li> + * </ul> + * </li> * </ol> - * + * * @author bleny - * * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.wikitty.generator.WikittyMetaGenerator" */ @@ -56,40 +54,49 @@ /*{generator option: writeString = +}*/ public class WikittyMetaTransformer extends AbstractMetaTransformer<ObjectModel> { - + private static final Log log = LogFactory.getLog(WikittyMetaTransformer.class); public WikittyMetaTransformer() { - - super(WikittyContractGenerator.class, - WikittyAbstractGenerator.class, - WikittyImplementationGenerator.class, - WikittyHelperGenerator.class - ); - + +// super(WikittyContractGenerator.class, +// WikittyAbstractGenerator.class, +// WikittyImplementationGenerator.class, +// WikittyHelperGenerator.class +// ); + + setTransformerTypes(WikittyPurifierTransformer.class); + setTemplateTypes( + WikittyContractGenerator.class, + WikittyAbstractGenerator.class, + WikittyImplementationGenerator.class, + WikittyHelperGenerator.class + ); + } - - /** */ + @Override protected boolean validateModel(ObjectModel model) { if (model.getClasses().isEmpty()) { - log.warn("model doesn't contains any class"); + if (log.isWarnEnabled()) { + log.warn("model does not contain any class to generate."); + } } for (ObjectModelClass clazz : model.getClasses()) { - + // warn user if deprecated stereotype is used - if (clazz.getStereotypes().contains(WikittyTransformerUtil.BUSINESS_ENTITY_STEREOTYPE_OLD_NAME)) { + if (clazz.getStereotypes().contains(WikittyTransformerUtil.BUSINESS_ENTITY_STEREOTYPE_OLD_NAME)) { log.warn(clazz.getQualifiedName() + " uses deprecated \"" + - WikittyTransformerUtil.BUSINESS_ENTITY_STEREOTYPE_OLD_NAME - + "\" stereotype. use \"" + - WikittyTransformerUtil.BUSINESS_ENTITY_STEREOTYPE_NAME + - "\" instead"); + WikittyTransformerUtil.BUSINESS_ENTITY_STEREOTYPE_OLD_NAME + + "\" stereotype. use \"" + + WikittyTransformerUtil.BUSINESS_ENTITY_STEREOTYPE_NAME + + "\" instead"); } if (!clazz.hasTagValue(WikittyTransformerUtil.TAG_VERSION)) { - log.warn(clazz.getQualifiedName() + " misses a \"" + + log.warn(clazz.getQualifiedName() + " misses a \"" + WikittyTransformerUtil.TAG_VERSION + "\" tagValue"); } } Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyPurifierTransformer.java =================================================================== --- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyPurifierTransformer.java 2010-11-27 15:57:22 UTC (rev 535) +++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyPurifierTransformer.java 2010-11-27 16:02:36 UTC (rev 536) @@ -45,7 +45,8 @@ */ public class WikittyPurifierTransformer extends ObjectModelTransformerToJava { - private static final Log log = LogFactory.getLog(WikittyPurifierTransformer.class); + private static final Log log = + LogFactory.getLog(WikittyPurifierTransformer.class); /** for a given class, store all the names used by this class and subClasses */ Map<ObjectModelClass, List<String>> namesUsedByClass = new HashMap<ObjectModelClass, List<String>>(); @@ -62,89 +63,100 @@ * to consider it as a new name. To choose a new name, we look for * an alternative name provided by the user through a tagValue on this * attribute. If no alternative provided, we try to generate an alternative - * name by adding "From<className>" to the attribute name. + * name by adding "From<className>" to the attribute name. + * + * @param clazz the class to process */ protected void processClass(ObjectModelClass clazz) { + if (processedClasses.contains(clazz)) { + // clazz has already been processed, do nothing - } else { - // all attributes names that will be used by clazz - List<String> allUsedNames = new ArrayList<String>(); + return; + } - - // first, we have to get all names used by the super classes and - // its superclasses. So they must have been processed before - // current class. Thus, we recursively call processClass on - // superClass. - - // process superclass first - for (ObjectModelClass superClasses : clazz.getSuperclasses()) { - if (WikittyTransformerUtil.isBusinessEntity(superClasses)) { - if (!processedClasses.contains(superClasses)) { - processClass(superClasses); - allUsedNames.addAll(namesUsedByClass.get(superClasses)); - } + if (isVerbose()) { + log.info("will purify " + clazz.getQualifiedName()); + } + + List<String> allUsedNames = new ArrayList<String>(); + + + // first, we have to get all names used by the super classes and + // its superclasses. So they must have been processed before + // current class. Thus, we recursively call processClass on + // superClass. + + // process superclass first + for (ObjectModelClass superClasses : clazz.getSuperclasses()) { + if (WikittyTransformerUtil.isBusinessEntity(superClasses)) { + if (!processedClasses.contains(superClasses)) { + processClass(superClasses); + allUsedNames.addAll(namesUsedByClass.get(superClasses)); } } + } - // now, allUsedNames contains all names used by superClass, we - // have to check current class attributes names for conflict. - // allUsedNames contains name that we - // can't use without generating a conflict - for (ObjectModelAttribute attribute : clazz.getAttributes()) { - - // will be null as long as a non-conflicting name is found - String attributeName = null; + // now, allUsedNames contains all names used by superClass, we + // have to check current class attributes names for conflict. + // allUsedNames contains name that we + // can't use without generating a conflict + for (ObjectModelAttribute attribute : clazz.getAttributes()) { - if (attribute.hasTagValue(WikittyTransformerUtil.TAG_ALTERNATIVE_NAME)) { - attributeName = attribute.getTagValue(WikittyTransformerUtil.TAG_ALTERNATIVE_NAME); - if (allUsedNames.contains(attributeName)) { - // using alternative name lead to a conflict - attribute.getTagValues().remove(WikittyTransformerUtil.TAG_ALTERNATIVE_NAME); - attributeName = null; - } + // will be null as long as a non-conflicting name is found + String attributeName = null; + + if (attribute.hasTagValue(WikittyTransformerUtil.TAG_ALTERNATIVE_NAME)) { + attributeName = attribute.getTagValue(WikittyTransformerUtil.TAG_ALTERNATIVE_NAME); + if (allUsedNames.contains(attributeName)) { + // using alternative name lead to a conflict + attribute.getTagValues().remove(WikittyTransformerUtil.TAG_ALTERNATIVE_NAME); + attributeName = null; } + } - if (attributeName == null) { - attributeName = attribute.getName(); - if (allUsedNames.contains(attributeName)) { - // using alternative name lead to a conflict - attributeName = null; - } + if (attributeName == null) { + attributeName = attribute.getName(); + if (allUsedNames.contains(attributeName)) { + // using alternative name lead to a conflict + attributeName = null; } + } - if (attributeName == null) { - attributeName = attribute.getName() + "From" + clazz.getName(); - if (allUsedNames.contains(attributeName)) { - // using alternative name lead to a conflict - attributeName = null; - } else { - addTagValue(attribute, WikittyTransformerUtil.TAG_ALTERNATIVE_NAME, attributeName); - } - } - - // finally - if (attributeName == null) { - // still no alternative :-( - log.error("no way to resolve conflict with attribute" + - attribute.getName() + " from class " + clazz - + ". You should add or change a tagValue \"" + - WikittyTransformerUtil.TAG_ALTERNATIVE_NAME + - "\" on this attribute"); + if (attributeName == null) { + attributeName = attribute.getName() + "From" + clazz.getName(); + if (allUsedNames.contains(attributeName)) { + // using alternative name lead to a conflict + attributeName = null; } else { - allUsedNames.add(attributeName); + addTagValue(attribute, WikittyTransformerUtil.TAG_ALTERNATIVE_NAME, attributeName); } } - // saving all names we used in current class will permit to sub classes - // to know what names it must not use - namesUsedByClass.put(clazz, allUsedNames); + // finally + if (attributeName == null) { + // still no alternative :-( + log.error("no way to resolve conflict with attribute" + + attribute.getName() + " from class " + clazz + + ". You should add or change a tagValue \"" + + WikittyTransformerUtil.TAG_ALTERNATIVE_NAME + + "\" on this attribute"); + } else { + allUsedNames.add(attributeName); + } } + + // saving all names we used in current class will permit to sub classes + // to know what names it must not use + namesUsedByClass.put(clazz, allUsedNames); } @Override public void transformFromModel(ObjectModel model) { for (ObjectModelClass clazz : model.getClasses()) { + if (isVerbose()) { + log.info("Will clone " + clazz.getQualifiedName()); + } ObjectModelClass clone = cloneClass(clazz, true); if (WikittyTransformerUtil.isBusinessEntity(clazz)) { processClass(clone); Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyTransformerUtil.java =================================================================== --- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyTransformerUtil.java 2010-11-27 15:57:22 UTC (rev 535) +++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyTransformerUtil.java 2010-11-27 16:02:36 UTC (rev 536) @@ -24,7 +24,9 @@ */ package org.nuiton.wikitty.generator; +import java.util.Date; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.apache.commons.lang.StringUtils; @@ -64,7 +66,9 @@ /** given a class called Client will return "EXT_CLIENT" * should be used as a variable name to store the extension name + * @param clazz * @param withClassNamePrefix add class name as prefix (will return "Client.EXT_CLIENT") + * @return */ protected static String classToExtensionVariableName(ObjectModelClass clazz, boolean withClassNamePrefix) { @@ -77,7 +81,9 @@ } /** given the field name of the class Client, will return "FIELD_CLIENT_NAME" + * @param attribute * @param withClassNamePrefix add class name as prefix (ie "Client.FIELD_CLIENT_NAME") + * @return */ protected static String attributeToFielVariableName(ObjectModelAttribute attribute, boolean withClassNamePrefix) { @@ -93,7 +99,10 @@ return fieldVariableName; } - /** given "my.java.package.MyClass" or "MyClass" return "MyClass" */ + /** given "my.java.package.MyClass" or "MyClass" return "MyClass" + * @param fqn + * @return + */ protected static String FQNtoSimpleName(String fqn) { // XXX should use GeneratorUtil#getSimpleName(String) int lastDotIndex = fqn.lastIndexOf("."); @@ -119,7 +128,7 @@ * wikitty interface provide getFieldAsString, getFieldAsDate etc. methods * this method returns the good name of the method to call depending the * type given as parameter - * @param typeName a name of a business entity or "String", "Integer" etc. + * @param attribute a name of a business entity or "String", "Integer" etc. * @return the name of a method "getFieldAsInt" for example */ protected static String generateGetFieldAsCall(ObjectModelAttribute attribute) { @@ -137,7 +146,10 @@ return "getFieldAs" + asWhat; } - /** for a given type of attribute, the getter returned type must be... */ + /** for a given type of attribute, the getter returned type must be... + * @param attribute + * @param considerMultiplicity + * @return*/ protected static String generateResultType(ObjectModelAttribute attribute, boolean considerMultiplicity) { String simpleTypeName = FQNtoSimpleName(attribute.getType()); @@ -155,9 +167,9 @@ protected static String getCollectionTypeName(ObjectModelAttribute attribute) { String result; if (attribute.isUnique()) { - result = "Set"; + result = Set.class.getSimpleName(); } else { - result = "List"; + result = List.class.getSimpleName(); } return result; } @@ -183,26 +195,28 @@ private static Set<String> commonNumerics; static { commonNumerics = new HashSet<String>(); - commonNumerics.add("byte"); - commonNumerics.add("Byte"); - commonNumerics.add("short"); - commonNumerics.add("Short"); - commonNumerics.add("int"); - commonNumerics.add("Integer"); - commonNumerics.add("long"); - commonNumerics.add("Long"); - commonNumerics.add("float"); - commonNumerics.add("Float"); - commonNumerics.add("double"); - commonNumerics.add("Double"); + commonNumerics.add(byte.class.getSimpleName()); + commonNumerics.add(Byte.class.getSimpleName()); + commonNumerics.add(short.class.getSimpleName()); + commonNumerics.add(Short.class.getSimpleName()); + commonNumerics.add(int.class.getSimpleName()); + commonNumerics.add(Integer.class.getSimpleName()); + commonNumerics.add(long.class.getSimpleName()); + commonNumerics.add(Long.class.getSimpleName()); + commonNumerics.add(float.class.getSimpleName()); + commonNumerics.add(Float.class.getSimpleName()); + commonNumerics.add(double.class.getSimpleName()); + commonNumerics.add(Double.class.getSimpleName()); } private static Set<String> commonStrings; static { commonStrings = new HashSet<String>(); - commonStrings.add("char"); + commonStrings.add(char.class.getSimpleName()); + commonStrings.add(Character.class.getSimpleName()); + //FIXME tchemit 2010-11-27 : this does NOT exists in jdk api ? commonStrings.add("Char"); - commonStrings.add("String"); + commonStrings.add(String.class.getSimpleName()); } private static Set<String> commonTypes; @@ -210,9 +224,9 @@ commonTypes = new HashSet<String>(); commonTypes.addAll(commonNumerics); commonTypes.addAll(commonStrings); - commonTypes.add("boolean"); - commonTypes.add("Boolean"); - commonTypes.add("Date"); + commonTypes.add(boolean.class.getSimpleName()); + commonTypes.add(Boolean.class.getSimpleName()); + commonTypes.add(Date.class.getSimpleName()); } public static String businessEntityToContractName(ObjectModelClass clazz) {