Index: topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityTOClassGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityTOClassGenerator.java:1.18 topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityTOClassGenerator.java:1.19 --- topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityTOClassGenerator.java:1.18 Wed Jun 16 09:41:26 2004 +++ topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityTOClassGenerator.java Fri Jun 18 18:29:19 2004 @@ -44,12 +44,7 @@ if (! Util.isEntity(clazz)) return; // ------------- File Header - if (!"".equals(clazz.getPackageName())) { -/*{ -package <%=clazz.getPackageName()%>.transfer; - -}*/ - } + generatePackageStatement(output, clazz); // ------------- Imports generateImport(output, clazz); @@ -58,11 +53,14 @@ generateClassDeclaration(output, clazz); // ------------- Attributes - generateAttributeDeclaration(output, clazz); // ------------- Accessors - generateAttributeAccessor(output, clazz); - + for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + generateAttributeDeclaration(output, attribute); + generateGetAttributeAccessor(output, attribute); + generateSetAttributeAccessor(output, attribute); + } // ------------- Operations declarations generateOperation(output, clazz); @@ -96,16 +94,12 @@ if (! Util.isEntity(interfacez)) return; // ------------- File Header - if (!"".equals(interfacez.getPackageName())) { -/*{ -package <%=interfacez.getPackageName()%>.transfer; - -}*/ - } + generatePackageStatement(output, interfacez); // ------------- Imports /*{ import org.codelutin.topia.TopiaEntityTO; +import org.codelutin.topia.TopiaEntityTO; import org.codelutin.topia.TopiaException; import <%=interfacez.getQualifiedName()%>; }*/ @@ -155,6 +149,15 @@ + public void generatePackageStatement(Writer output, ObjectModelClassifier clazz) + throws IOException { + if (!"".equals(clazz.getPackageName())) { +/*{ +package <%=clazz.getPackageName()%>.transfer; + +}*/ + } + } /** @@ -162,11 +165,15 @@ */ protected void generateImport(Writer output, ObjectModelClassifier clazz)throws IOException{ /*{ +import org.codelutin.topia.TopiaEntity; import org.codelutin.topia.TopiaEntityTO; -import org.codelutin.topia.AbstractTopiaEntity; +import org.codelutin.topia.AbstractTopiaEntityTO; import org.codelutin.topia.TopiaUser; import org.codelutin.topia.TopiaException; +import org.codelutin.topia.TopiaPersistenceService; +import org.codelutin.topia.PrivateTopiaPersistenceService; import java.util.List; +import java.util.Collections; import <%=clazz.getQualifiedName()%>; }*/ @@ -189,7 +196,7 @@ // BB: je ne comprend pas a quoi sert le Extension ? /*{ extends <%=superclass.getName()%><%if(Util.isDerived(clazz)){%>Extension<%}%>TO}*/ } else { -/*{ extends AbstractTopiaEntity}*/ +/*{ extends AbstractTopiaEntityTO}*/ } /*{ implements <%=clazz.getName()%>, TopiaEntityTO}*/ for (i = clazz.getInterfaces().iterator(); i.hasNext();) { @@ -204,14 +211,12 @@ /** * Permet la generation de la declaration des attributs */ - protected void generateAttributeDeclaration(Writer output, ObjectModelClass clazz)throws IOException{ - - // Iterate on each attribute to generate declarations - for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + protected void generateAttributeDeclaration(Writer output, ObjectModelAttribute attribute)throws IOException{ + if(!Util.isDerived(attribute)){ /*{ // variable declaration, the name is prefixed by _ protected <%=Util.getAttributeType(attribute)%> _<%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; + protected boolean _<%=attribute.getName()%>Modified_ = false; }*/ if (attribute.referenceClassifier()) { @@ -237,58 +242,92 @@ /** * Permet la generation des methode d'acces aux attributs */ - protected void generateAttributeAccessor(Writer output, ObjectModelClass clazz)throws IOException{ - // Iterate on each attribute to declare accessors - for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if (Util.isDerived(attribute)) { + protected void generateGetAttributeAccessor(Writer output, ObjectModelAttribute attribute)throws IOException{ + if (Util.isDerived(attribute)) { /*{ - public abstract <%=Util.getAttributeType(attribute)%> get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() throws TopiaException; + public abstract <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; }*/ - if (!Util.isReadOnly(attribute)) { -/*{ - public abstract void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException; - -}*/ - } - }else{ + }else{ // Not a derived attribute : /*{ - public <%=Util.getAttributeType(attribute)%> get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() throws TopiaException { + public boolean is_<%=attribute.getName()%>Modified_(){ + return this._<%=attribute.getName()%>Modified_; + } + + + public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException { <% if (attribute.referenceClassifier()) { %> if (! this._<%=attribute.getName()%>ReferenceLoaded_) { - _<%=attribute.getName()%> = getContext().getPersistenceService(<%=attribute.getType()%>.class).getByTopiaId(_<%=attribute.getName()%>Id_); + TopiaPersistenceService tps = + getContext().getPersistenceService(<%=attribute.getType()%>.class); + PrivateTopiaPersistenceService ptps = + (PrivateTopiaPersistenceService)tps; + _<%=attribute.getName()%> = <%=(Util.isNMultiplicity(attribute)?"":"("+Util.getAttributeType(attribute)+")")%> + ptps.findByTopiaId(_<%=attribute.getName()%>Id_); this._<%=attribute.getName()%>ReferenceLoaded_ = true; } - <% } %> - + <% } + if(Util.isNMultiplicity(attribute)){ + %> + return Collections.unmodifiableList(_<%=attribute.getName()%>); + <% }else{ %> return _<%=attribute.getName()%>; + <% } %> + } +}*/ + } } + + + /** + * Permet la generation des methode d'acces aux attributs + */ + protected void generateSetAttributeAccessor(Writer output, ObjectModelAttribute attribute)throws IOException{ + if (!Util.isReadOnly(attribute)) { + if (Util.isDerived(attribute)) { +/*{ + public abstract void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException; + }*/ - if (!Util.isReadOnly(attribute)) { + }else{ + if(!Util.isNMultiplicity(attribute)){ /*{ - public void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException { - this._<%=attribute.getName()%> = <%=attribute.getName()%>; + public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException { + this._<%=attribute.getName()%>Modified_ = true; + this._<%=attribute.getName()%> = <%=attribute.getName()%>; <% if (attribute.referenceClassifier()) { %> - this._<%=attribute.getName()%>ReferenceLoaded = true; + this._<%=attribute.getName()%>ReferenceLoaded_ = true; <% } %> } }*/ - if(Util.isNMultiplicity(attribute)){ + }else{ /*{ - public void add<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=attribute.getType()%> <%=attribute.getName()%>) throws TopiaException { + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> <%=attribute.getName()%>) throws TopiaException { + this._<%=attribute.getName()%>Modified_ = true; <% if (attribute.referenceClassifier()) { %> // on force le chargement - get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(); + get<%=Util.capitalize(attribute.getName())%>(); <% } %> this._<%=attribute.getName()%>.add(<%=attribute.getName()%>); } + + public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> <%=attribute.getName()%>) throws TopiaException { + this._<%=attribute.getName()%>Modified_ = true; + <% if (attribute.referenceClassifier()) { %> + // on force le chargement + get<%=Util.capitalize(attribute.getName())%>(); + <% } %> + this._<%=attribute.getName()%>.remove(<%=attribute.getName()%>); + } + + public void clear<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + this._<%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; + } }*/ - } } } } @@ -349,8 +388,17 @@ protected void generateFrameworkNeed(Writer output, ObjectModelClass clazz)throws IOException{ generateTopiaIdOperation(output, clazz); + generateSetAllFrameworkProperties(output, clazz); /*{ + + /** + * Return entity Class managed by this service + *) + public Class getEntityClass(){ + return <%=clazz.getName()%>.class; + } + protected String _version_; protected java.util.Date _creationDate_; protected java.util.Date _lastUpdateDate_; @@ -383,13 +431,17 @@ public void set_lastUpdateUser_(TopiaUser lastUpdateUser) throws TopiaException { this._lastUpdateUser_ = lastUpdateUser; } +}*/ + } + protected void generateSetAllFrameworkProperties(Writer output, ObjectModelClass clazz) throws IOException { +/*{ /** * Prend toutes les valeurs de l'objet passé en paramètre et les utilises * comme valeur pour l'objet courant, ceci inclue l'id de l'objet * Les modifications s'effectue au travers des methodes set. *) - public void set_AllProperties_(TopiaEntity topiaEntity){ + public void set_allProperties_(TopiaEntity topiaEntity) throws TopiaException { <%=clazz.getName()%> entity = (<%=clazz.getName()%>)topiaEntity; this._topiaId_ = entity.get_topiaId_(); @@ -402,48 +454,49 @@ // Iterate on each attribute for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if (! attribute.referenceClassifier()) { + if(! Util.isDerived(attribute)){ + if (! attribute.referenceClassifier()) { /*{ - // field direct copy to not used specifique subclasse set or get methode - this.<%=attribute.getName()%> = entity.get<%=Util.capitalize(attribute.getName())%>(); + this._<%=attribute.getName()%> = entity.get<%=Util.capitalize(attribute.getName())%>(); }*/ - } else { + } else { /*{ this._<%=attribute.getName()%>ReferenceLoaded_ = false; this._<%=attribute.getName()%> = null; }*/ - if (Util.isNMultiplicity(attribute)) { + if (!Util.isNMultiplicity(attribute)) { +/*{ + if(entity instanceof TopiaEntityTO && !((<%=clazz.getName()%>TO)entity)._<%=attribute.getName()%>ReferenceLoaded_){ + // if we can do more faster, we do :) + <%=clazz.getName()%>TO e = (<%=clazz.getName()%>TO)topiaEntity; + this._<%=attribute.getName()%>Id_ = e._<%=attribute.getName()%>Id_; + }else{ + TopiaEntity te = entity.get<%=Util.capitalize(attribute.getName())%>(); + if (te != null){ + this._<%=attribute.getName()%>Id_ = te.get_topiaId_(); + } + } +}*/ + } else { /*{ { ArrayList tmpIds = new ArrayList(); - if(entity instanceof TopiaEnityTO && !((<%=clazz.getName()%>TO)entity)._<%=attribute.getName()%>ReferenceLoaded_){ + if(entity instanceof TopiaEntityTO && !((<%=clazz.getName()%>TO)entity)._<%=attribute.getName()%>ReferenceLoaded_){ // if we can do more faster, we do :) - <%=clazz.getName()%>T0 e = (<%=clazz.getName()%>TO)topiaEntity; + <%=clazz.getName()%>TO e = (<%=clazz.getName()%>TO)topiaEntity; tmpIds.addAll(e._<%=attribute.getName()%>Id_); }else{ // else we use get method for (Iterator i=entity.get<%=Util.capitalize(attribute.getName())%>().iterator(); i.hasNext();) { - TopiaEnity te = (TopiaEnity)i.next(); + TopiaEntity te = (TopiaEntity)i.next(); if (object != null) tmpIds.add(te.get_topiaId_()); } } this._<%=attribute.getName()%>Id_ = tmpIds; } }*/ - } else { -/*{ - if(entity instanceof TopiaEnityTO && !((<%=clazz.getName()%>TO)entity)._<%=attribute.getName()%>ReferenceLoaded_){ - // if we can do more faster, we do :) - <%=clazz.getName()%>T0 e = (<%=clazz.getName()%>TO)topiaEntity; - this._<%=attribute.getName()%>Id_ = e._<%=attribute.getName()%>Id_; - }else{ - TopiaEnity te = entity.get<%=Util.capitalize(attribute.getName())%>(); - if (te != null){ - this._<%=attribute.getName()%>Id_ = te.get_topiaId_(); - } - } -}*/ - } + } + } } } /*{