Index: topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.11 topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.12 --- topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.11 Mon Jul 25 08:45:57 2005 +++ topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java Tue Jul 26 14:02: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/07/25 08:45:57 $ + * Mise a jour: $Date: 2005/07/26 14:02:57 $ * par : $Author: thimel $ */ @@ -60,10 +60,6 @@ */ 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); } Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.21 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.22 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.21 Mon Jul 25 08:45:57 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java Tue Jul 26 14:02:57 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.21 $ + * @version $Revision: 1.22 $ * - * Mise a jour: $Date: 2005/07/25 08:45:57 $ + * Mise a jour: $Date: 2005/07/26 14:02:57 $ * par : $Author: thimel $ */ @@ -101,12 +101,7 @@ // currentHashCode += Math.abs(attribute.getType().hashCode()); // currentHashCode += Math.abs(attribute.getName().hashCode()); if (Util.isAttributeEntity(attribute)) { -/*{ //On ne génère pas de méthode d'accès, on utilisera le TopiaAssociationManager -}*/ - }/* else*/ 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)%>; +/*{ //On ne génère pas d'attribut, on utilisera le TopiaAssociationManager }*/ } else { /*{ @@ -115,9 +110,9 @@ } /*{ protected boolean _<%=attribute.getName()%>Modified_ = false; }*/ - //On calcule le nom de l'association stockée dans order (puis dans nameFor<%=Util.capitalize(attribute.getName())%>) - //De plus, on enregistre dans index<%=Util.capitalize(attribute.getName())%> si l'objet courant est le premier(0) objet de la relation ou le second(1) - if (/*!Util.isPrimitiveAttributeType(attribute)*/Util.isAttributeEntity(attribute)) { + //On calcule le nom de l'association stockée dans order (puis dans _nameFor<%=Util.capitalize(attribute.getName())%>_) + //De plus, on enregistre dans _indexFor<%=Util.capitalize(attribute.getName())%>_ si l'objet courant est le premier(0) objet de la relation ou le second(1) + if (Util.isAttributeEntity(attribute)) { int index; String order = ""; if (attribute.getReverseAttribute() != null) { @@ -133,8 +128,8 @@ index = 0; order = attribute.getType() + "-" + attribute.getName(); } -/*{ protected int index<%=Util.capitalize(attribute.getName())%> = <%=index%>; - protected String nameFor<%=Util.capitalize(attribute.getName())%> = "<%=order%>"; +/*{ protected int _indexFor<%=Util.capitalize(attribute.getName())%>_ = <%=index%>; + protected String _nameFor<%=Util.capitalize(attribute.getName())%>_ = "<%=order%>"; }*/ } } @@ -160,16 +155,13 @@ public void generateGetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + TopiaAccessController.checkPermission(this, "read"); }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "read"); -}*/ - } - //if (Util.isAttributeEntity(attribute)) { //TODO Arno !!! -/*{ //return (<%=attribute.getType()%>)getContext().getAssociationManager().getFirstOppositeObjectForPosition(nameFor<%=Util.capitalize(attribute.getName())%>, this, index<%=Util.capitalize(attribute.getName())%>); -}*/ - /*} else*/ if (attribute.hasAssociationClass()) { -/*{ return (<%=attribute.getName()%> == null) ? null : <%=attribute.getName()%>.get<%=Util.capitalize(attribute.getName())%>(); + if (Util.isAttributeEntity(attribute)) { +/*{ <%=Util.getAssociationClassName(attribute)%> classAssoc = (<%=Util.getAssociationClassName(attribute)%>)getContext().getAssociationManager().getAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_); + if (classAssoc == null) + return null; + return classAssoc.get<%=Util.capitalize(attribute.getName())%>(); }*/ } else { /*{ return <%=attribute.getName()%>; @@ -185,7 +177,7 @@ if (attribute.hasAssociationClass()) { /*{ public <%=attribute.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(attribute.getAssociationClass().getName())%>() throws TopiaException { - return <%=attribute.getName()%>; + return (<%=attribute.getAssociationClass().getQualifiedName()%>)getContext().getAssociationManager().getAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_); } }*/ } @@ -198,17 +190,14 @@ * @return an unmodifiable collection *) public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + TopiaAccessController.checkPermission(this, "read"); }*/ - 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())%>()); + if (Util.isAttributeEntity(attribute)) { +/*{ List list = new ArrayList(); + for (Iterator it = getContext().getAssociationManager().getAssociationClasses(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_).iterator(); it.hasNext(); ) + list.add(((<%=Util.getAssociationClassName(attribute)%>)it.next()).get<%=Util.capitalize(attribute.getName())%>()); List result = <%=Util.getInitValue(attribute)%>; - result.addAll(list); + result.addAll(list); }*/ /*On ajoute tout d'un coup pour ne pas violer les contraintes de multiplicité*/ /*{ return Collections.unmodifiableList(result); }*/ } else { @@ -222,17 +211,20 @@ } 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 Iterator iteratorOn<%=Util.capitalize(attribute.getName())%>() throws TopiaException { }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "read"); + if (Util.isAttributeEntity(attribute)) { +/*{ return getContext().getAssociationManager().numberInPosition(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_); +}*/ + } else { +/*{ return <%=attribute.getName()%>.size(); }*/ } - if (attribute.hasAssociationClass()) { +/*{ } + + public Iterator iteratorOn<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + TopiaAccessController.checkPermission(this, "read"); +}*/ + if (Util.isAttributeEntity(attribute)) { /*{ return get<%=Util.capitalize(attribute.getName())%>().iterator(); }*/ } else { @@ -242,12 +234,9 @@ /*{ } public boolean containsIn<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { + TopiaAccessController.checkPermission(this, "read"); }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "read"); -}*/ - } - if (attribute.hasAssociationClass()) { + if (Util.isAttributeEntity(attribute)) { /*{ return get<%=Util.capitalize(attribute.getName())%>().contains(value); }*/ } else { @@ -257,12 +246,9 @@ /*{ } public boolean containsAllIn<%=Util.capitalize(attribute.getName())%>(java.util.Collection values) throws TopiaException { + TopiaAccessController.checkPermission(this, "read"); }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "read"); -}*/ - } - if (attribute.hasAssociationClass()) { + if (Util.isAttributeEntity(attribute)) { /*{ return get<%=Util.capitalize(attribute.getName())%>().containsAll(values); }*/ } else { @@ -272,13 +258,10 @@ /*{ } public <%=attribute.getType()%> get<%=Util.capitalize(attribute.getName())%>(int index) throws TopiaException { + TopiaAccessController.checkPermission(this, "read"); }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "read"); -}*/ - } - if (attribute.hasAssociationClass()) { -/*{ return ((<%=attribute.getAssociationClass().getQualifiedName()%>)<%=attribute.getName()%>.get(index)).get<%=Util.capitalize(attribute.getName())%>(); + if (Util.isAttributeEntity(attribute)) { +/*{ return ((<%=Util.getAssociationClassName(attribute)%>)getContext().getAssociationManager().getAssociationClassForIndex(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_, index)).get<%=Util.capitalize(attribute.getName())%>(); }*/ } else { /*{ return (<%=attribute.getType()%>)<%=attribute.getName()%>.get(index); @@ -291,12 +274,8 @@ 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()%>; + TopiaAccessController.checkPermission(this, "read"); + return <%=attribute.getName()%>; } public boolean is_<%=attribute.getName()%>Modified_() { @@ -319,14 +298,11 @@ public void generateSetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { - if (!attribute.hasAssociationClass()) { + if (/*!attribute.hasAssociationClass()*/!Util.isAttributeEntity(attribute)) { /*{ public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException { + TopiaAccessController.checkPermission(this, "write"); }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "write"); -}*/ - } if (!Util.isPrimitiveAttributeType(attribute) && Util.isOneMultiplicity(attribute)) if (attribute.isComposite()) { //TODO Pas adapté au composite !!!! @@ -347,70 +323,104 @@ } }*/ } else { + if (!attribute.hasAssociationClass()) { +/*{ public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) { + <%=Util.getAssociationClassName(attribute)%> oldAssocClass = (<%=Util.getAssociationClassName(attribute)%>)getContext().getAssociationManager().getAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_); + <%=Util.getAssociationClassName(attribute)%> newAssocClass = ((oldAssocClass == null) ? new <%=Util.getAssociationClassName(attribute)%>() : oldAssocClass.clone()); + if (newAssocClass != null) { + newAssocClass.set<%=Util.capitalize(attribute.getName())%>(value); +}*/ + if (attribute.getReverseAttribute() != null) { +/*{ newAssocClass.set<%=Util.capitalize(attribute.getReverseAttribute().getName())%>(this); +}*/ + } +/*{ } + getContext().getAssociationManager().removeAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_); + if (value != null) + getContext().getAssociationManager().addAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_, newAssocClass, value); + this._<%=attribute.getName()%>Modified_ = true; + } +}*/ + } else { /*{ + /** + * Replaces the current association class + *) public void set<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException { set<%=Util.capitalize(attribute.getName())%>(null, association); } + /** + * Replaces the current association class and set the given value + *) public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value, <%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException { + TopiaAccessController.checkPermission(this, "write"); + if (association != null) { + association.set<%=Util.capitalize(attribute.getName())%>(value); }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "write"); -}*/ - } -/*{ if (association != null) { -}*/ - if (attribute.getReverseAttribute() != 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; + } +/*{ } + getContext().getAssociationManager().removeAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_); + if (value != null) + getContext().getAssociationManager().addAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_, association, value); this._<%=attribute.getName()%>Modified_ = true; } }*/ + } } } public void generateSetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { - if (attribute.hasAssociationClass()) { + if (Util.isAttributeEntity(attribute)) { + if (!attribute.hasAssociationClass()) { /*{ - public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value, <%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException { + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { + TopiaAccessController.checkPermission(this, "write"); + <%=Util.getAssociationClassName(attribute)%> association = new <%=Util.getAssociationClassName(attribute)%>(); + association.set<%=Util.capitalize(attribute.getName())%>(value); }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "write"); + if (attribute.getReverseAttribute() != null) { +/*{ association.set<%=Util.capitalize(attribute.getReverseAttribute().getName())%>(this); }*/ - } - if (attribute.getReverseAttribute() != null) { + } +/*{ if (value != null) + getContext().getAssociationManager().addAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_, association, value); + this._<%=attribute.getName()%>Modified_ = true; + } +}*/ + } else { +/*{ + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value, <%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException { + 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); + if (value != null) + getContext().getAssociationManager().addAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_, association, value); this._<%=attribute.getName()%>Modified_ = true; } public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException { + TopiaAccessController.checkPermission(this, "write"); }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "write"); -}*/ - } -/*{ this.<%=attribute.getName()%>.add(association); +/*{ if (association.get<%=Util.capitalize(attribute.getName())%> != null) + getContext().getAssociationManager().addAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_, association, association.get<%=Util.capitalize(attribute.getName())%>); this._<%=attribute.getName()%>Modified_ = true; } }*/ + } } else { /*{ public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { + TopiaAccessController.checkPermission(this, "write"); }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "write"); -}*/ - } if (attribute.isComposite()) { /*{ add_dependentEntities_(value); }*/ @@ -421,33 +431,35 @@ }*/ } + if (Util.isAttributeEntity(attribute)) { /*{ public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { -}*/ - if (attribute.hasAssociationClass()) { - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "write"); -}*/ - } -/*{ if (value == null) + 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; - } - } + getContext().getAssociationManager().removeAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_, value); + this._<%=attribute.getName()%>Modified_ = true; } - - public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException { -}*/ - } - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "write"); +}*/ + if (attribute.hasAssociationClass()) { +/// *{ +// public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException { +// TopiaAccessController.checkPermission(this, "write"); +//}* / +// if (attribute.isComposite()) { +/// *{ remove_dependentEntities_(value); +//}* / +// } +/// *{ this._<%=attribute.getName()%>Modified_ = true; +// this.<%=attribute.getName()%>.remove(value); +// } +//}* / + } + } else { +/*{ + public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { + TopiaAccessController.checkPermission(this, "write"); }*/ - } if (attribute.isComposite()) { /*{ remove_dependentEntities_(value); }*/ @@ -455,13 +467,24 @@ /*{ this._<%=attribute.getName()%>Modified_ = true; this.<%=attribute.getName()%>.remove(value); } - +}*/ + } + + if (Util.isAttributeEntity(attribute)) { +/*{ public void clear<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + TopiaAccessController.checkPermission(this, "write"); + getContext().getAssociationManager().removeAllAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_); + this._<%=attribute.getName()%>Modified_ = true; + } }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "write"); + + } else { + +/*{ + public void clear<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + TopiaAccessController.checkPermission(this, "write"); }*/ - } if (attribute.isComposite()) { /*{ for (Iterator it = this.<%=attribute.getName()%>.iterator(); it.hasNext(); ) remove_dependentEntities_((TopiaEntity)it.next()); @@ -471,20 +494,40 @@ this.<%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; } }*/ - if (!attribute.hasAssociationClass()) { + } + + if (!attribute.hasAssociationClass()) { //Si on fait un addAll, on a pas les instances de Classes d'Assoc /*{ //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); } - +}*/ + if (Util.isAttributeEntity(attribute)) { +/*{ public void add<%=Util.capitalize(attribute.getName())%>(/*<%=Util.getAttributeType(attribute)%>*)java.util.Collection list, boolean duplicate) throws TopiaException { + if (duplicate) //FIXME + throw new TopiaException("Duplicate not yet supported because of associationManager"); + Iterator it = list.iterator(); + while (it.hasNext()) { + <%=attribute.getType()%> value = (<%=attribute.getType()%>)it.next(); + <%=Util.getAssociationClassName(attribute)%> association = new <%=Util.getAssociationClassName(attribute)%>(); }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "write"); + if (attribute.getReverseAttribute() != null) { +/*{ association.set<%=Util.capitalize(attribute.getReverseAttribute().getName())%>(this); }*/ - } -/*{ if(!duplicate){ + } +/*{ association.set<%=Util.capitalize(attribute.getName())%>(value); + getContext().getAssociationManager().addAssociationClass(_nameFor<%=Util.capitalize(attribute.getName())%>_, this, _indexFor<%=Util.capitalize(attribute.getName())%>_, association, value); + } + this._<%=attribute.getName()%>Modified_ = true; + } +}*/ + } else { +/*{ + public void add<%=Util.capitalize(attribute.getName())%>(/*<%=Util.getAttributeType(attribute)%>*)java.util.Collection list, boolean duplicate) throws TopiaException { + TopiaAccessController.checkPermission(this, "write"); + if(!duplicate){ java.util.ArrayList listClone = new java.util.ArrayList(); listClone.addAll(list); listClone.removeAll(get<%=Util.capitalize(attribute.getName())%>()); @@ -493,34 +536,21 @@ for(java.util.Iterator i = list.iterator(); i.hasNext();){ <%=attribute.getType()%> value = (<%=attribute.getType()%>)i.next(); }*/ - if (attribute.isComposite()) { + if (attribute.isComposite()) { /*{ add_dependentEntities_(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 (!Util.isAttributeEntity(attribute)) { +/*{ public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException { + TopiaAccessController.checkPermission(this, "write"); }*/ - } if (attribute.isComposite()) { /*{ remove_dependentEntities_((TopiaEntity)<%=attribute.getName()%>.get(index)); add_dependentEntities_(value); @@ -530,17 +560,15 @@ 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 { + TopiaAccessController.checkPermission(this, "write"); }*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "write"); -}*/ - } /*{ this._<%=attribute.getName()%>Modified_ = true; this.<%=attribute.getName()%> = value; } @@ -687,12 +715,8 @@ * Les modifications s'effectue au travers des methodes set. *) public void set_allProperties_(TopiaEntity topiaEntity) throws TopiaException { -}*/ - if (doSecurity()) { -/*{ TopiaAccessController.checkPermission(this, "write"); -}*/ - } -/*{ <%=clazz.getName()%> entity = (<%=clazz.getName()%>)topiaEntity; + TopiaAccessController.checkPermission(this, "write"); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)topiaEntity; }*/ if(clazz.getSuperclasses().size() != 0){ /*{ @@ -712,19 +736,20 @@ for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); if(! Util.isDerived(attribute)) { - if (attribute.hasAssociationClass() && !Util.isNMultiplicity(attribute)) { + if (!Util.isAttributeEntity(attribute)) + if (attribute.hasAssociationClass() && !Util.isNMultiplicity(attribute)) { /*{//TODO this.<%=attribute.getName()%> = entity.get<%=Util.capitalize(attribute.getAssociationClass().getName())%>(); }*/ - } else { + } else { /*{ this.<%=attribute.getName()%> = entity.get<%=Util.capitalize(attribute.getName())%>(); }*/ - } + } } } /*{ - } + } // <%=Util.capitalize(clazz.getName())%> }*/ } Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java:1.4 topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java:1.5 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java:1.4 Tue Jun 21 17:00:43 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java Tue Jul 26 14:02:57 2005 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * - * Mise a jour: $Date: 2005/06/21 17:00:43 $ + * Mise a jour: $Date: 2005/07/26 14:02:57 $ * par : $Author: thimel $ */ @@ -96,6 +96,10 @@ Logger.getLogger(getClass().getName() + ".generate").log(Level.FINE, "Generation de ObjectModelToServiceGenerator"); 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); } Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.9 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.10 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.9 Tue Jul 26 13:52:16 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java Tue Jul 26 14:02: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/07/26 13:52:16 $ + * Mise a jour: $Date: 2005/07/26 14:02:57 $ * par : $Author: thimel $ */ @@ -213,10 +213,13 @@ public void generateSetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { + if (!Util.isAttributeEntity(attribute)) { /*{ <%=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; Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToAssociationClassesGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ObjectModelToAssociationClassesGenerator.java:1.1 --- /dev/null Tue Jul 26 14:03:02 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToAssociationClassesGenerator.java Tue Jul 26 14:02:57 2005 @@ -0,0 +1,156 @@ +package org.codelutin.topia.generators; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Iterator; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.codelutin.generator.MonitorWriter; +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModel; +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.topia.annotation.MethodInfo; +import org.codelutin.topia.annotation.MethodType; + +public class ObjectModelToAssociationClassesGenerator extends + ObjectModelGenerator { + + @Override + public void generate(ObjectModel model, File destDir) throws IOException { + Iterator itClasses = model.getClasses().iterator(); + while (itClasses.hasNext()) { + ObjectModelClass clazz = (ObjectModelClass)itClasses.next(); + if (Util.isEntity(clazz)) { + Iterator itAttributes = clazz.getAttributes().iterator(); + while (itAttributes.hasNext()) { + ObjectModelAttribute attribute = (ObjectModelAttribute)itAttributes.next(); + if (Util.isAttributeEntity(attribute) && !attribute.hasAssociationClass()) { + String filename = Util.getAssociationClassName(attribute).replace('.', File.separatorChar) + ".java"; + File outputFile = getDestinationFile(destDir, filename); + if (getOverwrite() || !isNewerThanSource(outputFile)){ + StringWriter out = new StringWriter(); + MonitorWriter monitorOut = new MonitorWriter(out); + generateAssocClassFromAttribute(monitorOut, attribute); + write(outputFile, monitorOut); + }else{ + Logger.getLogger(getClass().getName() + ".generate").log(Level.FINE, "file "+ outputFile + " is up-to-date"); + } + + } + } + } + } + } + + public void generateClassInfo(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{@ClassInfo( + type = ClassType.ENTITY, + isAssociationClass = true, + isGeneratedClass = true, +}*/ + ObjectModelAttribute attr = attribute; +/*{ associationA = <%=attr.getType()%>.class, + associationAField = "<%=attr.getName()%>", + associationACardinality = {<%=attr.getMinMultiplicity()%>, <%=attr.getMaxMultiplicity()%>}, +}*/// associationAIsComposition = ... /* TODO Arno Vériier si la valeur par défaut correspond */ + if (attribute.getReverseAttribute() != null) { + attr = attribute.getReverseAttribute(); +/*{ associationB = <%=attr.getType()%>.class, + associationBField = "<%=attr.getName()%>", + associationBCardinality = {<%=attr.getMinMultiplicity()%>, <%=attr.getMaxMultiplicity()%>}, +}*/// associationBIsComposition = ... /* TODO Arno Vériier si la valeur par défaut correspond */ + } +//schemaVersion = <%=Util.getSerialVersionUID((ObjectModelClass)clazz)%>L, +/*{ fields = {"<%=attribute.getName()%>"}*/ if (attribute.getReverseAttribute() != null) {/*{, "<%=attribute.getReverseAttribute().getName()%>"}*/}/*{}, + fieldTypes = {<%=attribute.getType()%>.class}*/ if (attribute.getReverseAttribute() != null) {/*{, <%=attribute.getReverseAttribute().getType()%>.class}*/}/*{} +}*/ /* TODO Arno fieldValues = ... A changer si on veut mettre des valeurs par défaut aux attributs */ +/*{) +}*/ +} + + + private void generateAssocClassFromAttribute(Writer output, ObjectModelAttribute attribute) throws IOException { + String assocClassName = Util.getAssociationClassName(attribute).substring(Util.getAssociationClassName(attribute).lastIndexOf('.') +1); +/*{package <%=Util.getAssociationClassName(attribute).substring(0, Util.getAssociationClassName(attribute).lastIndexOf('.'))%>; + +import org.codelutin.topia.annotation.ClassInfo; +import org.codelutin.topia.annotation.ClassType; +import org.codelutin.topia.annotation.MethodInfo; +import org.codelutin.topia.annotation.MethodType; + +}*/ + generateClassInfo(output, attribute); +/*{public class <%=assocClassName%> { +}*/ + generateAttributeDeclaration(output, attribute); + generateGetAttributeAccessor(output, attribute); + generateSetAttributeAccessor(output, attribute); + if (attribute.getReverseAttribute() != null) { + ObjectModelAttribute reverse = attribute.getReverseAttribute(); + generateAttributeDeclaration(output, reverse); + generateGetAttributeAccessor(output, reverse); + generateSetAttributeAccessor(output, reverse); + } +/*{ + + @MethodInfo ( + type = MethodType.GENERATED + ) + public <%=assocClassName%> clone() { + <%=assocClassName%> clone = new <%=assocClassName%>(); + clone.set<%=Util.capitalize(attribute.getName())%>(<%=attribute.getName()%>); +}*/ + if (attribute.getReverseAttribute() != null) { + ObjectModelAttribute reverse = attribute.getReverseAttribute(); +/*{ clone.set<%=Util.capitalize(reverse.getName())%>(<%=reverse.getName()%>); +}*/ + } +/*{ return clone; + } + +} // <%=assocClassName%> +}*/ + } + + private void generateAttributeDeclaration(Writer output, ObjectModelAttribute attribute) throws IOException { +/*{ + protected <%=attribute.getType()%> <%=attribute.getName()%>; +}*/ + } + + private void generateGetAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { +/*{ + @MethodInfo( + type = MethodType.FIELD_ACCESSOR, + isFieldModifier = false, + field = "<%=attribute.getName()%>", + fieldType = <%=attribute.getType()%>.class + ) + public <%=attribute.getType()%> get<%=Util.capitalize(attribute.getName())%>() { + return <%=attribute.getName()%>; + } +}*/ + } + + private void generateSetAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { +/*{ + @MethodInfo( + type = MethodType.FIELD_ACCESSOR, + isFieldModifier = true, + field = "<%=attribute.getName()%>", + fieldType = <%=attribute.getType()%>.class + ) + public void set<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) { + this.<%=attribute.getName()%> = value; + } +}*/ + } + +}