Index: topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.12 topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.13 --- topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.12 Tue Jul 26 14:02:57 2005 +++ topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java Wed Jul 27 16:35:52 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.12 $ + * @version $Revision: 1.13 $ * - * Mise a jour: $Date: 2005/07/26 14:02:57 $ + * Mise a jour: $Date: 2005/07/27 16:35:52 $ * par : $Author: thimel $ */ @@ -68,7 +68,7 @@ // Consider only entities, return immediately if not an entity if (! accept(clazz)) return; - + // ------------- File Header generatePackageStatement(output, clazz); Index: topia/src/java/org/codelutin/topia/generators/Util.java diff -u topia/src/java/org/codelutin/topia/generators/Util.java:1.10 topia/src/java/org/codelutin/topia/generators/Util.java:1.11 --- topia/src/java/org/codelutin/topia/generators/Util.java:1.10 Tue Jul 26 16:54:24 2005 +++ topia/src/java/org/codelutin/topia/generators/Util.java Wed Jul 27 16:35:52 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.10 $ + * @version $Revision: 1.11 $ * - * Mise a jour: $Date: 2005/07/26 16:54:24 $ + * Mise a jour: $Date: 2005/07/27 16:35:52 $ * par : $Author: thimel $ */ @@ -379,9 +379,8 @@ * @return Une String représentant la class d'association */ public static String getQualifiedAssociationClassName(ObjectModelAttribute attr) { - if (attr.hasAssociationClass()) { + if (attr.hasAssociationClass()) return attr.getAssociationClass().getQualifiedName(); - } String packageName; String name; String local = attr.getName(); Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java:1.11 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java:1.12 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java:1.11 Tue Jul 26 13:17:17 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java Wed Jul 27 16:35:52 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.11 $ + * @version $Revision: 1.12 $ * - * Mise a jour: $Date: 2005/07/26 13:17:17 $ + * Mise a jour: $Date: 2005/07/27 16:35:52 $ * par : $Author: thimel $ */ @@ -49,6 +49,8 @@ public class ObjectModelToEntityPersistenceServiceImplGenerator extends TopiaAbstractObjectModelGenerator { // OjectModelToEntityPersistenceServiceImplGenerator + ObjectModelClassifier currentClazz; + public ObjectModelToEntityPersistenceServiceImplGenerator(){ super(); } @@ -71,6 +73,7 @@ ////////////////////////////////////////////////////////////////////// public void generateClassDeclaration(Writer output, ObjectModelClassifier clazz) throws IOException { + currentClazz = clazz; Collection operations = new LinkedList(); operations.addAll(clazz.getOperations()); operations.addAll(clazz.getAllOtherOperations(false)); @@ -104,12 +107,12 @@ /** * @return an entity *) - public <%=attribute.getDeclaringElement().getName()%> findBy<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException{ + public <%=currentClazz.getName()%> findBy<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException{ List result = find(newQuery().where("<%=attribute.getName()%> = ?").addArg(value)); if(result.size() == 0){ return null;/*throw new TopiaNotFoundException("Can't find object with attribute <%=attribute.getName()%> == " + value);*) } - return (<%=attribute.getDeclaringElement().getName()%>)result.get(0); + return (<%=currentClazz.getName()%>)result.get(0); } /** Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.23 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.24 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.23 Tue Jul 26 16:54:24 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java Wed Jul 27 16:35:52 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.23 $ + * @version $Revision: 1.24 $ * - * Mise a jour: $Date: 2005/07/26 16:54:24 $ + * Mise a jour: $Date: 2005/07/27 16:35:52 $ * par : $Author: thimel $ */ @@ -324,9 +324,9 @@ }*/ } else { if (!attribute.hasAssociationClass()) { -/*{ public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) { +/*{ public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException { <%=Util.getQualifiedAssociationClassName(attribute)%> oldAssocClass = (<%=Util.getQualifiedAssociationClassName(attribute)%>)getContext().getAssociationManager().getAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_); - <%=Util.getQualifiedAssociationClassName(attribute)%> newAssocClass = ((oldAssocClass == null) ? new <%=Util.getQualifiedAssociationClassName(attribute)%>() : oldAssocClass.clone()); + <%=Util.getQualifiedAssociationClassName(attribute)%> newAssocClass = new <%=Util.getQualifiedAssociationClassName(attribute)%>Impl(); if (newAssocClass != null) { newAssocClass.set<%=Util.capitalize(attribute.getName())%>(value); }*/ @@ -380,7 +380,7 @@ /*{ public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { TopiaAccessController.checkPermission(this, "write"); - <%=Util.getQualifiedAssociationClassName(attribute)%> association = new <%=Util.getQualifiedAssociationClassName(attribute)%>(); + <%=Util.getQualifiedAssociationClassName(attribute)%> association = new <%=Util.getQualifiedAssociationClassName(attribute)%>Impl(); association.set<%=Util.capitalize(attribute.getName())%>(value); }*/ if (attribute.getReverseAttribute() != null) { @@ -511,7 +511,7 @@ Iterator it = list.iterator(); while (it.hasNext()) { <%=attribute.getType()%> value = (<%=attribute.getType()%>)it.next(); - <%=Util.getQualifiedAssociationClassName(attribute)%> association = new <%=Util.getQualifiedAssociationClassName(attribute)%>(); + <%=Util.getQualifiedAssociationClassName(attribute)%> association = new <%=Util.getQualifiedAssociationClassName(attribute)%>Impl(); }*/ if (attribute.getReverseAttribute() != null) { /*{ association.set<%=Util.capitalize(attribute.getReverseAttribute().getName())%>(this); @@ -548,7 +548,7 @@ } if (!Util.isAttributeEntity(attribute)) { -/*{ public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException { +/*{ public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getType()%> value) throws TopiaException { TopiaAccessController.checkPermission(this, "write"); }*/ if (attribute.isComposite()) { @@ -560,6 +560,11 @@ this._<%=attribute.getName()%>Modified_ = true; } }*/ + } else { +/*{ public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getType()%> value) throws TopiaException { + throw new TopiaException("Not Yet supported"); + } +}*/ } } Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java:1.6 topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java:1.7 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java:1.6 Tue Jul 26 16:54:24 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java Wed Jul 27 16:35:52 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ * - * Mise a jour: $Date: 2005/07/26 16:54:24 $ + * Mise a jour: $Date: 2005/07/27 16:35:52 $ * par : $Author: thimel $ */ @@ -102,9 +102,6 @@ gen = new ObjectModelToServiceGenerator(); gen.generate(model, destDir); - Logger.getLogger(getClass().getName() + ".generate").log(Level.FINE, "Generation de ObjectModelToAssociationClassesGenerator"); - gen = new ObjectModelToAssociationClassesGenerator(); - gen.generate(model, destDir); } } // ObjectModelToTopiaMetaGenerator Index: topia/src/java/org/codelutin/topia/generators/TopiaObjectModelModifier.java diff -u topia/src/java/org/codelutin/topia/generators/TopiaObjectModelModifier.java:1.1 topia/src/java/org/codelutin/topia/generators/TopiaObjectModelModifier.java:1.2 --- topia/src/java/org/codelutin/topia/generators/TopiaObjectModelModifier.java:1.1 Tue Jul 26 16:54:24 2005 +++ topia/src/java/org/codelutin/topia/generators/TopiaObjectModelModifier.java Wed Jul 27 16:35:52 2005 @@ -1,12 +1,76 @@ package org.codelutin.topia.generators; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; +import org.codelutin.generator.models.object.xml.ObjectModeImplAssociationClassParticipant; +import org.codelutin.generator.models.object.xml.ObjectModelAssociationClassImpl; +import org.codelutin.generator.models.object.xml.ObjectModelAttributeImpl; +import org.codelutin.generator.models.object.xml.ObjectModelImpl; +import org.codelutin.generator.models.object.xml.ObjectModelImplRef; public class TopiaObjectModelModifier implements ObjectModelModifier { public ObjectModel modify(ObjectModel model) { - model.getClasses(); - return model; + if (!(model instanceof ObjectModelImpl)) + return model; // Si ce n'est pas un ObjectModelImpl, on ne pourra pas ajouter de classes + ObjectModelImpl modelImpl = (ObjectModelImpl)model; + // On parcours toutes les classes du modèle + Iterator classes = modelImpl.getClasses().iterator(); + List listClasses = new ArrayList(); + while (classes.hasNext()) { + listClasses.add((ObjectModelClass)classes.next()); + } + for (ObjectModelClass clazz : listClasses) { + // On parcours tous les attributs de la classe + Iterator attributes = clazz.getAttributes().iterator(); + while (attributes.hasNext()) { + ObjectModelAttribute attribute = (ObjectModelAttribute)attributes.next(); + // Si c'est l'attribut désigne une entity, alors il faut créer une class d'association entre les attributs + if (Util.isAttributeEntity(attribute)) { + String qualifiedAssociationClassName = Util.getQualifiedAssociationClassName(attribute); + // Si la classe existe déjà, on ne la recréé pas ! + if (modelImpl.getClass(qualifiedAssociationClassName) == null) { + ObjectModelAssociationClassImpl assocClassImpl = (ObjectModelAssociationClassImpl)modelImpl.parsetAssociationClass(null); + + assocClassImpl.parsetType(qualifiedAssociationClassName);//TODO + assocClassImpl.parsetName(qualifiedAssociationClassName.substring(qualifiedAssociationClassName.lastIndexOf(".") + 1)); + assocClassImpl.parsetPackage(qualifiedAssociationClassName.substring(0, qualifiedAssociationClassName.lastIndexOf("."))); + + // participant 1 + ObjectModeImplAssociationClassParticipant part = assocClassImpl.parsetParticipant(null); + part.parsetName(((ObjectModelClass)attribute.getDeclaringElement()).getQualifiedName()); + part.parsetAttribute(attribute.getName()); + assocClassImpl.parsetParticipant(part); + + // participant 2 + if (attribute.getReverseAttribute() != null) { + ObjectModelAttribute reverse = (ObjectModelAttribute)attribute.getReverseAttribute(); + part = assocClassImpl.parsetParticipant(null); + part.parsetName(((ObjectModelClass)reverse.getDeclaringElement()).getQualifiedName()); + part.parsetAttribute(reverse.getName()); + assocClassImpl.parsetParticipant(part); + } + + // stéréotypes + ObjectModelImplRef ref = assocClassImpl.parsetStereotype(null); + ref.parsetName("entity"); + assocClassImpl.parsetStereotype(ref); + + ref = assocClassImpl.parsetStereotype(null); + ref.parsetName("associationClassGenerated"); + assocClassImpl.parsetStereotype(ref); + + modelImpl.parsetAssociationClass(assocClassImpl); + } + } + } + } + return modelImpl; } } Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java:1.11 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java:1.12 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java:1.11 Fri Jul 22 16:57:57 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java Wed Jul 27 16:35:52 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.11 $ + * @version $Revision: 1.12 $ * - * Mise a jour: $Date: 2005/07/22 16:57:57 $ + * Mise a jour: $Date: 2005/07/27 16:35:52 $ * par : $Author: thimel $ */ @@ -45,6 +45,8 @@ public class ObjectModelToEntityPersistenceServiceGenerator extends TopiaAbstractObjectModelGenerator { // ObjectModelToEntityPersistenceServiceGenerator + ObjectModelClassifier currentClazz; + public ObjectModelToEntityPersistenceServiceGenerator(){ super(); } @@ -68,6 +70,7 @@ public void generateClassDeclaration(Writer output, ObjectModelClassifier clazz) throws IOException { + currentClazz = clazz; /*{ /** <%=clazz.getDocumentation()%> @@ -101,11 +104,12 @@ public void generateNormalAttributeDeclaration(Writer output, ObjectModelAttribute attribute) throws IOException { + currentClazz.getName(); /*{ /** * @return an entity *) - public <%=attribute.getDeclaringElement().getName()%> findBy<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException; + public <%=currentClazz.getName()%> findBy<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException; /** * @return an unmodifiable collection Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.11 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.12 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.11 Tue Jul 26 16:54:24 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java Wed Jul 27 16:35:52 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.11 $ + * @version $Revision: 1.12 $ * - * Mise a jour: $Date: 2005/07/26 16:54:24 $ + * Mise a jour: $Date: 2005/07/27 16:35:52 $ * par : $Author: thimel $ */ @@ -34,6 +34,7 @@ import java.io.IOException; import java.io.Writer; import java.util.Iterator; +import java.util.List; import org.codelutin.generator.Generator; import org.codelutin.generator.models.object.ObjectModelAssociationClass; @@ -96,7 +97,8 @@ }*/ if (clazz instanceof ObjectModelAssociationClass) { ObjectModelAssociationClass assocClass = (ObjectModelAssociationClass)clazz; - Iterator it = assocClass.getParticipantsAttributes().iterator(); + List list = assocClass.getParticipantsAttributes(); + Iterator it = list.iterator(); String[] ids = {"A", "B"}; for (int i=0; (it.hasNext() && i < ids.length); i++) { ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); @@ -221,13 +223,10 @@ public void generateSetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { - if (!Util.isAttributeEntity(attribute)) { /*{ <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getType()%> value) throws TopiaException; -}*/ - } -/*{ + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException;