r1389 - in topia/trunk/topia-persistence: . src/main/java/org/codelutin/topia/generator src/main/java/org/codelutin/topia/persistence src/test/java/org/codelutin/topia/persistence
Author: tchemit Date: 2009-02-20 13:56:00 +0000 (Fri, 20 Feb 2009) New Revision: 1389 Modified: topia/trunk/topia-persistence/changelog.txt topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/DepthEntityVisitor.java topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/EntityVisitor.java topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/ExportXMLVisitor.java Log: ajout propriete visite dans le EntityVisitor ajout visite sur propriete indexee reusinage EntityAbstractGenerator (pas de calcul dans les <%=...%>) Modified: topia/trunk/topia-persistence/changelog.txt =================================================================== --- topia/trunk/topia-persistence/changelog.txt 2009-02-20 12:06:29 UTC (rev 1388) +++ topia/trunk/topia-persistence/changelog.txt 2009-02-20 13:56:00 UTC (rev 1389) @@ -1,4 +1,4 @@ -2.1.3 ??? 200902?? +2.1.3 chemit 20090220 * 20090410 [chatellier] - add first letter capitalize on model name use * 20090129 [chemit] - add methods in TopiaGeneratorUtil class to optimize imports * 20090129 [thimel] - Refactor generators (part1 : remove any methods calls in <%=...%>) Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java 2009-02-20 12:06:29 UTC (rev 1388) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java 2009-02-20 13:56:00 UTC (rev 1389) @@ -262,9 +262,9 @@ /** * Envoi via les methodes du visitor l'ensemble des champs de l'entity - * avec leur type et leur valeur. + * avec leur nom, type et valeur. * - * @param visitor : le visiteur de l'entite. + * @param visitor le visiteur de l'entite. * * @throws TopiaException if any pb while visit *) @@ -289,28 +289,23 @@ String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType()); String attrName = attr.getName(); if (!GeneratorUtil.isNMultiplicity(attr)) { -/*{ visitor.visit(this, <%=attrType%>.class, <%=attrName%>); - +/*{ visitor.visit(this, "<%=attrName%>", <%=attrType%>.class, <%=attrName%>); }*/ } else { String collectionType = TopiaGeneratorUtil.getSimpleName(TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr)); -/*{ visitor.visit(this, <%=collectionType%>.class, <%=attrType%>.class, <%=attrName%>); - +/*{ visitor.visit(this, "<%=attrName%>", <%=collectionType%>.class, <%=attrType%>.class, <%=attrName%>); }*/ } } else { + String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); + assocAttrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName); + String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName()); if (!GeneratorUtil.isNMultiplicity(attr)) { - String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); - String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName()); -/*{ visitor.visit(this, <%=assocClassFQN%>.class, <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>); - +/*{ visitor.visit(this, "<%=assocAttrName%>", <%=assocClassFQN%>.class, <%=assocAttrName%>); }*/ } else { String collectionType = TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr); - String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); - String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName()); -/*{ visitor.visit(this, <%=collectionType%>.class, <%=assocClassFQN%>.class, <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>); - +/*{ visitor.visit(this, "<%=assocAttrName%>", <%=collectionType%>.class, <%=assocClassFQN%>.class, <%=assocAttrName%>); }*/ } } @@ -323,14 +318,13 @@ if (attr != null) { String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType()); String attrName = attr.getName(); -/*{ visitor.visit(this, <%=attrType%>.class, <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%>); - + attrName = GeneratorUtil.toLowerCaseFirstLetter(attrName); +/*{ visitor.visit(this, "<%=attrName%>", <%=attrType%>.class, <%=attrName%>); }*/ } } } -/*{ - visitor.end(this); +/*{ visitor.end(this); } @Override @@ -344,11 +338,12 @@ if (attr.referenceClassifier() && attr.getClassifier().hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) { if (attr.isAggregate()) { String attrName = attr.getName(); + String getterName = "get" + GeneratorUtil.capitalize(attrName); if (GeneratorUtil.isNMultiplicity(attr)) { -/*{ tmp.addAll(get<%=GeneratorUtil.capitalize(attrName)%>()); +/*{ tmp.addAll(<%=getterName%>()); }*/ } else { -/*{ tmp.add(get<%=GeneratorUtil.capitalize(attrName)%>()); +/*{ tmp.add(<%=getterName%>()); }*/ } } @@ -376,21 +371,23 @@ for (ObjectModelAttribute attr : clazz.getAttributes()) { if (attr.referenceClassifier() && attr.getClassifier().hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) { if (attr.isComposite()) { - String attrName = attr.getName(); + String attrName = attr.getName(); + String getterName = "get" + GeneratorUtil.capitalize(attrName); if (GeneratorUtil.isNMultiplicity(attr)) { -/*{ tmp.addAll(get<%=GeneratorUtil.capitalize(attrName)%>()); +/*{ tmp.addAll(<%=getterName%>()); }*/ } else { -/*{ tmp.add(get<%=GeneratorUtil.capitalize(attrName)%>()); +/*{ tmp.add(<%=getterName%>()); }*/ } } else if (attr.hasAssociationClass()) { String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName()); + String ref = "this." + GeneratorUtil.toLowerCaseFirstLetter(assocAttrName); if (!GeneratorUtil.isNMultiplicity(attr)) { /*{ - if (this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> != null) { - tmp.add(this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>); + if (<%=ref%> != null) { + tmp.add(<%=ref%>); } }*/ } else { @@ -403,8 +400,8 @@ // sur les asso, le champs est dans le mapping // hibernate et donc il le faut aussi dans la classe // sinon hibernate rale lorsqu'il charge l'objet -// if (this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> != null) { -// tmp.addAll(this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>); +// if (<%=ref%> != null) { +// tmp.addAll(<%=ref%>); // } /*{ tmp.addAll(((TopiaContextImplementor)getTopiaContext()) Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/DepthEntityVisitor.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/DepthEntityVisitor.java 2009-02-20 12:06:29 UTC (rev 1388) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/DepthEntityVisitor.java 2009-02-20 13:56:00 UTC (rev 1389) @@ -65,7 +65,7 @@ * @see org.codelutin.topia.persistence.EntityVisitor#visit(org.codelutin.topia.persistence.TopiaEntity, java.lang.Class, java.lang.Object) */ @Override - public void visit(TopiaEntity e, Class type, Object value) { + public void visit(TopiaEntity e, String name, Class type, Object value) { // si c'est une entité if(value instanceof TopiaEntity) { TopiaEntity entity = (TopiaEntity)value; @@ -80,7 +80,7 @@ } } else { - delegateVisitor.visit(e, type, value); + delegateVisitor.visit(e, name, type, value); } } @@ -88,17 +88,37 @@ * @see org.codelutin.topia.persistence.EntityVisitor#visit(org.codelutin.topia.persistence.TopiaEntity, java.lang.Class, java.lang.Class, java.lang.Object) */ @Override - public void visit(TopiaEntity e, Class collectionType, Class type, + public void visit(TopiaEntity e, String name, Class collectionType, Class type, Object value) { Collection cValue = (Collection)value; if(cValue != null && !cValue.isEmpty()) { + int i=0; for (Object currentValue : cValue) { - visit(e, type, currentValue); + visit(e, name, type, collectionType ,i++, currentValue); } } } + @Override + public void visit(TopiaEntity e, String name, Class collectionType, Class type, int index, Object value) { + // si c'est une entité + if(value instanceof TopiaEntity) { + TopiaEntity entity = (TopiaEntity)value; + try { + if(!alreadyExplored.contains(entity)) { + entity.accept(this); + } + } catch (TopiaException e1) { + if(log.isErrorEnabled()) { + log.error("Error on depth exploration", e1); + } + } + } + else { + delegateVisitor.visit(e, name, collectionType, type, index, value); + } + } /* * @see org.codelutin.topia.persistence.EntityVisitor#end(org.codelutin.topia.persistence.TopiaEntity) */ @@ -107,13 +127,12 @@ delegateVisitor.end(e); } - /** - * Pour pouvoir nettoyer le visiteur, afin de pouvoir - * réutiliser plusieurs fois de suite la même instance - * de ce visiteur. - */ - public void clean() { + @Override + public void clear() { alreadyExplored.clear(); + delegateVisitor.clear(); } + + } Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/EntityVisitor.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/EntityVisitor.java 2009-02-20 12:06:29 UTC (rev 1388) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/EntityVisitor.java 2009-02-20 13:56:00 UTC (rev 1389) @@ -19,6 +19,8 @@ /** * + * The contract of a visitor of any {@link TopiaEntity}. + * * Created: 28 janv. 2009 18:10:34 * * @author poussin @@ -29,8 +31,61 @@ */ public interface EntityVisitor { - public void start(TopiaEntity e); - public void end(TopiaEntity e); - public void visit(TopiaEntity e, Class type, Object value); - public void visit(TopiaEntity e, Class collectionType, Class type, Object value); + /** + * Start the visit of the given entity. + * + * @param e the visited entity + */ + void start(TopiaEntity e); + + /** + * Ends the visit of the given entity. + * + * @param e the visited entity + */ + void end(TopiaEntity e); + + /** + * Visit a none indexed property for the given entity. + * + * The property visited is defined by the other parameters. + * + * @param e the visited entity + * @param name the name of the visited property + * @param type the type of the visited property + * @param value the value of the visitied property + */ + void visit(TopiaEntity e, String name, Class type, Object value); + + /** + * Visit a collection property for the given entity. + * + * The property visited is defined by the other parameters. + * + * @param e the visited entity + * @param name the name of the visited property + * @param collectionType the type of the visited collection + * @param type the type of the visited property + * @param value the value of the visitied property + */ + void visit(TopiaEntity e, String name, Class collectionType, Class type, Object value); + + /** + * Visit a indexed value from a collection property for the given entity. + * + * The property visited is defined by the other parameters. + * + * @param e the visited entity + * @param name the name of the visited property + * @param collectionType the type of the container of the visited property + * @param type the type of the visited property + * @param index the index of the visited property in his container + * @param value the value of the visitied property + */ + void visit(TopiaEntity e, String name, Class collectionType, Class type, int index, Object value); + + /** + * reset all states of the visitor. + */ + void clear(); } Modified: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/ExportXMLVisitor.java =================================================================== --- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/ExportXMLVisitor.java 2009-02-20 12:06:29 UTC (rev 1388) +++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/persistence/ExportXMLVisitor.java 2009-02-20 13:56:00 UTC (rev 1389) @@ -46,9 +46,6 @@ buffer = new StringBuffer(); } - /* - * @see org.codelutin.topia.persistence.EntityVisitor#start(org.codelutin.topia.persistence.TopiaEntity) - */ @Override public void start(TopiaEntity e) { if(log.isDebugEnabled()) { @@ -62,11 +59,8 @@ buffer.append(">\n"); } - /* - * @see org.codelutin.topia.persistence.EntityVisitor#visit(org.codelutin.topia.persistence.TopiaEntity, java.lang.Class, java.lang.Object) - */ @Override - public void visit(TopiaEntity e, Class type, Object value) { + public void visit(TopiaEntity e, String name, Class type, Object value) { if(log.isDebugEnabled()) { log.debug("visit : " + e); } @@ -74,18 +68,16 @@ buffer.append("<" + type.getName() + ">" + value + "</" + type.getName() + ">\n"); } - /* - * @see org.codelutin.topia.persistence.EntityVisitor#visit(org.codelutin.topia.persistence.TopiaEntity, java.lang.Class, java.lang.Class, java.lang.Object) - */ @Override - public void visit(TopiaEntity e, Class collectionType, Class type, + public void visit(TopiaEntity e, String name, Class collectionType, Class type, Object value) { + } + @Override + public void visit(TopiaEntity e, String name, Class collectionType, Class type, int index, Object value) { + visit(e, name, type, value); } - /* - * @see org.codelutin.topia.persistence.EntityVisitor#end(org.codelutin.topia.persistence.TopiaEntity) - */ @Override public void end(TopiaEntity e) { if(log.isDebugEnabled()) { @@ -100,4 +92,12 @@ String content = buffer.toString(); return content; } + + @Override + public void clear() { + // do nothing + } + + + }
participants (1)
-
tchemit@users.labs.libre-entreprise.org