Index: topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java:1.24 topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java:1.25 --- topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java:1.24 Mon Jun 21 09:51:17 2004 +++ topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityDOClassGenerator.java Tue Jun 22 19:01:06 2004 @@ -16,47 +16,25 @@ import org.codelutin.generator.models.object.ObjectModelOperation; import org.codelutin.generator.models.object.ObjectModelParameter; import org.codelutin.topia.generators.Util; -import org.codelutin.topia.generators.commons.ObjectModelToEntityTOClassGenerator; +import org.codelutin.topia.generators.DefaultObjectModelToJavaGenerator; +//import org.codelutin.topia.generators.commons.ObjectModelToEntityTOClassGenerator; public class ObjectModelToEntityDOClassGenerator - extends ObjectModelToEntityTOClassGenerator { + extends DefaultObjectModelToJavaGenerator { + ////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// + //// + //// + //// COMMON TO CLASS AND INTERFACE + //// + //// + ////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// - public String getFilenameForInterface(ObjectModelInterface interfacez) { - return (interfacez.getPackageName()+".persistence.").replace('.', File.separatorChar)+interfacez.getName()+"JDODO.java"; - } - - protected void generateImport(Writer output, ObjectModelClassifier clazz) - throws IOException{ - super.generateImport(output, clazz); -/*{ -import java.util.HashSet; -import org.codelutin.topia.TopiaEntityTO; -import org.codelutin.topia.TopiaEntityDO; -import org.codelutin.topia.AbstractTopiaEntityDO; -import org.codelutin.topia.PrivateTopiaPersistenceService; -import org.codelutin.topia.jdo.TopiaJDOPersistenceHelper; -import javax.jdo.PersistenceManager; -import <%=clazz.getPackageName()%>.transfer.<%=clazz.getName()%>TO; -}*/ - if(clazz instanceof ObjectModelClass){ - for (Iterator i=((ObjectModelClass)clazz).getAttributes().iterator(); i.hasNext();) { - ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); - if(attribute.referenceClassifier()){ - ObjectModelClassifier classifier = attribute.getClassifier(); -/*{ -import <%=classifier.getPackageName()%>.transfer.<%=classifier.getName()%>TO; -import <%=classifier.getPackageName()%>.persistence.<%=classifier.getName()%>JDODO; -}*/ - } - } - } - } - - public String getFilenameForClass(ObjectModelClass clazz) { - return (clazz.getPackageName()+".persistence.").replace('.', File.separatorChar)+clazz.getName()+"JDODO.java"; - } - + /** + * add transfer sub package + */ public void generatePackageStatement(Writer output, ObjectModelClassifier clazz) throws IOException { if (!"".equals(clazz.getPackageName())) { @@ -67,86 +45,103 @@ } } - public void generateClassDeclaration(Writer output, ObjectModelClass clazz) + /** + * Importe les classes utilises utilisees le plus souvent + */ + public void generateImportStatement(Writer output, ObjectModelClassifier clazz) throws IOException { + super.generateImportStatement(output, clazz); /*{ -public class <%=clazz.getName()%>JDODO}*/ - Iterator i = clazz.getSuperclasses().iterator(); - if (i.hasNext()) { - ObjectModelClass superclass = (ObjectModelClass) i.next(); -/*{ extends <%=superclass.getName()%>JDODO}*/ - } else { -/*{ extends AbstractTopiaEntityDO}*/ - } -/*{ implements <%=clazz.getName()%>, TopiaEntityDO}*/ - for (i = clazz.getInterfaces().iterator(); i.hasNext();) { +import <%=clazz.getQualifiedName()%>; +import org.codelutin.topia.jdo.TopiaJDOPersistenceHelper; +import javax.jdo.PersistenceManager; +import <%=clazz.getPackageName()%>.transfer.<%=clazz.getName()%>TO; +}*/ + + for (Iterator i = clazz.getInterfaces().iterator(); i.hasNext();) { ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); -/*{, <%=interfacezz.getName()%>}*/ +/*{ +import <%=clazz.getQualifiedName()%>; +}*/ } -/*{ { + } + public void generateImportStatement(Writer output, ObjectModelClass clazz) throws IOException { + generateImportStatement(output, (ObjectModelClassifier)clazz); + for (Iterator i=clazz.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + if(attribute.referenceClassifier()){ + ObjectModelClassifier classifier = attribute.getClassifier(); +/*{ +import <%=classifier.getPackageName()%>.transfer.<%=classifier.getName()%>TO; +import <%=classifier.getPackageName()%>.persistence.<%=classifier.getName()%>JDODO; }*/ + } + } } + public String getClassName(ObjectModelClassifier clazz){ + return clazz.getName() + "JDODO"; + } + ////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// + //// + //// + //// FOR INTERFACE + //// + //// + ////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// - /** - * Permet la generation de la declaration des attributs - */ - protected void generateAttributeDeclaration(Writer output, ObjectModelAttribute attribute)throws IOException{ - if (!Util.isDerived(attribute)) { - if(!attribute.referenceClassifier()){ -/*{ - protected <%=Util.getAttributeTypeForDO(attribute)%> <%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; -}*/ - }else{ - if(Util.isNMultiplicity(attribute)){ -/*{ - protected <%=Util.getAttributeTypeForDO(attribute)%> <%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; -}*/ - }else{ -/*{ - protected <%=attribute.getClassifier().getName()%>JDODO <%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; -}*/ - } - } - } + public String getFilenameForInterface(ObjectModelInterface interfacez) { + return (interfacez.getPackageName()+".persistence.").replace('.', File.separatorChar)+interfacez.getName()+"JDODO.java"; } + public String getExtendsInterfaceName(ObjectModelInterface interfacez){ + return interfacez.getName()+ ", TopiaEntityDO"; + } + ////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// + //// + //// + //// FOR CLASS + //// + //// + ////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// - + public String getFilenameForClass(ObjectModelClass clazz) { + return (clazz.getPackageName()+".persistence.").replace('.', File.separatorChar)+clazz.getName()+"JDODO.java"; + } /** - * Permet la generation des methodes d'acces aux attributs + * Les DO ne sont jamais abstrait car il n'y a pas de methode dessus */ - protected void generateGetAttributeAccessor(Writer output, ObjectModelAttribute attribute)throws IOException{ - if (!Util.isDerived(attribute)) { -/*{ - public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException { - return <%=attribute.getName()%>; + public boolean isAbstract(ObjectModelClass clazz){ + return false; } -}*/ - } + + public String getExtendsClassName(ObjectModelClass clazz){ + return "AbstractTopiaEntityDO"; } + public String getImplementsClassName(ObjectModelClass clazz){ + return clazz.getName() + ", TopiaEntityDO"; + } - /** - * Permet la generation des methode d'acces aux attributs - */ - protected void generateSetAttributeAccessor(Writer output, ObjectModelAttribute attribute)throws IOException{ - if (!Util.isReadOnly(attribute) && !Util.isDerived(attribute)) { - if(!Util.isNMultiplicity(attribute)){ - if(!attribute.referenceClassifier()){ + + public void generateEntityAttributeDeclaration(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ - public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException { - this.<%=attribute.getName()%> = value; - } + protected <%=attribute.getClassifier().getName()%>JDODO <%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; }*/ - }else{ - ObjectModelClassifier classifier = attribute.getClassifier(); + } + + public void generateSetEntityAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { + ObjectModelClassifier classifier = attribute.getClassifier(); /*{ public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException { if(!(value instanceof TopiaEntityDO)){ @@ -155,25 +150,21 @@ this.<%=attribute.getName()%> = (<%=classifier.getName()%>JDODO)value; } }*/ - - } - }else{ + } + public void generateSetEntityNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { /*{ public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { - <% if(attribute.referenceClassifier()) { %> if(!(value instanceof TopiaEntityDO)){ throw new TopiaException("Only DO can be used for entity attribute"); } - <% } %> this.<%=attribute.getName()%>.add(value); } public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { - <% if(attribute.referenceClassifier()) { %> if(!(value instanceof TopiaEntityDO)){ throw new TopiaException("Only DO can be used for entity attribute"); } - <% } %> this.<%=attribute.getName()%>.remove(value); } @@ -181,19 +172,66 @@ this.<%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; } }*/ - } - } } + public void generateOperationBody(Writer output, ObjectModelOperation operation) + throws IOException { +/*{ { + throw new TopiaException("<%=operation.getName()%>(...) is not implemented on data objects. You shall use transfer objets instead !"); + } +}*/ + } + public void generateOther(Writer output, ObjectModelClass clazz) throws IOException { + if(clazz.getSuperclasses().size() != 0){ + // on a deja genere la meme choses dans la classe mere, + // on sort tout de suite. + return; + } + generateTopiaIdOperation(output, clazz); + generateSetAllFrameworkProperties(output, clazz); + /*{ + /** + * Return entity Class managed by this service + *) + public Class getEntityClass(){ + return <%=clazz.getName()%>.class; + } - public void generateOperationBody(Writer output, ObjectModelOperation operation) - throws IOException { -/*{ { - throw new TopiaException("<%=operation.getName()%>(...) is not implemented on data objects. You shall use transfer objets instead !"); + protected String _version_; + protected java.util.Date _creationDate_; + protected java.util.Date _lastUpdateDate_; + protected TopiaUser _lastUpdateUser_; + + public String get_version_() throws TopiaException { + return _version_; + } + public void set_version_(String version) throws TopiaException { + this._version_ = version; + } + + public java.util.Date get_creationDate_() throws TopiaException { + return _creationDate_; + } + public void set_creationDate_(java.util.Date creationDate) throws TopiaException { + this._creationDate_ = creationDate; + } + + public java.util.Date get_lastUpdateDate_() throws TopiaException { + return _lastUpdateDate_; + } + public void set_lastUpdateDate_(java.util.Date lastUpdateDate) throws TopiaException { + this._lastUpdateDate_ = lastUpdateDate; + } + + public TopiaUser get_lastUpdateUser_() throws TopiaException { + return _lastUpdateUser_; + } + public void set_lastUpdateUser_(TopiaUser lastUpdateUser) throws TopiaException { + this._lastUpdateUser_ = lastUpdateUser; } }*/ } @@ -259,7 +297,7 @@ ArrayList tmpIds = new ArrayList(); for (Iterator i=entity.get<%=Util.capitalize(attribute.getName())%>().iterator(); i.hasNext();) { TopiaEntityTO te = (TopiaEntityTO)i.next(); - if (object != null){ + if (te != null){ tmpIds.add(te.toDO(done)); }else{ tmpIds.add(null); Index: topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java:1.10 topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java:1.11 --- topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java:1.10 Mon Jun 21 09:51:17 2004 +++ topia/src/java/org/codelutin/topia/generators/jdo/ObjectModelToEntityPersistenceServiceClassGenerator.java Tue Jun 22 19:01:06 2004 @@ -23,9 +23,9 @@ * * @author Cédric Pineau * Copyright Code Lutin -* @version $Revision: 1.10 $ +* @version $Revision: 1.11 $ * -* Last update : $Date: 2004/06/21 09:51:17 $ +* Last update : $Date: 2004/06/22 19:01:06 $ * by : $Author: bpoussin $ */ package org.codelutin.topia.generators.jdo; @@ -168,7 +168,7 @@ * * @return the transient transferable TopiaEntity. *) - public TopiaEntity create() throws TopiaException { + public TopiaEntityTO create() throws TopiaException { throw new TopiaException("You can't create an instance of <%=interfacez.getName()%> as it is an interface"); } }