Index: topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.8 topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.9 --- topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.8 Tue Jun 21 17:00:43 2005 +++ topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java Thu Jul 21 12:54:50 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * - * Mise a jour: $Date: 2005/06/21 17:00:43 $ + * Mise a jour: $Date: 2005/07/21 12:54:50 $ * par : $Author: thimel $ */ @@ -199,6 +199,7 @@ import org.codelutin.topia.TopiaArgument; import org.codelutin.topia.TopiaAssociationsManager; import org.codelutin.topia.security.TopiaAccessController; +import org.codelutin.topia.annotation.*; import org.codelutin.generator.models.object.ObjectModelClass; import org.codelutin.generator.models.object.ObjectModelInterface; import java.util.List; Index: topia/src/java/org/codelutin/topia/generators/Util.java diff -u topia/src/java/org/codelutin/topia/generators/Util.java:1.7 topia/src/java/org/codelutin/topia/generators/Util.java:1.8 --- topia/src/java/org/codelutin/topia/generators/Util.java:1.7 Wed Jul 6 17:51:24 2005 +++ topia/src/java/org/codelutin/topia/generators/Util.java Thu Jul 21 12:54:50 2005 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ * - * Mise a jour: $Date: 2005/07/06 17:51:24 $ - * par : $Author: bpoussin $ + * Mise a jour: $Date: 2005/07/21 12:54:50 $ + * par : $Author: thimel $ */ package org.codelutin.topia.generators; @@ -306,6 +306,71 @@ } return result; } + + /** + * Retourne la liste des champs + * @param clazz la classe dont on souhaite lister les champs + * @return une String contenant les noms des champs sous la forme : '"a", "b", "c", [...], "k"' + */ + public static String getFieldList(ObjectModelClass clazz) { + String output = ""; + Collection attributes = clazz.getAttributes(); + if (attributes != null) { + Iterator it = attributes.iterator(); + while (it.hasNext()) { + ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); + output += "\"" + attr.getName() + "\""; + if (it.hasNext()) + output += ", "; + } + } + return output; + } + + /** + * Retourne la liste des types des champs d'un classe spécifiée (valeur + * textuelle d'un tableau de Class : + * 'Class[] classes = {<%=getFieldTypes(clazz)%>}') + * ATTENTION, les types primitifs sont tranformés en class de la classe + * associée, par exemple : int > Integer.class, float > Float.class + * @param clazz la classe dont on souhaite lister le type des champs + * @return une String contenant la liste des types des champs sous la forme : 'Integer.class, java.lang.String.class, mon.package.MaClasse.class, [...]' + */ + public static String getFieldClassTypes(ObjectModelClass clazz) { + String output = ""; + Collection attributes = clazz.getAttributes(); + if (attributes != null) { + Iterator it = attributes.iterator(); + while (it.hasNext()) { + ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); + output += getFieldClassType(attr); + if (it.hasNext()) + output += ", "; + } + } + return output; + } + + /** + * Retourne le type de l'attribut spécifié. + * ATTENTION, les types primitifs sont tranformés en class de la classe + * associée, par exemple : int > Integer.class, float > Float.class + * @param attr l'attribut dont on souhaite connaitre le type + * @return le type de l'attribut + */ + public static String getFieldClassType(ObjectModelAttribute attr) { + String output = ""; + if (Util.isPrimitiveAttributeType(attr)) { + if (attr.getType().equals("int")) + output += "Integer"; // Int > Integer + else + output += Util.capitalize(attr.getType()); + output += ".class"; + } else + output += attr.getType() + ".class"; + return output; + } + } // Util Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.19 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.20 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.19 Tue Jul 19 12:27:14 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java Thu Jul 21 12:54:50 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.19 $ + * @version $Revision: 1.20 $ * - * Mise a jour: $Date: 2005/07/19 12:27:14 $ + * Mise a jour: $Date: 2005/07/21 12:54:50 $ * par : $Author: thimel $ */ @@ -585,7 +585,7 @@ /*{ /** * Delete this entity with its persistenceService - *) + *) }*/ /*implements TopiaEntiti.remove()*/ /*{ public void remove() throws TopiaException{ <%=clazz.getName()%>PersistenceService persistenceService = getPersistenceService(); persistenceService.delete(this); Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.7 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.8 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.7 Wed Jul 6 22:35:20 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java Thu Jul 21 12:54:50 2005 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ * - * Mise a jour: $Date: 2005/07/06 22:35:20 $ - * par : $Author: bpoussin $ + * Mise a jour: $Date: 2005/07/21 12:54:50 $ + * par : $Author: thimel $ */ package org.codelutin.topia.generators; @@ -35,13 +35,14 @@ import java.io.Writer; import java.util.Iterator; +import org.codelutin.generator.Generator; +import org.codelutin.generator.models.object.ObjectModelAssociationClass; import org.codelutin.generator.models.object.ObjectModelAttribute; import org.codelutin.generator.models.object.ObjectModelClass; import org.codelutin.generator.models.object.ObjectModelClassifier; import org.codelutin.generator.models.object.ObjectModelInterface; import org.codelutin.generator.models.object.ObjectModelOperation; -import org.codelutin.topia.generators.Util; -import org.codelutin.generator.Generator; +import org.codelutin.topia.annotation.MethodType; public class ObjectModelToEntityGenerator extends TopiaAbstractObjectModelGenerator { // ObjectModelToEntityGenerator @@ -65,13 +66,57 @@ // C L A S S D E C L A R A T I O N ////////////////////////////////////////////////////////////////////// + public String generateMethodInfo(MethodType type, boolean isModifier, ObjectModelAttribute attr) { + String output = "@MethodInfo (\n"; + output += " type = MethodType." + type; + if (type == MethodType.FIELD_ACCESSOR) { + output += ",\n field = \"" + attr.getName() + "\""; + output += ",\n isFieldModifier = " + isModifier + ""; + if (attr.hasAssociationClass()) + output += ",\n associationClass = " + attr.getAssociationClass().getQualifiedName() + ".class"; + output += ",\n fieldType = " + Util.getFieldClassType(attr); + } + return (output + "\n )"); + } + + public void generateClassInfo(Writer output, ObjectModelClassifier clazz) + throws IOException { +/*{@ClassInfo( + type = ClassType.ENTITY, + isAssociationClass = <%=(clazz instanceof ObjectModelAssociationClass)%>, + isGeneratedClass = false, }*/ /*TODO Arno Puisque pas encore de AssociationClass pour ttes les relations, on reste à false*/ /*{ +}*/ + if (clazz instanceof ObjectModelAssociationClass) { + ObjectModelAssociationClass assocClass = (ObjectModelAssociationClass)clazz; + Iterator it = assocClass.getParticipantsAttributes().iterator(); + String[] ids = {"A", "B"}; + for (int i=0; (it.hasNext() && i < ids.length); i++) { + ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); +/*{ + association<%=ids[i]%> = <%=attr.getType()%>.class, + association<%=ids[i]%>Field = "<%=attr.getName()%>", + association<%=ids[i]%>Cardinality = {<%=attr.getMinMultiplicity()%>, <%=attr.getMaxMultiplicity()%>}, +}*/// association<%=ids[i]%>IsComposition = ... /* TODO Arno Vériier si la valeur par défaut correspond */ + } + } +/*{ + schemaVersion = <%=Util.getSerialVersionUID((ObjectModelClass)clazz)%>L, + fields = {<%=Util.getFieldList((ObjectModelClass)clazz)%>}, + fieldTypes = {<%=Util.getFieldClassTypes((ObjectModelClass)clazz)%>} +}*/ /* TODO Arno fieldValues = ... A changer si on veut mettre des valeurs par défaut aux attributs */ +/*{) +}*/ + } + public void generateClassDeclaration(Writer output, ObjectModelClassifier clazz) throws IOException { /*{ /** <%=clazz.getDocumentation()%> *) -public interface <%=clazz.getName()%> extends TopiaEntity}*/ +}*/ + generateClassInfo(output, clazz); +/*{public interface <%=clazz.getName()%> extends TopiaEntity}*/ for (Iterator i = clazz.getInterfaces().iterator(); i.hasNext();) { ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); /*{, }*/ @@ -95,12 +140,13 @@ public void generateGetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ - + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute)%> public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; }*/ if (attribute.hasAssociationClass()) { /*{ + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute)%> public <%=attribute.getAssociationClass().getQualifiedName()%> get<%=attribute.getAssociationClass().getName()%>() throws TopiaException; }*/ } @@ -113,16 +159,22 @@ /** * @return an unmodifiable collection *) + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute)%> public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute)%> public int sizeOf<%=Util.capitalize(attribute.getName())%>() throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute)%> public Iterator iteratorOn<%=Util.capitalize(attribute.getName())%>() throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute)%> public boolean containsIn<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute)%> public boolean containsAllIn<%=Util.capitalize(attribute.getName())%>(java.util.Collection values) throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute)%> public <%=attribute.getType()%> get<%=Util.capitalize(attribute.getName())%>(int index) throws TopiaException; }*/ @@ -131,6 +183,7 @@ public void generateGetAssociationAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute)%> public <%=attribute.getType()%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; }*/ } @@ -144,12 +197,15 @@ throws IOException { if (!attribute.hasAssociationClass()) { /*{ + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException; }*/ } else { /*{ + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void set<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value, <%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException; }*/ } @@ -158,28 +214,38 @@ public void generateSetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getType()%> value) throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void clear<%=Util.capitalize(attribute.getName())%>() throws TopiaException; }*/ if (!attribute.hasAssociationClass()) { /*{ + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void add<%=Util.capitalize(attribute.getName())%>(/*<%=Util.getAttributeType(attribute)%>*)java.util.Collection list) throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void add<%=Util.capitalize(attribute.getName())%>(/*<%=Util.getAttributeType(attribute)%>*)java.util.Collection list, boolean duplicate) throws TopiaException; }*/ } else { /*{ + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value, <%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException; + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException; }*/ } @@ -190,6 +256,7 @@ public void generateSetAssociationAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute)%> public void set<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; }*/ } @@ -203,6 +270,7 @@ /** <%=operation.getDocumentation()%> *) + <%=generateMethodInfo(MethodType.OPERATION, false, null)%> <%=operation.getVisibility()%> <%=operation.getReturnType()%> <%=operation.getName()%> (<%=Util.getMethodParameterDeclaration(operation.getParameters())%>) throws TopiaException}*/ } @@ -222,19 +290,21 @@ /** * Return an XML representation of this entity *) + <%=generateMethodInfo(MethodType.GENERATED, false, null)%> public String toXML(); }*/ if(clazzifier instanceof ObjectModelClass){ ObjectModelClass clazz = (ObjectModelClass)clazzifier; -/*{ - public static final long schemaVersion = <%=Util.getSerialVersionUID(clazz)%>L; -}*/ +///*{ +// public static final long schemaVersion = <%=Util.getSerialVersionUID(clazz)%>L; +//}*/ /*{ /** * Return the model class for this entity as an entry point in the project entities model *) + <%=generateMethodInfo(MethodType.GENERATED, false, null)%> public ObjectModelClass getModelElement(); }*/ @@ -249,7 +319,7 @@ /*{ /** * Delete this entity with its persistenceService - *) + *) }*/ /* Déplacée dans TopiaEntity */ /*{ //public void remove() throws TopiaException; }*/ }