Index: topia/src/java/org/codelutin/topia/generators/Util.java diff -u topia/src/java/org/codelutin/topia/generators/Util.java:1.17 topia/src/java/org/codelutin/topia/generators/Util.java:1.18 --- topia/src/java/org/codelutin/topia/generators/Util.java:1.17 Wed Sep 7 16:10:28 2005 +++ topia/src/java/org/codelutin/topia/generators/Util.java Fri Sep 16 14:12:06 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.17 $ + * @version $Revision: 1.18 $ * - * Mise a jour: $Date: 2005/09/07 16:10:28 $ + * Mise a jour: $Date: 2005/09/16 14:12:06 $ * par : $Author: thimel $ */ @@ -336,19 +336,24 @@ output.append("\"" + attr.getName() + "\", "); } } - // BB 20050826 - // il faut aussi mettre dans les champs les attributs d'associations if (clazz instanceof ObjectModelAssociationClass) { ObjectModelAssociationClass assocClass = (ObjectModelAssociationClass)clazz; List list = assocClass.getParticipantsAttributes(); Iterator it = list.iterator(); - String id; + int nbAttr = 0; + ObjectModelAttribute nonNullAttr = null; while (it.hasNext()) { ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); if (attr != null) { output.append("\"" + attr.getName() + "\", "); + nonNullAttr = attr; + nbAttr++; } } + if (nbAttr < 2 && nonNullAttr != null) { + //Cas d'une navigabilité unidirectionnelle + output.append("\"" + toLowerCaseFirstLetter(nonNullAttr.getDeclaringElement().getName()) + "\", "); + } } // on supprime la virgule en trop if(output.length() >= 2){ @@ -376,18 +381,23 @@ output.append(getFieldClassType(attr) + ", "); } } - // BB 20050826 - // il faut aussi mettre dans les champs les attributs d'associations if (clazz instanceof ObjectModelAssociationClass) { ObjectModelAssociationClass assocClass = (ObjectModelAssociationClass)clazz; List list = assocClass.getParticipantsAttributes(); Iterator it = list.iterator(); - String id; + int nbAttr = 0; + ObjectModelAttribute nonNullAttr = null; while (it.hasNext()) { ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); if (attr != null) { output.append(getFieldClassType(attr) + ", "); + nonNullAttr = attr; + nbAttr++; } + } + if (nbAttr < 2 && nonNullAttr != null) { + //Cas d'une navigabilité unidirectionnelle + output.append(((ObjectModelClass)nonNullAttr.getDeclaringElement()).getQualifiedName() + ".class, "); } } // on supprime la virgule en trop Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.19 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.20 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.19 Wed Sep 7 16:10:28 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java Fri Sep 16 14:12:06 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.19 $ + * @version $Revision: 1.20 $ * - * Mise a jour: $Date: 2005/09/07 16:10:28 $ + * Mise a jour: $Date: 2005/09/16 14:12:06 $ * par : $Author: thimel $ */ @@ -67,24 +67,41 @@ // 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, boolean isAssociationFieldAccessor) { + /** + * @param type Le type de methode (selon MethodType) + * @param isModifier indique si la methode modifie l'attribut + * @param attr l'attribut concerne pas a methode + * @param isAssociationFieldAccessor indique si la methode est un accesseur a un attribut représentant une classe d'association + * @param useReverseAttribute indique si l'annotation concerne l'attribut inverse (navigabilité unidirectionnelle) + * @return renvoie l'annotation de la methode en String + */ + public String generateMethodInfo(MethodType type, boolean isModifier, ObjectModelAttribute attr, boolean isAssociationFieldAccessor, boolean useReverseAttribute) { String output = "@MethodInfo (\n"; output += " type = MethodType." + type; if (type == MethodType.FIELD_ACCESSOR) { - if (isAssociationFieldAccessor) { - output += ",\n field = \"" + Util.getAssociationClassName(attr) + "\""; + if (useReverseAttribute) { + output += ",\n field = \"" + Util.toLowerCaseFirstLetter(attr.getDeclaringElement().getName()) + "\""; } else { - output += ",\n field = \"" + attr.getName() + "\""; + if (isAssociationFieldAccessor) { + output += ",\n field = \"" + Util.getAssociationClassName(attr) + "\""; + } else { + output += ",\n field = \"" + attr.getName() + "\""; + } } output += ",\n isFieldModifier = " + isModifier + ""; if (Util.isAttributeEntity(attr)){ output += ",\n associationClass = " + Util.getQualifiedAssociationClassName(attr) + ".class"; } - output += ",\n associationParty = '" + ((Util.isFirstAttribute(attr)) ? "A" : "B") + "'"; - if (isAssociationFieldAccessor) { - output += ",\n fieldType = " + Util.getQualifiedAssociationClassName(attr) + ".class"; - } else { - output += ",\n fieldType = " + Util.getFieldClassType(attr); + if (useReverseAttribute) { + output += ",\n associationParty = 'B'"; + output += ",\n fieldType = " + ((ObjectModelClass)attr.getDeclaringElement()).getQualifiedName() + ".class"; + }else { + output += ",\n associationParty = '" + ((Util.isFirstAttribute(attr)) ? "A" : "B") + "'"; + if (isAssociationFieldAccessor) { + output += ",\n fieldType = " + Util.getQualifiedAssociationClassName(attr) + ".class"; + } else { + output += ",\n fieldType = " + Util.getFieldClassType(attr); + } } } return (output + "\n )"); @@ -102,14 +119,17 @@ List list = assocClass.getParticipantsAttributes(); Iterator it = list.iterator(); String id; + int nbAttr = 0; + ObjectModelAttribute nonNullAttr = null; while (it.hasNext()) { ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); if (attr == null) { - // La navigabilité fait que cet attribut ne doit pas - // apparaître alors on l'ignore + //On se basera sur l'attribut opposé pour déterminer les annotations sur cet attribut continue; } else { id = (Util.isFirstAttribute(attr)) ? "A" : "B"; + nonNullAttr = attr; + nbAttr++; } /*{ association<%=id%> = <%=attr.getType()%>.class, @@ -117,6 +137,16 @@ association<%=id%>Cardinality = {<%=attr.getMinMultiplicity()%>, <%=attr.getMaxMultiplicity()%>}, }*/// association<%=id%>IsComposition = ... /* TODO Vérifier si la valeur par défaut correspond */ } + if (nbAttr < 2 && nonNullAttr != null) { + id = "B"; //Navigabilité oblige, cet attribut passe en second + +/*{ + association<%=id%> = <%=((ObjectModelClass)nonNullAttr.getDeclaringElement()).getQualifiedName()%>.class, + association<%=id%>Field = "<%=Util.toLowerCaseFirstLetter(nonNullAttr.getDeclaringElement().getName())%>", + association<%=id%>Cardinality = {1, 1}, //car pas de navigabilité +}*/// association<%=id%>IsComposition = ... /* TODO Vérifier si la valeur par défaut correspond */ + + } } /*{ schemaVersion = <%=Util.getSerialVersionUID((ObjectModelClass)clazz)%>L, @@ -162,13 +192,13 @@ public void generateGetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false, false)%> public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; }*/ if (attribute.hasAssociationClass()) { /*{ - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, true)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, true, false)%> public <%=attribute.getAssociationClass().getQualifiedName()%> get<%=attribute.getAssociationClass().getName()%>() throws TopiaException; }*/ } @@ -181,22 +211,22 @@ /** * @return an unmodifiable collection *) - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false, false)%> public <%=Util.getAttributeType(attribute)%><<%=attribute.getType()%>> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false, false)%> public int sizeOf<%=Util.capitalize(attribute.getName())%>() throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false, false)%> public Iterator<<%=attribute.getType()%>> iteratorOn<%=Util.capitalize(attribute.getName())%>() throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false, false)%> public boolean containsIn<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false, false)%> public boolean containsAllIn<%=Util.capitalize(attribute.getName())%>(java.util.Collection values) throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false, false)%> public <%=attribute.getType()%> get<%=Util.capitalize(attribute.getName())%>(int index) throws TopiaException; }*/ @@ -205,12 +235,20 @@ public void generateGetAssociationAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false, false)%> public TopiaEntity get_attribute_<%=((Util.isFirstAttribute(attribute)) ? "A" : "B") %>_() throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false, false)%> public <%=attribute.getType()%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; }*/ + if (attribute.getReverseAttribute() == null) { + //Pas de navigabilité => on veut tout de même l'attribut opposé +/*{ + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, false, attribute, false, true)%> + public TopiaEntity get_attribute_B_() throws TopiaException; +}*/ + + } } @@ -222,15 +260,15 @@ throws IOException { if (!attribute.hasAssociationClass()) { /*{ - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException; }*/ } else { /*{ - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, true)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, true, false)%> public void set<%=Util.capitalize(attribute.getAssociationClass().getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value, <%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException; }*/ } @@ -239,38 +277,38 @@ public void generateSetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getType()%> value) throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void clear<%=Util.capitalize(attribute.getName())%>() throws TopiaException; }*/ if (!attribute.hasAssociationClass()) { /*{ - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void add<%=Util.capitalize(attribute.getName())%>(/*<%=Util.getAttributeType(attribute)%>*)java.util.Collection list) throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> 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, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value, <%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException; }*/ } @@ -281,13 +319,21 @@ public void generateSetAssociationAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void set_attribute_<%=((Util.isFirstAttribute(attribute)) ? "A" : "B") %>_(TopiaEntity value) throws TopiaException; - <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false)%> + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, false)%> public void set<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; }*/ -} + if (attribute.getReverseAttribute() == null) { + //Pas de navigabilité => on veut tout de même l'attribut opposé +/*{ + <%=generateMethodInfo(MethodType.FIELD_ACCESSOR, true, attribute, false, true)%> + public void set_attribute_B_(TopiaEntity value) throws TopiaException; +}*/ + + } + } ////////////////////////////////////////////////////////////////////// // O P E R A T I O N @@ -298,7 +344,7 @@ /** <%=operation.getDocumentation()%> *) - <%=generateMethodInfo(MethodType.OPERATION, false, null, false)%> + <%=generateMethodInfo(MethodType.OPERATION, false, null, false, false)%> <%=operation.getVisibility()%> <%=operation.getReturnType()%> <%=operation.getName()%> (<%=Util.getMethodParameterDeclaration(operation.getParameters())%>) throws TopiaException}*/ }