Index: topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToApplicationContextGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToApplicationContextGenerator.java:1.2 topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToApplicationContextGenerator.java:1.3 --- topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToApplicationContextGenerator.java:1.2 Fri Jun 4 18:43:54 2004 +++ topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToApplicationContextGenerator.java Wed Jun 16 09:41:26 2004 @@ -23,9 +23,9 @@ * * @author Cédric Pineau * Copyright Code Lutin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Last update : $Date: 2004/06/04 18:43:54 $ + * Last update : $Date: 2004/06/16 09:41:26 $ * by : $Author: bpoussin $ */ package org.codelutin.topia.generators.commons; @@ -33,6 +33,7 @@ import java.io.IOException; import java.io.Writer; import java.util.Iterator; +import java.io.File; import org.codelutin.generator.ObjectModelGenerator; import org.codelutin.generator.models.object.ObjectModel; @@ -45,7 +46,9 @@ public class ObjectModelToApplicationContextGenerator extends ObjectModelGenerator { public String getFilenameForModel(ObjectModel model){ - return "org/"+model.getName()+"Context.java"; + // TODO rechercher le bon package pour mettre le fichier + // peut-etre un argument du generateur ? + return "org" + File.separator + model.getName() + "Context.java"; } public void generateFromModel(Writer output, ObjectModel model) throws IOException { Index: topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityInterfaceGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityInterfaceGenerator.java:1.13 topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityInterfaceGenerator.java:1.14 --- topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityInterfaceGenerator.java:1.13 Thu May 13 10:58:30 2004 +++ topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityInterfaceGenerator.java Wed Jun 16 09:41:26 2004 @@ -18,12 +18,6 @@ import org.codelutin.generator.models.object.ObjectModelOperation; import org.codelutin.generator.models.object.ObjectModelParameter; -/** - * @author cedric - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ public class ObjectModelToEntityInterfaceGenerator extends ObjectModelGenerator { @@ -31,103 +25,103 @@ return super.getFilenameForClass(clazz) + ".java"; } - public void generateFromClass(Writer output, ObjectModelClass clazz) - throws IOException { + public void generateFromClass(Writer output, ObjectModelClass clazz) + throws IOException { - // Consider only entities, return immediately if not an entity - if (! Util.isEntity(clazz)) return; + // Consider only entities, return immediately if not an entity + if (! Util.isEntity(clazz)) return; - // ------------- File Header - if (!"".equals(clazz.getPackageName())) { + // ------------- File Header + if (!"".equals(clazz.getPackageName())) { /*{ package <%=clazz.getPackageName()%>; }*/ - } + } - // ------------- Imports + // ------------- Imports /*{ import org.codelutin.topia.TopiaEntity; import org.codelutin.topia.TopiaException; }*/ - // ------------- Interface start + // ------------- Interface start /*{ /** <%=clazz.getDocumentation()%> *) public interface <%=clazz.getName()%> extends TopiaEntity}*/ - for (Iterator i = clazz.getInterfaces().iterator(); i.hasNext();) { - ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); + for (Iterator i = clazz.getInterfaces().iterator(); i.hasNext();) { + ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); /*{, <%=interfacezz.getName()%> }*/ - } - for (Iterator i = clazz.getSuperclasses().iterator(); i.hasNext();) { - ObjectModelClass superclass = (ObjectModelClass) i.next(); + } + for (Iterator i = clazz.getSuperclasses().iterator(); i.hasNext();) { + ObjectModelClass superclass = (ObjectModelClass) i.next(); /*{, <%=superclass.getName()%>}*/ - } + } /*{ { }*/ - // ------------- Operations declarations - // Iterate on each operation to generate declarations - for (Iterator i = clazz.getOperations().iterator(); i.hasNext();) { - ObjectModelOperation operation = (ObjectModelOperation) i.next(); + // ------------- Operations declarations + // Iterate on each operation to generate declarations + for (Iterator i = clazz.getOperations().iterator(); i.hasNext();) { + ObjectModelOperation operation = (ObjectModelOperation) i.next(); /*{ /** <%=operation.getDocumentation()%> *) - <%=operation.getVisibility()%> <%=operation.getReturnType()%> <%=operation.getName()%>(}*/ - // Iterate on each parameters to declare operation parameters - for (Iterator j = operation.getParameters().iterator(); - j.hasNext(); - ) { - ObjectModelParameter parameter = - (ObjectModelParameter) j.next(); + <%=operation.getVisibility()%> <%=operation.getReturnType()%> <%=operation.getName()%>(}*/ + // Iterate on each parameters to declare operation parameters + for (Iterator j = operation.getParameters().iterator(); + j.hasNext(); + ) { + ObjectModelParameter parameter = + (ObjectModelParameter) j.next(); /*{ <%=parameter.getType()+" "+parameter.getName()%>}*/ - if (j.hasNext()) { /*{, }*/ - } - } + if (j.hasNext()) { /*{, }*/ + } + } /*{ ) throws TopiaException; }*/ - } + } /*{ }*/ - // ------------- Accessors - // Iterate on each attribute to declare accessors - for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + // ------------- Accessors + // Iterate on each attribute to declare accessors + for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); /*{ /** Getter on <%=attribute.getName()%>. <%=attribute.getDocumentation()%> *) - public <%=Util.getAttributeType(attribute)%> get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() throws TopiaException; + public <%=Util.getAttributeType(attribute)%> get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() throws TopiaException; }*/ - if (! Util.isReadOnly(attribute)) { + if (! Util.isReadOnly(attribute)) { /*{ /** Setter on <%=attribute.getName()%>. <%=attribute.getDocumentation()%> *) - public void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException; + public void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException; }*/ - } + } /*{ - + }*/ - } + } - // ------------- Interface end + // ------------- Interface end /*{ } }*/ - } + } public String getFilenameForInterface(ObjectModelInterface interfacez) { return super.getFilenameForInterface(interfacez) + ".java"; @@ -138,8 +132,8 @@ ObjectModelInterface interfacez) throws IOException { - // Consider only entities, return immediately if not an entity - if (! Util.isEntity(interfacez)) return; + // Consider only entities, return immediately if not an entity + if (! Util.isEntity(interfacez)) return; // ------------- File Header if (!"".equals(interfacez.getPackageName())) { @@ -149,7 +143,7 @@ }*/ } - // ------------- Imports + // ------------- Imports /*{ import org.codelutin.topia.TopiaEntity; import org.codelutin.topia.TopiaException; @@ -170,7 +164,7 @@ } /*{ { - + }*/ // ------------- Operations declarations Index: topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityTOClassGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityTOClassGenerator.java:1.17 topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityTOClassGenerator.java:1.18 --- topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityTOClassGenerator.java:1.17 Wed May 19 10:33:03 2004 +++ topia/src/java/org/codelutin/topia/generators/commons/ObjectModelToEntityTOClassGenerator.java Wed Jun 16 09:41:26 2004 @@ -15,380 +15,439 @@ import org.codelutin.topia.Util; import org.codelutin.generator.models.object.ObjectModelAttribute; import org.codelutin.generator.models.object.ObjectModelClass; +import org.codelutin.generator.models.object.ObjectModelClassifier; import org.codelutin.generator.models.object.ObjectModelInterface; import org.codelutin.generator.models.object.ObjectModelOperation; import org.codelutin.generator.models.object.ObjectModelParameter; -/** - * @author cedric - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ public class ObjectModelToEntityTOClassGenerator extends ObjectModelGenerator { + ////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// + //// + //// + //// FOR CLASS + //// + //// + ////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// + public String getFilenameForClass(ObjectModelClass clazz) { - return (clazz.getPackageName()+".transfer.").replace('.', File.separatorChar)+clazz.getName()+"TO.java"; + return (clazz.getPackageName()+".transfer.").replace('.', File.separatorChar)+clazz.getName()+"TO.java"; } - public void generateFromClass(Writer output, ObjectModelClass clazz) - throws IOException { + public void generateFromClass(Writer output, ObjectModelClass clazz) + throws IOException { - // Consider only entities, return immediately if not an entity - if (! Util.isEntity(clazz)) return; + // Consider only entities, return immediately if not an entity + if (! Util.isEntity(clazz)) return; - // ------------- File Header - if (!"".equals(clazz.getPackageName())) { + // ------------- File Header + if (!"".equals(clazz.getPackageName())) { /*{ package <%=clazz.getPackageName()%>.transfer; }*/ - } + } - // ------------- Imports -/*{ -import org.codelutin.topia.TopiaEntityTO; -import org.codelutin.topia.AbstractTopiaEntity; -import org.codelutin.topia.TopiaUser; -import org.codelutin.topia.TopiaException; -import java.util.List; -import <%=clazz.getQualifiedName()%>; -}*/ + // ------------- Imports + generateImport(output, clazz); - for (Iterator i = clazz.getInterfaces().iterator(); i.hasNext();) { - ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); + // ------------- Class start + generateClassDeclaration(output, clazz); + + // ------------- Attributes + generateAttributeDeclaration(output, clazz); + + // ------------- Accessors + generateAttributeAccessor(output, clazz); + + // ------------- Operations declarations + generateOperation(output, clazz); + + // ---------------- All that framework used + generateFrameworkNeed(output, clazz); /*{ -import <%=clazz.getPackageName()%>.<%=interfacezz.getName()%>; + } }*/ - } -/*{ -}*/ - - // ------------- Class start -/*{ -public }*/ - for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if (Util.isDerived(attribute)) { -/*{abstract }*/ - break; - } - } + } + ////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// + //// + //// + //// FOR INTERFACE + //// + //// + ////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// -/*{class <%=clazz.getName()%>TO}*/ - Iterator i = clazz.getSuperclasses().iterator(); - if (i.hasNext()) { - ObjectModelClass superclass = (ObjectModelClass) i.next(); -/*{ extends <%=superclass.getName()%>}*/ - for (Iterator j = superclass.getAttributes().iterator(); j.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) j.next(); - if (Util.isDerived(attribute)) { -/*{Extension}*/ - break; - } - } -/*{TO}*/ - } else { -/*{ extends AbstractTopiaEntity}*/ - } -/*{ implements <%=clazz.getName()%>, TopiaEntityTO}*/ - for (i = clazz.getInterfaces().iterator(); i.hasNext();) { - ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); -/*{, <%=interfacezz.getName()%>}*/ - } -/*{ { - - protected Object _topiaId; -}*/ - // ------------- refs loaded flags and ids attributes - // Iterate on each attribute to generate declarations - for (i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if (attribute.referenceClassifier()) { -/*{ - public boolean _<%=attribute.getName()%>ReferenceLoaded = false; -}*/ - if ((attribute.getMaxMultiplicity() > 1) || (attribute.getMaxMultiplicity( )== -1)) { + public String getFilenameForInterface(ObjectModelInterface interfacez) { + return (interfacez.getPackageName()+".transfer.").replace('.', File.separatorChar)+interfacez.getName()+"TO.java"; + } + + public void generateFromInterface(Writer output, ObjectModelInterface interfacez) + throws IOException { + + // Consider only entities, return immediately if not an entity + if (! Util.isEntity(interfacez)) return; + + // ------------- File Header + if (!"".equals(interfacez.getPackageName())) { /*{ - public List _<%=attribute.getName()%> = null; -}*/ - } else { -/*{ - public Object _<%=attribute.getName()%> = null; +package <%=interfacez.getPackageName()%>.transfer; + }*/ - } - } - } -/*{ - // TODO a rechanger pour rendre protected ces champs et passer par des assaceurs -}*/ + } - // ------------- Attribute declaration - // Iterate on each attribute to generate declarations - for (i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); -/*{ - public <%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>; -}*/ - } + // ------------- Imports /*{ - protected String _version; - protected java.util.Date _creationDate; - protected java.util.Date _lastUpdateDate; - protected TopiaUser _lastUpdateUser; -}*/ +import org.codelutin.topia.TopiaEntityTO; +import org.codelutin.topia.TopiaException; +import <%=interfacez.getQualifiedName()%>; +}*/ - // ------------- Default empty constructor -/*{ - public <%=clazz.getName()%>TO() throws TopiaException { - super(); -}*/ - // Iterate on each attribute to generate parameter inits - for (i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + for (Iterator i = interfacez.getInterfaces().iterator(); i.hasNext();) { + ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); /*{ - this.<%=attribute.getName()%> = <%=Util.getAttributeInitValue(attribute)%>; +import <%=interfacez.getPackageName()%>.<%=interfacezz.getName()%>; }*/ - } + } /*{ - } }*/ - if (! clazz.getAttributes().isEmpty()) { - // ------------- Full constructor -/*{ - public <%=clazz.getName()%>TO(}*/ - // Iterate on each attribute to declare constructor parameters - for (i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); -/*{<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>}*/ - if (i.hasNext()) { /*{, }*/ } - } + // ------------- Interface start /*{ -) throws TopiaException { - super(); +public interface <%=interfacez.getName()%>TO}*/ +/*{ extends <%=interfacez.getName()%>, TopiaEntityTO}*/ + for (Iterator i = interfacez.getInterfaces().iterator(); i.hasNext();) { + ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); +/*{, <%=interfacezz.getName()%>}*/ + } +/*{ { }*/ - // Iterate on each attribute to generate parameter settings - for (i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + generateOperation(output, interfacez); /*{ - this.<%=attribute.getName()%> = <%=attribute.getName()%>; + } }*/ - } -/*{ - } + + } + + + + + ////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// + //// + //// + //// SUB GENERATOR + //// + //// + ////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// + + + + + + + + + /** + * Permet la generation des imports + */ + protected void generateImport(Writer output, ObjectModelClassifier clazz)throws IOException{ + /*{ +import org.codelutin.topia.TopiaEntityTO; +import org.codelutin.topia.AbstractTopiaEntity; +import org.codelutin.topia.TopiaUser; +import org.codelutin.topia.TopiaException; +import java.util.List; +import <%=clazz.getQualifiedName()%>; }*/ - } - - // ------------- Accessors - // Iterate on each attribute to declare accessors - for (i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if (Util.isDerived(attribute)) { + + for (Iterator i = clazz.getInterfaces().iterator(); i.hasNext();) { + ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); /*{ - public abstract <%=Util.getAttributeType(attribute)%> get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() throws TopiaException; +import <%=clazz.getPackageName()%>.<%=interfacezz.getName()%>; }*/ - if (!Util.isReadOnly(attribute)) { + } + } + + + protected void generateClassDeclaration(Writer output, ObjectModelClass clazz) + throws IOException { /*{ - public abstract void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException; - +public<% if(Util.isDerived(clazz)){ %> abstract<% } %> class <%=clazz.getName()%>TO}*/ + Iterator i = clazz.getSuperclasses().iterator(); + if (i.hasNext()) { + ObjectModelClass superclass = (ObjectModelClass) i.next(); + // BB: je ne comprend pas a quoi sert le Extension ? +/*{ extends <%=superclass.getName()%><%if(Util.isDerived(clazz)){%>Extension<%}%>TO}*/ + } else { +/*{ extends AbstractTopiaEntity}*/ + } +/*{ implements <%=clazz.getName()%>, TopiaEntityTO}*/ + for (i = clazz.getInterfaces().iterator(); i.hasNext();) { + ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); +/*{, <%=interfacezz.getName()%>}*/ + } +/*{ { }*/ + + } + + + /** + * 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(); +/*{ + // variable declaration, the name is prefixed by _ + protected <%=Util.getAttributeType(attribute)%> _<%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; }*/ - } - continue; - } - - // Not a derived attribute : + + if (attribute.referenceClassifier()) { /*{ - public <%=Util.getAttributeType(attribute)%> get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() throws TopiaException { + // boolean to know if attribute is allready loaded + protected boolean _<%=attribute.getName()%>ReferenceLoaded_ = false; + <% if (Util.isNMultiplicity(attribute)) { %> + // lists des Ids des entities + protected List _<%=attribute.getName()%>Id_ = null; + <% } else { %> + // Id of the entity + protected Object _<%=attribute.getName()%>Id_ = null; + <% } %> }*/ - if (attribute.referenceClassifier()) { -/*{ - if (! this._<%=attribute.getName()%>ReferenceLoaded) { - //TODO Appel au service CRUD correspondant <%=attribute.getName()%> = <%=attribute.getType()%>DAO.getInstance().getById(_<%=attribute.getName()%>Id); - this._<%=attribute.getName()%>ReferenceLoaded = true; + } } -}*/ - } -/*{ - return <%=attribute.getName()%>; - } -}*/ - if (!Util.isReadOnly(attribute)) { + } + + + + + + /** + * 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)) { /*{ - public void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException { + public abstract <%=Util.getAttributeType(attribute)%> get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() throws TopiaException; }*/ - if ((attribute.getMaxMultiplicity() == -1) || (attribute.getMaxMultiplicity()>1)) { + if (!Util.isReadOnly(attribute)) { /*{ - this.<%=attribute.getName()%> = (<%=attribute.getName()%> == null)?<%=Util.getAttributeInitValue(attribute)%>:<%=attribute.getName()%>; + public abstract void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException; + }*/ - } else { + } + }else{ + + // Not a derived attribute : /*{ - this.<%=attribute.getName()%> = <%=attribute.getName()%>; + public <%=Util.getAttributeType(attribute)%> get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>() throws TopiaException { + + <% if (attribute.referenceClassifier()) { %> + + if (! this._<%=attribute.getName()%>ReferenceLoaded_) { + _<%=attribute.getName()%> = getContext().getPersistenceService(<%=attribute.getType()%>.class).getByTopiaId(_<%=attribute.getName()%>Id_); + this._<%=attribute.getName()%>ReferenceLoaded_ = true; + } + + <% } %> + + return _<%=attribute.getName()%>; + } }*/ - } - if (attribute.referenceClassifier()) { + if (!Util.isReadOnly(attribute)) { /*{ - this._<%=attribute.getName()%>ReferenceLoaded = true; -}*/ - } -/*{ - } + public void set<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException { + this._<%=attribute.getName()%> = <%=attribute.getName()%>; + <% if (attribute.referenceClassifier()) { %> + this._<%=attribute.getName()%>ReferenceLoaded = true; + <% } %> + } }*/ - } + if(Util.isNMultiplicity(attribute)){ /*{ - + public void add<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(<%=attribute.getType()%> <%=attribute.getName()%>) throws TopiaException { + <% if (attribute.referenceClassifier()) { %> + // on force le chargement + get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>(); + <% } %> + this._<%=attribute.getName()%>.add(<%=attribute.getName()%>); + } }*/ - } + } + } + } + } + } -// ------------- refs loaded flags and ids accessors - // Iterate on each attribute to generate declarations - for (i = clazz.getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if (attribute.referenceClassifier()) { + /** + * Permet la generation des methodes + */ + protected void generateOperation(Writer output, ObjectModelClassifier clazz)throws IOException{ + // Iterate on each operation to generate declarations + for (Iterator i = clazz.getOperations().iterator(); i.hasNext();) { + ObjectModelOperation operation = (ObjectModelOperation) i.next(); /*{ - public boolean _get<%=Util.toUpperCaseFirstLetter(attribute.getName())%>ReferenceLoaded() throws TopiaException { - return this._<%=attribute.getName()%>ReferenceLoaded; + <%=operation.getVisibility()%> <%=(operation.isAbstract()?"abstract ":"")%><%=operation.getReturnType()%> <%=operation.getName()%> (<%=Util.getMethodParameterDeclaration(operation.getParameters())%>) throws TopiaException}*/ + } } -}*/ - } - } - // ------------- Operations declarations - // Iterate on each operation to generate declarations - for (i = clazz.getOperations().iterator(); i.hasNext();) { - ObjectModelOperation operation = (ObjectModelOperation) i.next(); -/*{ - <%=operation.getVisibility()%> <%=(operation.isAbstract()?"abstract ":"")%><%=operation.getReturnType()%> <%=operation.getName()%> (}*/ - // Iterate on each parameters to declare operation parameters - for (Iterator j = operation.getParameters().iterator(); - j.hasNext(); - ) { - ObjectModelParameter parameter = - (ObjectModelParameter) j.next(); -/*{ -<%=parameter.getType()+" "+parameter.getName()%>}*/ - if (j.hasNext()) { /*{, }*/ - } - } - if (operation.isAbstract()) { -/*{ -) throws TopiaException; -}*/ - } else { -/*{ -) throws TopiaException { - // TODO forward sur le service adéquat + protected void generateOperationBody(Writer output, ObjectModelOperation operation) throws IOException { + if (operation.isAbstract() + || operation.getDeclaringElement() instanceof ObjectModelInterface) { +/*{;}*/ + } else { +/*{{ + // TODO forward sur le service adéquat }*/ - if (! "void".equals(operation.getReturnType())) { + if (! "void".equals(operation.getReturnType())) { /*{ - return null; + return <%=Util.getInitValue(operation.getReturnType())%>; }*/ - } + } /*{ - } + } }*/ - } - } - - // ------------- Class end + } + } + + + public void generateTopiaIdOperation(Writer output, ObjectModelClassifier clazz) + throws IOException { /*{ + protected Object _topiaId_; - public Object _getTopiaId() throws TopiaException { - return this._topiaId; + public Object get_topiaId_() throws TopiaException { + return this._topiaId_; } - public void _setTopiaId(Object topiaId) throws TopiaException { - this._topiaId = topiaId; + public void set_topiaId_(Object topiaId) throws TopiaException { + this._topiaId_ = topiaId; } +}*/ + } + + /** + * Permet la generation de tout ce dont a besoin de le framework + */ + protected void generateFrameworkNeed(Writer output, ObjectModelClass clazz)throws IOException{ + + generateTopiaIdOperation(output, clazz); + + /*{ + protected String _version_; + protected java.util.Date _creationDate_; + protected java.util.Date _lastUpdateDate_; + protected TopiaUser _lastUpdateUser_; - public String _getVersion() throws TopiaException { - return _version; + public String get_version_() throws TopiaException { + return _version_; } - public void _setVersion(String version) throws TopiaException { - this._version = version; + public void set_version_(String version) throws TopiaException { + this._version_ = version; } - - public java.util.Date _getCreationDate() throws TopiaException { - return _creationDate; + + public java.util.Date get_creationDate_() throws TopiaException { + return _creationDate_; } - public void _setCreationDate(java.util.Date creationDate) throws TopiaException { - this._creationDate = creationDate; + public void set_creationDate_(java.util.Date creationDate) throws TopiaException { + this._creationDate_ = creationDate; } - - public java.util.Date _getLastUpdateDate() throws TopiaException { - return _lastUpdateDate; + + public java.util.Date get_lastUpdateDate_() throws TopiaException { + return _lastUpdateDate_; } - public void _setLastUpdateDate(java.util.Date lastUpdateDate) throws TopiaException { - this._lastUpdateDate = lastUpdateDate; + public void set_lastUpdateDate_(java.util.Date lastUpdateDate) throws TopiaException { + this._lastUpdateDate_ = lastUpdateDate; } - public TopiaUser _getLastUpdateUser() throws TopiaException { - return _lastUpdateUser; + public TopiaUser get_lastUpdateUser_() throws TopiaException { + return _lastUpdateUser_; } - public void _setLastUpdateUser(TopiaUser lastUpdateUser) throws TopiaException { - this._lastUpdateUser = lastUpdateUser; + public void set_lastUpdateUser_(TopiaUser lastUpdateUser) throws TopiaException { + this._lastUpdateUser_ = lastUpdateUser; } - -} -}*/ - - } - - public String getFilenameForInterface(ObjectModelInterface interfacez) { - return (interfacez.getPackageName()+".transfer.").replace('.', File.separatorChar)+interfacez.getName()+"TO.java"; - } - public void generateFromInterface(Writer output, ObjectModelInterface interfacez) - throws IOException { - - // Consider only entities, return immediately if not an entity - if (! Util.isEntity(interfacez)) return; - - // ------------- File Header - if (!"".equals(interfacez.getPackageName())) { -/*{ -package <%=interfacez.getPackageName()%>.transfer; + /** + * 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){ + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)topiaEntity; -}*/ - } + this._topiaId_ = entity.get_topiaId_(); + this._version_ = entity.get_version_(); + this._creationDate_ = entity.get_creationDate_(); + this._lastUpdateDate_ = entity.get_lastUpdateDate_(); + this._lastUpdateUser_ = entity.get_lastUpdateUser_(); + }*/ - // ------------- Imports + // Iterate on each attribute + for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + if (! attribute.referenceClassifier()) { /*{ -import org.codelutin.topia.TopiaEntityTO; -import org.codelutin.topia.TopiaException; -import <%=interfacez.getQualifiedName()%>; + // field direct copy to not used specifique subclasse set or get methode + this.<%=attribute.getName()%> = entity.get<%=Util.capitalize(attribute.getName())%>(); }*/ - - for (Iterator i = interfacez.getInterfaces().iterator(); i.hasNext();) { - ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); + } else { /*{ -import <%=interfacez.getPackageName()%>.<%=interfacezz.getName()%>; + this._<%=attribute.getName()%>ReferenceLoaded_ = false; + this._<%=attribute.getName()%> = null; +}*/ + if (Util.isNMultiplicity(attribute)) { +/*{ + { + ArrayList tmpIds = new ArrayList(); + 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; + 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(); + 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_(); + } + } }*/ - - // ------------- Interface start + } + } + } /*{ -public interface <%=interfacez.getName()%>TO}*/ -/*{ extends <%=interfacez.getName()%>, TopiaEntityTO}*/ - for (Iterator i = interfacez.getInterfaces().iterator(); i.hasNext();) { - ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); -/*{, <%=interfacezz.getName()%>}*/ - } -/*{ { - -} + } }*/ - - } - + } }