r1266 - topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator
Author: tchemit Date: 2008-12-11 21:33:45 +0000 (Thu, 11 Dec 2008) New Revision: 1266 Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityImplGenerator.java Log: fix methods to test if a EnittyImpl is abstract (was not ok when you add an Interface to a Entity) Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityImplGenerator.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityImplGenerator.java 2008-12-11 16:33:58 UTC (rev 1265) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityImplGenerator.java 2008-12-11 21:33:45 UTC (rev 1266) @@ -33,14 +33,19 @@ import java.io.IOException; import java.io.Writer; import java.util.Iterator; +import java.util.Collection; import org.codelutin.generator.Generator; import org.codelutin.generator.ObjectModelGenerator; import org.codelutin.generator.models.object.ObjectModelClass; import org.codelutin.generator.models.object.ObjectModelOperation; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; public class EntityImplGenerator extends ObjectModelGenerator { + private static final Log log = LogFactory.getLog(EntityImplGenerator.class); + public EntityImplGenerator() { super(); } @@ -61,17 +66,17 @@ } //De même, on ne génère pas le impl si il y a des opérations venant des // superclasses non implémentées - for (Iterator otherOps = clazz.getAllOtherOperations(false).iterator(); otherOps.hasNext(); ) { - ObjectModelOperation otherOp = (ObjectModelOperation)otherOps.next(); + for (ObjectModelOperation otherOp : clazz.getAllOtherOperations(false)) { if (otherOp.isAbstract()) { return; } } - boolean isAbstract = clazz.isAbstract(); + boolean isAbstract = isAbstract(clazz); + //boolean isAbstract = clazz.isAbstract(); //Une classe peut être abstraite si elle a des méthodes définies dans // ses superinterface et non implantées dans ses superclasses - if (!isAbstract) { + /*if (!isAbstract) { for (Iterator operations = clazz.getAllInterfaceOperations(true).iterator(); (!isAbstract) && operations.hasNext(); ) { ObjectModelOperation op = (ObjectModelOperation)operations.next(); boolean implementationFound = false; @@ -84,7 +89,7 @@ } isAbstract = !implementationFound; } - } + }*/ String copyright = GeneratorUtil.getCopyright(model); if (GeneratorUtil.notEmpty(copyright)) { /*{<%=copyright%> @@ -107,4 +112,35 @@ }*/ } + + protected boolean isAbstract(ObjectModelClass clazz) { + if (clazz.isAbstract()) { + return true; + } + + //Une classe peut être abstraite si elle a des méthodes définies dans + // ses superinterface et non implantées dans ses superclasses + Collection<ObjectModelOperation> allInterfaceOperations = clazz.getAllInterfaceOperations(true); + allInterfaceOperations.removeAll(clazz.getAllOtherOperations(true)); + for (ObjectModelOperation op : allInterfaceOperations) { + boolean implementationFound = false; + for (ObjectModelClass superClazz : clazz.getSuperclasses()) { + for (ObjectModelOperation matchingOp : superClazz.getOperations(op.getName())) { + implementationFound = (op.equals(matchingOp) && !matchingOp.isAbstract()); + if (implementationFound) { + break; + } + } + if (implementationFound) { + break; + } + } + if (!implementationFound) { + log.info(clazz.getName()+" : abstract operation "+op); + return true; + } + } + return false; + } + } //EntityPOJOGenerator
participants (1)
-
tchemit@users.labs.libre-entreprise.org