Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.5 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.6 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.5 Wed Apr 27 14:39:50 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java Fri Jun 10 08:21:57 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Mise a jour: $Date: 2005/04/27 14:39:50 $ + * Mise a jour: $Date: 2005/06/10 08:21:57 $ * par : $Author: thimel $ */ @@ -78,12 +78,12 @@ if (!Util.isEntity(interfacezz)) { /*{<%=interfacezz.getPackageName() + "."%>}*/ } -/*{<%=interfacezz.getName()%> }*/ +/*{<%=interfacezz.getQualifiedName()%> }*/ } if(clazz instanceof ObjectModelClass){ for (Iterator i=((ObjectModelClass)clazz).getSuperclasses().iterator(); i.hasNext();) { ObjectModelClass superclass = (ObjectModelClass) i.next(); - /*{, <%=superclass.getName()%>}*/ + /*{, <%=superclass.getQualifiedName()%>}*/ } } } @@ -95,47 +95,105 @@ public void generateGetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ + public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; }*/ + if (attribute.hasAssociationClass()) { +/*{ + + public <%=attribute.getAssociationClass().getQualifiedName()%> get<%=attribute.getAssociationClass().getName()%>() throws TopiaException; +}*/ + } } public void generateGetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ + /** * @return an unmodifiable collection *) public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; + + public int sizeOf<%=Util.capitalize(attribute.getName())%>() throws TopiaException; + + public Iterator iteratorOn<%=Util.capitalize(attribute.getName())%>() throws TopiaException; + + public boolean containsIn<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; + + public boolean containsAllIn<%=Util.capitalize(attribute.getName())%>(java.util.Collection values) throws TopiaException; + + public <%=attribute.getType()%> get<%=Util.capitalize(attribute.getName())%>(int index) throws TopiaException; }*/ } + public void generateGetAssociationAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + public <%=attribute.getType()%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; +}*/ + } + + ////////////////////////////////////////////////////////////////////// // S E T A T T R I B U T E S A C C E S S O R S ////////////////////////////////////////////////////////////////////// public void generateSetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { + if (!attribute.hasAssociationClass()) { /*{ public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException; }*/ + } else { +/*{ + public void set<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException; + + public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value, <%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException; +}*/ + } } public void generateSetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ - public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; + public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getType()%> value) throws TopiaException; public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; public void clear<%=Util.capitalize(attribute.getName())%>() throws TopiaException; +}*/ + if (!attribute.hasAssociationClass()) { +/*{ + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; - public void add<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> list) throws TopiaException; + public void add<%=Util.capitalize(attribute.getName())%>(/*<%=Util.getAttributeType(attribute)%>*)java.util.Collection list) throws TopiaException; - public void add<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> list, boolean duplicate) throws TopiaException; + public void add<%=Util.capitalize(attribute.getName())%>(/*<%=Util.getAttributeType(attribute)%>*)java.util.Collection list, boolean duplicate) throws TopiaException; +}*/ + } else { +/*{ + public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException; + + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value, <%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException; + + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException; + + public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException; }*/ + } + } + + public void generateSetAssociationAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + public void set<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; +}*/ +} + ////////////////////////////////////////////////////////////////////// // O P E R A T I O N ////////////////////////////////////////////////////////////////////// @@ -188,7 +246,7 @@ /** * Delete this entity with its persistenceService *) - public void remove() throws TopiaException; + //public void remove() throws TopiaException; }*/ } Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.11 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.12 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.11 Fri May 20 17:58:59 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java Fri Jun 10 08:21:57 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.11 $ + * @version $Revision: 1.12 $ * - * Mise a jour: $Date: 2005/05/20 17:58:59 $ + * Mise a jour: $Date: 2005/06/10 08:21:57 $ * par : $Author: thimel $ */ @@ -34,9 +34,11 @@ import java.io.File; import java.io.IOException; import java.io.Writer; +import java.util.Collections; 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; @@ -65,7 +67,6 @@ ////////////////////////////////////////////////////////////////////// // C L A S S D E C L A R A T I O N ////////////////////////////////////////////////////////////////////// - public void generateClassDeclaration(Writer output, ObjectModelClassifier clazzifier) throws IOException { ObjectModelClass clazz = (ObjectModelClass)clazzifier; /*{ @@ -76,7 +77,7 @@ Iterator i = clazz.getSuperclasses().iterator(); if (i.hasNext()) { ObjectModelClass superclass = (ObjectModelClass) i.next(); -/*{ extends <%=superclass.getName() + "Impl"%>}*/ +/*{ extends <%=superclass.getQualifiedName() + "Impl"%>}*/ } else { /*{ extends AbstractTopiaEntity}*/ } @@ -90,11 +91,54 @@ public void generateNormalAttributeDeclaration(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ + ////////////////////////////////////////////////////////////////////// + // Attribute <%=attribute.getName()%> + ////////////////////////////////////////////////////////////////////// +}*/ + if (attribute.hasAssociationClass() && !Util.isNMultiplicity(attribute)) { + //On remplace le type de l'élément par la classe d'association. +/*{ + private <%=attribute.getAssociationClass().getQualifiedName()%> <%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; +}*/ + } else { +/*{ private <%=Util.getAttributeType(attribute)%> <%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; - protected boolean _<%=attribute.getName()%>Modified_ = false; }*/ + } +/*{ protected boolean _<%=attribute.getName()%>Modified_ = false; +}*/ + if (!Util.isBasicAttributeType(attribute)) { + int index; + String order = ""; + if (attribute.getReverseAttribute() != null) { +/*{ //<%=attribute.getName() + "/" + attribute.getReverseAttribute().getName() + " : " + attribute.getName().compareTo(attribute.getReverseAttribute().getName())%> +}*/ + if (attribute.getName().compareTo(attribute.getReverseAttribute().getName()) < 0) { + //Attribut + petit donc l'objet courant (+ grd) passe en dernier => 1 + index = 1; + order = attribute.getType() + Util.capitalize(attribute.getName()) + ((ObjectModelClass)attribute.getDeclaringElement()).getQualifiedName() + Util.capitalize(attribute.getReverseAttribute().getName()); + } else { + index = 0; + order = ((ObjectModelClass)attribute.getDeclaringElement()).getQualifiedName() + Util.capitalize(attribute.getReverseAttribute().getName()) + attribute.getType() + Util.capitalize(attribute.getName()); + } + } else { + index = 0; + order = attribute.getType() + Util.capitalize(attribute.getName()); + } +System.out.println(order + " : " + index); +/*{ protected int index<%=Util.capitalize(attribute.getName())%> = <%=index%>; + protected String nameFor<%=Util.capitalize(attribute.getName())%> = "<%=order%>"; +}*/ + } } + public void generateAssociationAttributeDeclaration(Writer output, ObjectModelAttribute attribute) throws IOException { +/*{ + private <%=attribute.getType()%> <%=attribute.getName()%> = null; + protected boolean _<%=attribute.getName()%>Modified_ = false; +}*/ + } + ////////////////////////////////////////////////////////////////////// // G E T A T T R I B U T E S A C C E S S O R S ////////////////////////////////////////////////////////////////////// @@ -109,16 +153,32 @@ public void generateGetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException { -}*/ if ("false".equals(getProperty("security.skip"))){ +}*/ + if (doSecurity()) { /*{ TopiaAccessController.checkPermission(this, "read"); }*/ - } + } + if (attribute.hasAssociationClass()) { +/*{ return (<%=attribute.getName()%> == null) ? null : <%=attribute.getName()%>.get<%=Util.capitalize(attribute.getName())%>(); +}*/ + } else { /*{ return <%=attribute.getName()%>; - } - public boolean is_<%=attribute.getName()%>Modified_(){ +}*/ + } +/*{ } + + public boolean is_<%=attribute.getName()%>Modified_() { return this._<%=attribute.getName()%>Modified_; } }*/ + + if (attribute.hasAssociationClass()) { +/*{ + public <%=attribute.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(attribute.getAssociationClass().getName())%>() throws TopiaException { + return <%=attribute.getName()%>; + } +}*/ + } } public void generateGetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) @@ -128,18 +188,113 @@ * @return an unmodifiable collection *) public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException { -}*/ if (!"false".equals(getProperty("security.skip"))){ +}*/ + if (doSecurity()) { /*{ TopiaAccessController.checkPermission(this, "read"); }*/ + } + if (attribute.hasAssociationClass()) { +/*{ List list = new ArrayList(); + for (Iterator it = <%=attribute.getName()%>.iterator(); it.hasNext(); ) + list.add(((<%=attribute.getAssociationClass().getQualifiedName()%>)it.next()).get<%=Util.capitalize(attribute.getName())%>()); + List result = <%=Util.getInitValue(attribute)%>; + result.add(list); + return Collections.unmodifiableList(result); +}*/ + } else { +/*{ return Collections.unmodifiableList(<%=attribute.getName()%>); +}*/ + } +/*{ } + + public boolean is_<%=attribute.getName()%>Modified_() { + return this._<%=attribute.getName()%>Modified_; } -/*{ return Collections.unmodifiableCollection(<%=attribute.getName()%>); + + public int sizeOf<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + return <%=attribute.getName()%>.size();}*/ + /*Peut être optimisé en évitant de charger l'objet si ce n'est pas le cas*/ /*{ } - public boolean is_<%=attribute.getName()%>Modified_(){ - return this._<%=attribute.getName()%>Modified_; + + public Iterator iteratorOn<%=Util.capitalize(attribute.getName())%>() throws TopiaException { +}*/ + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "read"); +}*/ + } + if (attribute.hasAssociationClass()) { +/*{ return get<%=Util.capitalize(attribute.getName())%>().iterator(); +}*/ + } else { +/*{ return <%=attribute.getName()%>.iterator(); +}*/ + } +/*{ } + + public boolean containsIn<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { +}*/ + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "read"); +}*/ + } + if (attribute.hasAssociationClass()) { +/*{ return get<%=Util.capitalize(attribute.getName())%>().contains(value); +}*/ + } else { +/*{ return <%=attribute.getName()%>.contains(value); +}*/ + } +/*{ } + + public boolean containsAllIn<%=Util.capitalize(attribute.getName())%>(java.util.Collection values) throws TopiaException { +}*/ + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "read"); +}*/ + } + if (attribute.hasAssociationClass()) { +/*{ return get<%=Util.capitalize(attribute.getName())%>().containsAll(values); +}*/ + } else { +/*{ return <%=attribute.getName()%>.containsAll(values); +}*/ + } +/*{ } + + public <%=attribute.getType()%> get<%=Util.capitalize(attribute.getName())%>(int index) throws TopiaException { +}*/ + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "read"); +}*/ + } + if (attribute.hasAssociationClass()) { +/*{ return ((<%=attribute.getAssociationClass().getQualifiedName()%>)<%=attribute.getName()%>.get(index)).get<%=Util.capitalize(attribute.getName())%>(); +}*/ + } else { +/*{ return (<%=attribute.getType()%>)<%=attribute.getName()%>.get(index); +}*/ + } +/*{ } +}*/ } + + public void generateGetAssociationAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { +/*{ + public <%=attribute.getType()%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException { }*/ + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "read"); +}*/ + } +/*{ return <%=attribute.getName()%>; } + public boolean is_<%=attribute.getName()%>Modified_() { + return this._<%=attribute.getName()%>Modified_; + } +}*/ + } + ////////////////////////////////////////////////////////////////////// // S E T A T T R I B U T E S A C C E S S O R S ////////////////////////////////////////////////////////////////////// @@ -154,61 +309,182 @@ public void generateSetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { + if (!attribute.hasAssociationClass()) { /*{ public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException { -}*/ if (!"false".equals(getProperty("security.skip"))){ +}*/ + if (doSecurity()) { /*{ TopiaAccessController.checkPermission(this, "write"); }*/ + }//TODO Changement 1 => 0..1 trop laxiste + if (!Util.isBasicAttributeType(attribute) && Util.is1Multiplicity(attribute)) + if (!Util.is1Multiplicity(attribute.getReverseAttribute())) { // Si c'est une association 1-1, on la considère comme une association 0..1 - 0..1 +/*{ if (value == null) + throw new TopiaException("Cannot set <%=attribute.getName()%> to null - Multiplicity 1"); +}*/ + } else { +/*{ //Multiplicity 1 changed to 0..1 because of 1-1 relation +}*/ + } + if (attribute.isComposite()) { +/*{ _dependentEntities.remove(this.<%=attribute.getName()%>); + _dependentEntities.add(value); +}*/ + } + if (attribute.getReverseAttribute() != null) + if(Util.isNMultiplicity(attribute.getReverseAttribute())) { +/*{ this.<%=attribute.getName()%>.remove<%=Util.capitalize(attribute.getReverseAttribute().getName())%>(this); + if (!value.containsIn<%=Util.capitalize(attribute.getReverseAttribute().getName())%>(this)) + value.add<%=Util.capitalize(attribute.getReverseAttribute().getName())%>(this); +}*/ + } else { +/*{ this.<%=attribute.getName()%>.set<%=Util.capitalize(attribute.getReverseAttribute().getName())%>(null); + if (!this.equals(value.get<%=Util.capitalize(attribute.getReverseAttribute().getName())%>())) + value.set<%=Util.capitalize(attribute.getReverseAttribute().getName())%>(this); +}*/ + } +/*{ this.<%=attribute.getName()%> = value; + this._<%=attribute.getName()%>Modified_ = true; } -/*{ this._<%=attribute.getName()%>Modified_ = true; - this.<%=attribute.getName()%> = value; +}*/ + } else { +/*{ + public void set<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException { + set<%=Util.capitalize(attribute.getName())%>(null, association); } + + public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value, <%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException { }*/ + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "write"); +}*/ + } +/*{ if (association != null) { +}*/ + if (attribute.getReverseAttribute() != null) { +/*{ association.set<%=Util.capitalize(attribute.getReverseAttribute().getName())%>(this); +}*/ + } +/*{ if (value != null) + association.set<%=Util.capitalize(attribute.getName())%>(value); + } + this.<%=attribute.getName()%> = association; + this._<%=attribute.getName()%>Modified_ = true; + } +}*/ + } } public void generateSetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { + if (attribute.hasAssociationClass()) { /*{ - public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { -}*/ if (!"false".equals(getProperty("security.skip"))){ + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value, <%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException { +}*/ + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "write"); +}*/ + } + if (attribute.getReverseAttribute() != null) { +/*{ association.set<%=Util.capitalize(attribute.getReverseAttribute().getName())%>(this); +}*/ + } +/*{ association.set<%=Util.capitalize(attribute.getName())%>(value); + this.<%=attribute.getName()%>.add(association); + this._<%=attribute.getName()%>Modified_ = true; + } + + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException { +}*/ + if (doSecurity()) { /*{ TopiaAccessController.checkPermission(this, "write"); }*/ + } +/*{ this.<%=attribute.getName()%>.add(association); + this._<%=attribute.getName()%>Modified_ = true; } +}*/ + } else { +/*{ + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { +}*/ + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "write"); +}*/ + } + if (attribute.isComposite()) { +/*{ _dependentEntities.add(value); +}*/ + } /*{ this._<%=attribute.getName()%>Modified_ = true; this.<%=attribute.getName()%>.add(value); } - +}*/ + } + +/*{ public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { -}*/ if (!"false".equals(getProperty("security.skip"))){ +}*/ + if (attribute.hasAssociationClass()) { + if (doSecurity()) { /*{ TopiaAccessController.checkPermission(this, "write"); }*/ - } + } +/*{ if (value == null) + return; + for (Iterator i = this.<%=attribute.getName()%>.iterator(); i.hasNext(); ) { + <%=attribute.getAssociationClass().getQualifiedName()%> item = (<%=attribute.getAssociationClass().getQualifiedName()%>)i.next(); + if (value.equals(item.get<%=Util.capitalize(attribute.getName())%>())) { + this.<%=attribute.getName()%>.remove(item); + this._<%=attribute.getName()%>Modified_ = true; + return; + } + } + } + + public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException { +}*/ + } + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "write"); +}*/ + } + if (attribute.isComposite()) { +/*{ _dependentEntities.remove(value); +}*/ + } /*{ this._<%=attribute.getName()%>Modified_ = true; this.<%=attribute.getName()%>.remove(value); } public void clear<%=Util.capitalize(attribute.getName())%>() throws TopiaException { -}*/ if (!"false".equals(getProperty("security.skip"))){ -/*{ TopiaAccessController.checkPermission(this, "write"); }*/ - } + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "write"); +}*/ + } + if (attribute.isComposite()) { +/*{ for (Iterator it = this.<%=attribute.getName()%>.iterator(); it.hasNext(); ) + _dependentEntities.remove(it.next()); +}*/ + } /*{ this._<%=attribute.getName()%>Modified_ = true; this.<%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; } - - public void add<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> list) throws TopiaException{ -}*/ if (!"false".equals(getProperty("security.skip"))){ -/*{ TopiaAccessController.checkPermission(this, "write"); }*/ - } -/*{ add<%=Util.capitalize(attribute.getName())%>(list, false); + if (!attribute.hasAssociationClass()) { +/*{ + //Pas de controle de sécurité car appel à add<%=Util.capitalize(attribute.getName())%>(List, boolean) où il y a controle, et donc ca fait doublon sinon ! + public void add<%=Util.capitalize(attribute.getName())%>(/*<%=Util.getAttributeType(attribute)%>*)java.util.Collection list) throws TopiaException { + add<%=Util.capitalize(attribute.getName())%>(list, false); } - public void add<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> list, boolean duplicate) throws TopiaException{ -}*/ if (!"false".equals(getProperty("security.skip"))){ + public void add<%=Util.capitalize(attribute.getName())%>(/*<%=Util.getAttributeType(attribute)%>*)java.util.Collection list, boolean duplicate) throws TopiaException { +}*/ + if (doSecurity()) { /*{ TopiaAccessController.checkPermission(this, "write"); }*/ - } + } /*{ if(!duplicate){ java.util.ArrayList listClone = new java.util.ArrayList(); listClone.addAll(list); @@ -217,10 +493,59 @@ } for(java.util.Iterator i = list.iterator(); i.hasNext();){ <%=attribute.getType()%> value = (<%=attribute.getType()%>)i.next(); - add<%=Util.capitalize(attribute.getName())%>(value); +}*/ + if (attribute.isComposite()) { +/*{ _dependentEntities.add(value); +}*/ + } +/*{ add<%=Util.capitalize(attribute.getName())%>(value); } } }*/ + } +/*{ + public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getType()%> value) throws TopiaException { +}*/ + if (attribute.hasAssociationClass()) { + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "write"); +}*/ + } +/*{ ((<%=attribute.getAssociationClass().getQualifiedName()%>)<%=attribute.getName()%>.get(index)).set<%=Util.capitalize(attribute.getName())%>(value); + this._<%=attribute.getName()%>Modified_ = true; + } + + public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException { +}*/ + } + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "write"); +}*/ + } + if (attribute.isComposite()) { +/*{ _dependentEntities.remove(<%=attribute.getName()%>.get(index)); + _dependentEntities.add(value); +}*/ + } +/*{ <%=attribute.getName()%>.set(index, value); + this._<%=attribute.getName()%>Modified_ = true; + } +}*/ + } + + public void generateSetAssociationAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + public void set<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { +}*/ + if (doSecurity()) { +/*{ TopiaAccessController.checkPermission(this, "write"); +}*/ + } +/*{ this._<%=attribute.getName()%>Modified_ = true; + this.<%=attribute.getName()%> = value; + } +}*/ } ////////////////////////////////////////////////////////////////////// @@ -265,6 +590,8 @@ public void remove() throws TopiaException{ <%=clazz.getName()%>PersistenceService persistenceService = getPersistenceService(); persistenceService.delete(this); + for (Iterator i = _dependentEntities.iterator(); i.hasNext(); ) + ((TopiaEntity)i.next()).remove(); } }*/ } @@ -274,10 +601,14 @@ ////////////////////////////////////////////////////////////////////// public void generateOther(Writer output, ObjectModelClassifier clazzifier) throws IOException { - generateSetAllFrameworkProperties(output, (ObjectModelClass)clazzifier); /*{ - + ////////////////////////////////////////////////////////////////////// + // Other framework methods + ////////////////////////////////////////////////////////////////////// +}*/ + generateSetAllFrameworkProperties(output, (ObjectModelClass)clazzifier); +/*{ public <%=clazzifier.getName()%>Impl()throws TopiaException { } @@ -317,7 +648,6 @@ *) public String toString(){ }*/ - //TODO Arno : Faut-il restreindre ca ??? /*{ return <%=getProperty("defaultPackage")%>.<%=model.getName()%>EntitiesHelper.toString(this); } @@ -329,7 +659,7 @@ } }*/ - if(clazzifier instanceof ObjectModelClass){ + if(clazzifier instanceof ObjectModelClass) { ObjectModelClass clazz = (ObjectModelClass)clazzifier; /*{ /** @@ -351,10 +681,11 @@ * Les modifications s'effectue au travers des methodes set. *) public void set_allProperties_(TopiaEntity topiaEntity) throws TopiaException { -}*/ if (!"false".equals(getProperty("security.skip"))){ +}*/ + if (doSecurity()) { /*{ TopiaAccessController.checkPermission(this, "write"); }*/ - } + } /*{ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)topiaEntity; }*/ if(clazz.getSuperclasses().size() != 0){ @@ -374,10 +705,16 @@ // Iterate on each attribute for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if(! Util.isDerived(attribute)){ + if(! Util.isDerived(attribute)) { + if (attribute.hasAssociationClass() && !Util.isNMultiplicity(attribute)) { +/*{//TODO + this.<%=attribute.getName()%> = entity.get<%=Util.capitalize(attribute.getAssociationClass().getName())%>(); +}*/ + } else { /*{ this.<%=attribute.getName()%> = entity.get<%=Util.capitalize(attribute.getName())%>(); }*/ + } } } /*{ Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationGenerator.java:1.3 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationGenerator.java:1.4 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationGenerator.java:1.3 Wed Apr 27 14:39:50 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationGenerator.java Fri Jun 10 08:21:57 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Mise a jour: $Date: 2005/04/27 14:39:50 $ + * Mise a jour: $Date: 2005/06/10 08:21:57 $ * par : $Author: thimel $ */ @@ -76,13 +76,13 @@ for (Iterator i = clazz.getInterfaces().iterator(); i.hasNext();) { ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); if (Util.isEntity(interfacezz)) { -/*{, <%=interfacezz.getName()%>Operation }*/ +/*{, <%=interfacezz.getQualifiedName()%>Operation }*/ } } if(clazz instanceof ObjectModelClass){ for (Iterator i=((ObjectModelClass)clazz).getSuperclasses().iterator(); i.hasNext();) { ObjectModelClass superclass = (ObjectModelClass) i.next(); - /*{, <%=superclass.getName()%>Operation}*/ + /*{, <%=superclass.getQualifiedName()%>Operation}*/ } } } Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationRouterGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationRouterGenerator.java:1.3 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationRouterGenerator.java:1.4 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationRouterGenerator.java:1.3 Fri Aug 6 17:48:52 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationRouterGenerator.java Fri Jun 10 08:21:57 2005 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Mise a jour: $Date: 2004/08/06 17:48:52 $ - * par : $Author: bpoussin $ + * Mise a jour: $Date: 2005/06/10 08:21:57 $ + * par : $Author: thimel $ */ package org.codelutin.topia.generators; @@ -77,7 +77,7 @@ Iterator i = clazz.getSuperclasses().iterator(); if (i.hasNext()) { ObjectModelClass superclass = (ObjectModelClass) i.next(); -/*{ extends <%=superclass.getName() + "OperationRouter"%>}*/ +/*{ extends <%=superclass.getQualifiedName() + "OperationRouter"%>}*/ } else { /*{ extends AbstractTopiaElement}*/ } Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java:1.9 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java:1.10 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java:1.9 Thu May 26 14:19:28 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java Fri Jun 10 08:21:57 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.9 $ + * @version $Revision: 1.10 $ * - * Mise a jour: $Date: 2005/05/26 14:19:28 $ + * Mise a jour: $Date: 2005/06/10 08:21:57 $ * par : $Author: thimel $ */ @@ -76,13 +76,13 @@ for (Iterator i = clazz.getInterfaces().iterator(); i.hasNext();) { ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); if (Util.isEntity(interfacezz)) { -/*{, <%=interfacezz.getName()%>PersistenceService }*/ +/*{, <%=interfacezz.getQualifiedName()%>PersistenceService }*/ } } if(clazz instanceof ObjectModelClass){ for (Iterator i=((ObjectModelClass)clazz).getSuperclasses().iterator(); i.hasNext();) { ObjectModelClass superclass = (ObjectModelClass) i.next(); -/*{, <%=superclass.getName()%>PersistenceService}*/ +/*{, <%=superclass.getQualifiedName()%>PersistenceService}*/ } } } Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java:1.8 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java:1.9 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java:1.8 Thu May 26 14:19:28 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java Fri Jun 10 08:21:57 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * - * Mise a jour: $Date: 2005/05/26 14:19:28 $ + * Mise a jour: $Date: 2005/06/10 08:21:57 $ * par : $Author: thimel $ */ @@ -83,7 +83,7 @@ Iterator i=((ObjectModelClass)clazz).getSuperclasses().iterator(); if (i.hasNext()) { ObjectModelClass superclass = (ObjectModelClass) i.next(); - /*{<%=superclass.getName()%>PersistenceServiceImpl}*/ + /*{<%=superclass.getQualifiedName()%>PersistenceServiceImpl}*/ }else{ /*{AbstractTopiaPersistenceService}*/ } Index: topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.5 topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.6 --- topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.5 Wed May 4 16:09:41 2005 +++ topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java Fri Jun 10 08:21:57 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Mise a jour: $Date: 2005/05/04 16:09:41 $ + * Mise a jour: $Date: 2005/06/10 08:21:57 $ * par : $Author: thimel $ */ @@ -38,6 +38,7 @@ import org.codelutin.generator.Generator; import org.codelutin.generator.ObjectModelGenerator; +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; @@ -59,6 +60,10 @@ */ abstract public boolean accept(ObjectModelClassifier clazz); + public boolean doSecurity() { + return (!"false".equals(getProperty("security.skip"))); + } + public String getFilenameForClassifier(ObjectModelClassifier clazz){ return clazz.getQualifiedName().replace('.', File.separatorChar); } @@ -67,7 +72,7 @@ // Consider only entities, return immediately if not an entity if (! accept(clazz)) return; - + // ------------- File Header generatePackageStatement(output, clazz); @@ -78,6 +83,17 @@ generateClassDeclaration(output, clazz); /*{ { }*/ + if (clazz instanceof ObjectModelAssociationClass) { + ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz; + for (Iterator i = assoc.getParticipantsAttributes().iterator(); i.hasNext(); ) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + if (attribute != null) { + generateAssociationAttributeDeclaration(output, attribute); + generateGetAssociationAttributeAccessor(output, attribute); + generateSetAssociationAttributeAccessor(output, attribute); + } + } + } if(clazz instanceof ObjectModelClass){ // ------------- Attributes @@ -129,7 +145,7 @@ // P A C K A G E ////////////////////////////////////////////////////////////////////// - /** + /** * Il faut absolument que les classes soit dans un package, sinon * il faut revoir la modelisation :) */ @@ -244,6 +260,7 @@ } } + /** * For derived (calculated) attribute. Generate nothing */ @@ -268,6 +285,15 @@ } /** + * @param output + * @param attribute + */ + public void generateAssociationAttributeDeclaration(Writer output, ObjectModelAttribute attribute) + throws IOException { + generateNormalAttributeDeclaration(output, attribute); + } + + /** * For entity attribute with 0/1 cardinality. By default call * {@link #generateNormalAttributeDeclaration} */ @@ -334,6 +360,15 @@ } /** + * @param output + * @param attribute + */ + public void generateGetAssociationAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + generateGetNormalAttributeAccessor(output, attribute); + } + + /** * For entity attribute with 0/1 cardinality. By default call * {@link #generateNormalAttributeDeclaration} */ @@ -398,6 +433,15 @@ */ public void generateSetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { + } + + /** + * @param output + * @param attribute + */ + public void generateSetAssociationAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + generateSetNormalAttributeAccessor(output, attribute); } /**