r2322 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
Author: tchemit Date: 2011-08-29 18:38:35 +0200 (Mon, 29 Aug 2011) New Revision: 2322 Url: http://nuiton.org/repositories/revision/topia/2322 Log: Evolution #1716: Improve generators Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2011-08-19 16:29:32 UTC (rev 2321) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2011-08-29 16:38:35 UTC (rev 2322) @@ -51,6 +51,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -112,9 +113,9 @@ if (log.isDebugEnabled()) { log.debug("for entity : " + input.getQualifiedName()); - log.info("Will use classLoader " + getClassLoader()); + log.debug("Will use classLoader " + getClassLoader()); } - + // fix once for all the constant prefix to use String prefix = getConstantPrefix(input, ""); if (StringUtils.isEmpty(prefix)) { @@ -185,23 +186,30 @@ protected void createEntityInterface(ObjectModelClass input) { - outputInterface = createInterface(input.getName(), input.getPackageName()); + outputInterface = createInterface(input.getName(), + input.getPackageName()); // Documentation if (TopiaGeneratorUtil.hasDocumentation(input)) { setDocumentation(outputInterface, input.getDocumentation()); } + if (log.isTraceEnabled()) { + log.trace("Will add interfaces on " + + outputInterface.getQualifiedName()); + } + + List<String> interfaceAlreadyDone = new LinkedList<String> (); // Extends for (ObjectModelClassifier parent : input.getInterfaces()) { - addInterface(outputInterface, parent.getQualifiedName()); + addInterface(interfaceAlreadyDone, outputInterface, parent); } // Extends from inheritance boolean needTopiaEntity = true; for (ObjectModelClassifier parent : input.getSuperclasses()) { if (TopiaGeneratorUtil.isEntity(parent)) { - addInterface(outputInterface, parent.getQualifiedName()); + addInterface(interfaceAlreadyDone, outputInterface, parent); needTopiaEntity = false; break; } @@ -209,12 +217,16 @@ // Extends TopiaEntity (only if hasn't parent entity) if (needTopiaEntity) { + + Class<?> interfaze = TopiaEntity.class; + if (TopiaGeneratorUtil.isContextable(input)) { - addInterface(outputInterface, TopiaEntityContextable.class); + interfaze = TopiaEntityContextable.class; } - else { - addInterface(outputInterface, TopiaEntity.class); - } + + addInterface(interfaceAlreadyDone, + outputInterface, + interfaze); } } @@ -263,12 +275,17 @@ } // serialVersionUID - String svUID = - TopiaGeneratorUtil.findTagValue("serialVersionUID", input, model); - if (svUID != null) { - addConstant(outputInterface, "serialVersionUID", long.class, svUID, + String svUID = TopiaGeneratorUtil.findTagValue("serialVersionUID", + input, + model + ); + if (svUID == null) { + + // use a default one + svUID = "1L"; + } + addConstant(outputAbstract, "serialVersionUID", long.class, svUID, ObjectModelModifier.PRIVATE); - } addContextableMethods(input, outputAbstract); } @@ -276,8 +293,11 @@ /** * Ajout les methodes necessaire à l'interface {@link TopiaEntityContextable} * si le tagValue {@link TopiaTagValues#TAG_CONTEXTABLE} est renseigné. + * @param input + * @param outputAbstract */ - protected void addContextableMethods(ObjectModelClass input, ObjectModelClass outputAbstract) { + protected void addContextableMethods(ObjectModelClass input, + ObjectModelClass outputAbstract) { if (TopiaGeneratorUtil.isContextable(input)) { @@ -304,7 +324,6 @@ }*/ ); } - } protected boolean isGenerateImpl(ObjectModelClass input, @@ -363,6 +382,16 @@ setDocumentation(outputImpl, "Implantation des operations pour l'entité " + input.getName() + "."); setSuperClass(outputImpl, input.getQualifiedName() + "Abstract"); + + String svUID = + TopiaGeneratorUtil.findTagValue("serialVersionUID", input, model); + if (svUID == null) { + + // use a default one + svUID = "1L"; + } + addConstant(outputImpl, "serialVersionUID", long.class, svUID, + ObjectModelModifier.PRIVATE); } /** @@ -1552,4 +1581,46 @@ return operation; } + + protected void addInterface(List<String> interfaceAlreadyDone, + ObjectModelClassifier output, + ObjectModelClassifier interfaze) { + String qualifiedName = interfaze.getQualifiedName(); + if (!interfaceAlreadyDone.contains(qualifiedName)) { + + interfaceAlreadyDone.add(qualifiedName); + + if (output != null) { + + // add it to output + addInterface(output, qualifiedName); + + if (log.isTraceEnabled()) { + log.trace("Add interface " + qualifiedName + " on " + + output.getQualifiedName()); + } + } else { + if (log.isTraceEnabled()) { + log.trace("Skip included interface " + qualifiedName); + } + } + + // scan also all interfaces or super-classes of it + for (ObjectModelClassifier parent : interfaze.getInterfaces()) { + addInterface(interfaceAlreadyDone, null, parent); + } + } + } + + protected void addInterface(List<String> interfaceAlreadyDone, + ObjectModelClassifier output, + Class<?> clazz) { + String qualifiedName = clazz.getName(); + if (!interfaceAlreadyDone.contains(qualifiedName)) { + + // add it to output + addInterface(output, qualifiedName); + + } + } }
participants (1)
-
tchemit@users.nuiton.org