Index: topia2/src/java/org/codelutin/topia/generator/DAOAbstractGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/DAOAbstractGenerator.java:1.14 topia2/src/java/org/codelutin/topia/generator/DAOAbstractGenerator.java:1.15 --- topia2/src/java/org/codelutin/topia/generator/DAOAbstractGenerator.java:1.14 Mon Jul 30 14:21:08 2007 +++ topia2/src/java/org/codelutin/topia/generator/DAOAbstractGenerator.java Thu Nov 8 20:14:59 2007 @@ -24,10 +24,10 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.14 $ +* @version $Revision: 1.15 $ * -* Mise a jour: $Date: 2007-07-30 14:21:08 $ -* par : $Author: ndupont $ +* Mise a jour: $Date: 2007-11-08 20:14:59 $ +* par : $Author: thimel $ */ package org.codelutin.topia.generator; @@ -70,6 +70,11 @@ if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { return; } + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } /*{package <%=clazz.getPackageName()%>; import java.util.List; Index: topia2/src/java/org/codelutin/topia/generator/DAOGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/DAOGenerator.java:1.2 topia2/src/java/org/codelutin/topia/generator/DAOGenerator.java:1.3 --- topia2/src/java/org/codelutin/topia/generator/DAOGenerator.java:1.2 Wed Jan 4 13:21:51 2006 +++ topia2/src/java/org/codelutin/topia/generator/DAOGenerator.java Thu Nov 8 20:14:59 2007 @@ -24,10 +24,10 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.2 $ +* @version $Revision: 1.3 $ * -* Mise a jour: $Date: 2006-01-04 13:21:51 $ -* par : $Author: bpoussin $ +* Mise a jour: $Date: 2007-11-08 20:14:59 $ +* par : $Author: thimel $ */ package org.codelutin.topia.generator; @@ -56,6 +56,11 @@ if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { return; } + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } /*{package <%=clazz.getPackageName()%>; /** Index: topia2/src/java/org/codelutin/topia/generator/DAOHelperGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/DAOHelperGenerator.java:1.9 topia2/src/java/org/codelutin/topia/generator/DAOHelperGenerator.java:1.10 --- topia2/src/java/org/codelutin/topia/generator/DAOHelperGenerator.java:1.9 Wed Jun 7 15:56:01 2006 +++ topia2/src/java/org/codelutin/topia/generator/DAOHelperGenerator.java Thu Nov 8 20:14:59 2007 @@ -25,9 +25,9 @@ * * @author Arnaud Thimel * - * @version $Revision: 1.9 $ + * @version $Revision: 1.10 $ * - * Mise a jour: $Date: 2006-06-07 15:56:01 $ par : $Author: thimel $ + * Mise a jour: $Date: 2007-11-08 20:14:59 $ par : $Author: thimel $ */ package org.codelutin.topia.generator; @@ -70,8 +70,12 @@ @Override public void generateFromModel(Writer output, ObjectModel model) throws IOException { -/*{ -package <%=getProperty("defaultPackage")%>; + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } +/*{package <%=getProperty("defaultPackage")%>; import org.codelutin.topia.TopiaContext; import org.codelutin.topia.framework.TopiaContextImplementor; Index: topia2/src/java/org/codelutin/topia/generator/DAOImplGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/DAOImplGenerator.java:1.1 topia2/src/java/org/codelutin/topia/generator/DAOImplGenerator.java:1.2 --- topia2/src/java/org/codelutin/topia/generator/DAOImplGenerator.java:1.1 Wed Jan 4 13:21:51 2006 +++ topia2/src/java/org/codelutin/topia/generator/DAOImplGenerator.java Thu Nov 8 20:14:59 2007 @@ -24,10 +24,10 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.1 $ +* @version $Revision: 1.2 $ * -* Mise a jour: $Date: 2006-01-04 13:21:51 $ -* par : $Author: bpoussin $ +* Mise a jour: $Date: 2007-11-08 20:14:59 $ +* par : $Author: thimel $ */ package org.codelutin.topia.generator; @@ -56,6 +56,11 @@ if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { return; } + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } /*{package <%=clazz.getPackageName()%>; /** Index: topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java:1.26 topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java:1.27 --- topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java:1.26 Thu Dec 28 14:53:52 2006 +++ topia2/src/java/org/codelutin/topia/generator/EntityAbstractGenerator.java Thu Nov 8 20:14:59 2007 @@ -24,10 +24,10 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.26 $ +* @version $Revision: 1.27 $ * -* Mise a jour: $Date: 2006-12-28 14:53:52 $ -* par : $Author: bpoussin $ +* Mise a jour: $Date: 2007-11-08 20:14:59 $ +* par : $Author: thimel $ */ package org.codelutin.topia.generator; @@ -53,6 +53,7 @@ import org.codelutin.generator.models.object.ObjectModelClassifier; import org.codelutin.topia.framework.TopiaContextImplementor; import org.codelutin.topia.persistence.TopiaEntity; +import org.codelutin.topia.persistence.TopiaEntityAbstract; /** * Generateur d'entites abstraites. Il s'agit de l'implatation par defaut d'une @@ -81,6 +82,11 @@ if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { return; } + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } /*{package <%=clazz.getPackageName()%>; import org.apache.commons.lang.builder.ToStringBuilder; @@ -117,14 +123,20 @@ } } if (extendClass.length() == 0) { - extendClass += "org.codelutin.topia.persistence.TopiaEntityAbstract"; + extendClass += TopiaEntityAbstract.class.getName(); } /*{<%=extendClass%> implements java.io.Serializable, <%=clazz.getQualifiedName()%> { }*/ - for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { - ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); + + String svUID = GeneratorUtil.findTagValue("serialVersionUID", clazz, model); + if (svUID != null) { +/*{ public static final long serialVersionUID = <%=svUID%>; + +}*/ + } + for (ObjectModelAttribute attr : clazz.getAttributes()) { ObjectModelAttribute reverse = attr.getReverseAttribute(); // pour les asso quoi qu'il arrive il faut les lier des 2 cotes @@ -135,15 +147,21 @@ || attr.hasAssociationClass())) { continue; } + String dbName = attr.getTagValue(GeneratorUtil.TAG_DB_NAME); + if (GeneratorUtil.hasDocumentation(attr) || dbName != null) { /*{ /** }*/ - if (GeneratorUtil.hasDocumentation(attr)) { + if (GeneratorUtil.hasDocumentation(attr)) { /*{ * <%=attr.getDocumentation()%> }*/ - } + } + if (dbName != null) { /*{ * Nom de l'attribut en BD : <%=attr.getTagValue(GeneratorUtil.TAG_DB_NAME)%>. - *) }*/ + } +/*{ *) +}*/ + } String annotation = attr.getTagValue(TAG_ANNOTATION); if (annotation != null && annotation.length() > 0) { /*{ <%=annotation%> @@ -203,48 +221,48 @@ }*/ - /*{ - public List getAggregate() throws TopiaException { - List tmp = new ArrayList(); - // pour tous les attributs rechecher les composites et les class d'asso - // on les ajoute dans tmp - }*/ - for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { - ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); - if (attr.referenceClassifier() && attr.getClassifier().hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { - if (attr.isAggregate()) { - if (Util.isNMultiplicity(attr)) { - /*{ - tmp.addAll(get<%=Util.capitalize(attr.getName())%>()); - }*/ - } else { - /*{ - tmp.add(get<%=Util.capitalize(attr.getName())%>()); - }*/ - } +/*{ + public List getAggregate() throws TopiaException { + List tmp = new ArrayList(); + // pour tous les attributs rechecher les composites et les class d'asso + // on les ajoute dans tmp +}*/ + for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { + ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); + if (attr.referenceClassifier() && attr.getClassifier().hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { + if (attr.isAggregate()) { + if (Util.isNMultiplicity(attr)) { +/*{ + tmp.addAll(get<%=Util.capitalize(attr.getName())%>()); +}*/ + } else { +/*{ + tmp.add(get<%=Util.capitalize(attr.getName())%>()); +}*/ } } } - /*{ - // on refait un tour sur chaque entity de tmp pour recuperer leur - // composite - List result = new ArrayList(); - for (TopiaEntity entity : tmp) { - result.add(entity); - result.addAll(entity.getAggregate()); - } - - return result; + } +/*{ + // on refait un tour sur chaque entity de tmp pour recuperer leur + // composite + List result = new ArrayList(); + for (TopiaEntity entity : tmp) { + result.add(entity); + result.addAll(entity.getAggregate()); } - }*/ + return result; + } + +}*/ /*{ public List getComposite() throws TopiaException { List tmp = new ArrayList(); // pour tous les attributs rechecher les composites et les class d'asso // on les ajoute dans tmp - }*/ +}*/ for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); ObjectModelAttribute reverse = attr.getReverseAttribute(); @@ -279,9 +297,9 @@ // tmp.addAll(this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>); // } /*{ - tmp.addAll(((TopiaContextImplementor)getTopiaContext()) - .getDAO(<%=attr.getAssociationClass().getQualifiedName()%>.class) - .findAllByProperties("<%=reverse.getName()%>", this)); + tmp.addAll(((TopiaContextImplementor)getTopiaContext()) + .getDAO(<%=attr.getAssociationClass().getQualifiedName()%>.class) + .findAllByProperties("<%=reverse.getName()%>", this)); }*/ } } Index: topia2/src/java/org/codelutin/topia/generator/EntityImplGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/EntityImplGenerator.java:1.4 topia2/src/java/org/codelutin/topia/generator/EntityImplGenerator.java:1.5 --- topia2/src/java/org/codelutin/topia/generator/EntityImplGenerator.java:1.4 Fri Jul 21 00:47:50 2006 +++ topia2/src/java/org/codelutin/topia/generator/EntityImplGenerator.java Thu Nov 8 20:14:59 2007 @@ -24,9 +24,9 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.4 $ +* @version $Revision: 1.5 $ * -* Mise a jour: $Date: 2006-07-21 00:47:50 $ +* Mise a jour: $Date: 2007-11-08 20:14:59 $ * par : $Author: thimel $ */ @@ -84,6 +84,11 @@ isAbstract = !implementationFound; } } + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } /*{package <%=clazz.getPackageName()%>; import java.io.Serializable; Index: topia2/src/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java:1.13 topia2/src/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java:1.14 --- topia2/src/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java:1.13 Wed Jun 7 15:56:01 2006 +++ topia2/src/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java Thu Nov 8 20:14:59 2007 @@ -24,9 +24,9 @@ * Created: 12 déc. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.13 $ +* @version $Revision: 1.14 $ * -* Mise a jour: $Date: 2006-06-07 15:56:01 $ +* Mise a jour: $Date: 2007-11-08 20:14:59 $ * par : $Author: thimel $ */ @@ -144,6 +144,11 @@ } private void generateInterfaceHeader(Writer output, ObjectModelClassifier classifier) throws IOException { + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } /*{package <%=classifier.getPackageName()%>; import org.codelutin.topia.persistence.SearchFields; Index: topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java diff -u topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java:1.19 topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java:1.20 --- topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java:1.19 Wed Nov 7 17:01:57 2007 +++ topia2/src/java/org/codelutin/topia/generator/GeneratorUtil.java Thu Nov 8 20:15:00 2007 @@ -25,9 +25,9 @@ * * @author Arnaud Thimel * - * @version $Revision: 1.19 $ + * @version $Revision: 1.20 $ * - * Mise a jour: $Date: 2007-11-07 17:01:57 $ par : $Author: thimel $ + * Mise a jour: $Date: 2007-11-08 20:15:00 $ par : $Author: thimel $ */ package org.codelutin.topia.generator; @@ -41,10 +41,10 @@ import org.apache.commons.lang.StringUtils; import org.codelutin.generator.Generator; import org.codelutin.generator.Util; +import org.codelutin.generator.models.Model; import org.codelutin.generator.models.object.ObjectModel; 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.ObjectModelElement; import org.codelutin.generator.models.object.ObjectModelInterface; import org.codelutin.generator.models.object.ObjectModelOperation; @@ -111,6 +111,11 @@ public static final String TAG_ANNOTATION = "annotation"; /** + * Tag pour ajouter specifier le copyright d'un fichier + */ + public static final String TAG_COPYRIGHT = "copyright"; + + /** * Tag pour specfier le type d'acces a un champ */ public static final String TAG_ACCESS = "access"; @@ -231,19 +236,36 @@ * @return le nom du schema ou null */ public static String getSchemaName(ObjectModelElement element, ObjectModel model) { + return findTagValue(TAG_SCHEMA_NAME, element, model); + } + + /** + * Cherches et renvoie le copyright a utiliser sur le model. + * @return le texte du copyright ou null + */ + public static String getCopyright(Model model) { + return findTagValue(TAG_COPYRIGHT, null, model); + } + + /** + * Cherches et renvoie la valeur du tagvalue indique sur cet element, + * sinon sur le model. + * @return la valeur du tagValue ou null + */ + public static String findTagValue(String tagName, ObjectModelElement element, Model model) { if (element == null) { if (model != null) { - if (notEmpty(model.getTagValue(TAG_SCHEMA_NAME))) { - return model.getTagValue(TAG_SCHEMA_NAME); + if (notEmpty(model.getTagValue(tagName))) { + return model.getTagValue(tagName); } } return null; } - if (notEmpty(element.getTagValue(TAG_SCHEMA_NAME))) { - return element.getTagValue(TAG_SCHEMA_NAME); + if (notEmpty(element.getTagValue(tagName))) { + return element.getTagValue(tagName); } //On va chercher sur l'element declarant - return getSchemaName(element.getDeclaringElement(), model); + return findTagValue(tagName, element.getDeclaringElement(), model); } public static Collection getElementsWithStereotype( Index: topia2/src/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java:1.8 topia2/src/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java:1.9 --- topia2/src/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java:1.8 Mon Nov 5 17:51:33 2007 +++ topia2/src/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java Thu Nov 8 20:15:00 2007 @@ -48,7 +48,7 @@ * Created: 19 juin 2007 * * @author dupont -* @version $Revision: 1.8 $ +* @version $Revision: 1.9 $ * * Le service abstrait etend TopiaApplicationServiceAbstract et implemente * l'interface du service. @@ -59,7 +59,7 @@ * @see ServiceInterfaceGenerator * @see TopiaApplicationServiceAbstract * -* Mise a jour: $Date: 2007-11-05 17:51:33 $ +* Mise a jour: $Date: 2007-11-08 20:15:00 $ * par : $Author: thimel $ */ public class ServiceAbstractGenerator extends ObjectModelGenerator { @@ -105,6 +105,11 @@ } private void generateInterfaceHeader(Writer output, ObjectModelClassifier classifier) throws IOException { + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } /*{package <%=classifier.getPackageName()%>; import java.util.Arrays; Index: topia2/src/java/org/codelutin/topia/generator/ServiceImplGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/ServiceImplGenerator.java:1.2 topia2/src/java/org/codelutin/topia/generator/ServiceImplGenerator.java:1.3 --- topia2/src/java/org/codelutin/topia/generator/ServiceImplGenerator.java:1.2 Tue Jul 17 16:18:30 2007 +++ topia2/src/java/org/codelutin/topia/generator/ServiceImplGenerator.java Thu Nov 8 20:15:00 2007 @@ -44,7 +44,7 @@ * Created: 19 juin 2007 * * @author ndupont -* @version $Revision: 1.2 $ +* @version $Revision: 1.3 $ * * Genere l'entete du service implante. * @@ -56,8 +56,8 @@ * @see ServiceInterfaceGenerator * @see TopiaApplicationServiceAbstract * -* Mise a jour: $Date: 2007-07-17 16:18:30 $ -* par : $Author: ndupont $ +* Mise a jour: $Date: 2007-11-08 20:15:00 $ +* par : $Author: thimel $ */ public class ServiceImplGenerator extends ObjectModelGenerator { @@ -112,6 +112,11 @@ } private void generateInterfaceHeader(Writer output, ObjectModelClassifier classifier) throws IOException { + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } /*{package <%=classifier.getPackageName()%>;}*/ if (GeneratorUtil.hasDocumentation(classifier)) { Index: topia2/src/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java:1.7 topia2/src/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java:1.8 --- topia2/src/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java:1.7 Mon Nov 5 17:51:33 2007 +++ topia2/src/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java Thu Nov 8 20:15:00 2007 @@ -51,7 +51,7 @@ * Created: 14 juin 2007 * * @author ndupont -* @version $Revision: 1.7 $ +* @version $Revision: 1.8 $ * * L'interface du service etend TopiaApplicationService * @@ -68,7 +68,7 @@ * * @see TopiaApplicationService * -* Mise a jour: $Date: 2007-11-05 17:51:33 $ +* Mise a jour: $Date: 2007-11-08 20:15:00 $ * par : $Author: thimel $ */ public class ServiceInterfaceGenerator extends ObjectModelGenerator { @@ -128,6 +128,11 @@ } private void generateInterfaceHeader(Writer output, ObjectModelClassifier classifier) throws IOException { + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } /*{package <%=classifier.getPackageName()%>; import java.util.List; Index: topia2/src/java/org/codelutin/topia/generator/TapestryWebGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/TapestryWebGenerator.java:1.3 topia2/src/java/org/codelutin/topia/generator/TapestryWebGenerator.java:1.4 --- topia2/src/java/org/codelutin/topia/generator/TapestryWebGenerator.java:1.3 Thu Aug 9 14:22:14 2007 +++ topia2/src/java/org/codelutin/topia/generator/TapestryWebGenerator.java Thu Nov 8 20:15:00 2007 @@ -45,10 +45,10 @@ * * @see org.codelutin.generator.StateModelGenerator * @author chatellier - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Last update : $Date: 2007-08-09 14:22:14 $ - * By : $Author: ndupont $ + * Last update : $Date: 2007-11-08 20:15:00 $ + * By : $Author: thimel $ */ public class TapestryWebGenerator extends StateModelGenerator { @@ -57,7 +57,9 @@ /** Already asssigned use case states names */ protected List assignedUseCaseStateNames; - + + protected StateModel model; + /** * Constructeur * @param parent Generateur parent @@ -74,6 +76,8 @@ */ public void generate(StateModel stateModel, File destDir) throws IOException { + this.model = stateModel; + // pour tous les diagramme du model for (StateModelStateChart chart : stateModel.getStateCharts()) { generate(chart,chart.getStates(),destDir); @@ -199,7 +203,12 @@ * @throws IOException */ protected void generateFromSimpleState(Writer output, StateModelStateChart chart, StateModelState state) throws IOException { - /*{// Automatically generated by LutinGenerator + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } +/*{// Automatically generated by LutinGenerator package <%=getPackageFromState(chart)%>; import org.apache.tapestry.annotations.InjectPage; Index: topia2/src/java/org/codelutin/topia/generator/EntityDTOGenerator.java diff -u /dev/null topia2/src/java/org/codelutin/topia/generator/EntityDTOGenerator.java:1.1 --- /dev/null Thu Nov 8 20:15:05 2007 +++ topia2/src/java/org/codelutin/topia/generator/EntityDTOGenerator.java Thu Nov 8 20:14:59 2007 @@ -0,0 +1,283 @@ +/* *##% +* Copyright (C) 2002, 2003, 2004, 2005 Code Lutin, +* Cédric Pineau, Benjamin Poussin, +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +/* * +* EntityAbstractGenerator.java +* +* Created: 12 déc. 2005 +* +* @author Arnaud Thimel +* @version $Revision: 1.1 $ +* +* Mise a jour: $Date: 2007-11-08 20:14:59 $ +* par : $Author: thimel $ +*/ + +package org.codelutin.topia.generator; + +import static org.codelutin.topia.generator.GeneratorUtil.TAG_ANNOTATION; +import static org.codelutin.topia.generator.GeneratorUtil.hasUnidirectionalRelationOnAbstractType; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.Util; +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; + +/** + * Generateur d'entites abstraites. Il s'agit de l'implatation par defaut d'une + * entite. Les classes generees sont surchargees par un XXXImpl lorsque l'entite + * n'est pas abstraite. La surcharge peut etre ecrite par l'utilisateur. + */ +public class EntityDTOGenerator extends ObjectModelGenerator { + + /** + * Logger for this class + */ + private static final Log log = LogFactory + .getLog(EntityDTOGenerator.class); + + public EntityDTOGenerator() { + super(); + } + + @Override + public String getFilenameForClass(ObjectModelClass clazz) { + return clazz.getQualifiedName().replace('.', File.separatorChar) + "DTO.java"; + } + + public boolean isEntity(String type) { + ObjectModelClassifier clazz = model.getClassifier(type); + if (clazz == null) { + return false; + } + return clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY); + } + + @Override + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { + return; + } + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } +/*{package <%=clazz.getPackageName()%>; + +import org.apache.commons.lang.builder.ToStringBuilder; + +/** + * Implantation DTO pour l'entité <%=Util.capitalize(clazz.getName())%>. + *) +public class <%=clazz.getName()%>DTO }*/ + String extendClass = ""; + for (Iterator i=clazz.getSuperclasses().iterator(); i.hasNext();) { + ObjectModelClassifier parent = (ObjectModelClassifier)i.next(); + extendClass += parent.getQualifiedName() + "DTO"; + if (i.hasNext()) { + extendClass += ", "; + } + } + if (extendClass.length() > 0) { + /*{extends <%=extendClass%> }*/ + } + + /*{implements java.io.Serializable { + +}*/ + + String svUID = GeneratorUtil.findTagValue("dto-serialVersionUID", clazz, model); + if (svUID != null) { +/*{ public static final long serialVersionUID = <%=svUID%>; + +}*/ + } + for (ObjectModelAttribute attr : clazz.getAttributes()) { + ObjectModelAttribute reverse = attr.getReverseAttribute(); + + // pour les asso quoi qu'il arrive il faut les lier des 2 cotes + // pour pouvoir supprimer en cascade l'asso lors de la suppression + // d'un des cotes + if (!(attr.isNavigable() + || hasUnidirectionalRelationOnAbstractType(reverse, model) + || attr.hasAssociationClass())) { + continue; + } + if (GeneratorUtil.hasDocumentation(attr)) { +/*{ /** + * <%=attr.getDocumentation()%> + *) +}*/ + } + String annotation = attr.getTagValue(TAG_ANNOTATION); + if (annotation != null && annotation.length() > 0) { +/*{ <%=annotation%> +}*/ + } + if (!Util.isNMultiplicity(attr)) { + if (!attr.hasAssociationClass()) { +/*{ <%=attr.getVisibility()%> <%=attr.getType()%><%=(isEntity(attr.getType())?"DTO":"")%> <%=attr.getName()%>; + +}*/ + } else { + String assocAttrName = GeneratorUtil.getAssocAttrName(attr); +/*{ <%=attr.getVisibility()%> <%=attr.getAssociationClass().getQualifiedName()%>DTO <%=Util.toLowerCaseFirstLetter(assocAttrName)%>; + +}*/ + } + } else { + if (!attr.hasAssociationClass()) { +/*{ <%=attr.getVisibility()%> <%=attr.getType()%><%=(isEntity(attr.getType())?"DTO":"")%>[] <%=attr.getName()%>; + +}*/ + } else { + String assocAttrName = GeneratorUtil.getAssocAttrName(attr); +/*{ <%=attr.getVisibility()%> <%=attr.getAssociationClass().getQualifiedName()%>DTO[] <%=Util.toLowerCaseFirstLetter(assocAttrName)%>; + +}*/ + } + } + } + + //Déclaration des attributs d'une classe d'associations + if (clazz instanceof ObjectModelAssociationClass) { + ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz; + for (Iterator i = assoc.getParticipantsAttributes().iterator(); i.hasNext(); ) { + ObjectModelAttribute attr = (ObjectModelAttribute) i.next(); + if (attr != null) { +/*{ <%=attr.getVisibility()%> <%=attr.getType()%><%=(isEntity(attr.getType())?"DTO":"")%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>; + +}*/ + } + } + } + +/*{ /** + * Constructeur de <%=clazz.getName()%>DTO par défaut. + *) + public <%=clazz.getName()%>DTO() {} + +}*/ + + for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { + ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); + ObjectModelAttribute reverse = attr.getReverseAttribute(); + + if (!(attr.isNavigable() + || hasUnidirectionalRelationOnAbstractType(reverse, model))) { + continue; + } + if (!Util.isNMultiplicity(attr)) { + if (!attr.hasAssociationClass()) { +/*{ public void set<%=Util.capitalize(attr.getName())%>(<%=attr.getType()%><%=(isEntity(attr.getType())?"DTO":"")%> value) { + this.<%=attr.getName()%> = value; + } + + public <%=attr.getType()%><%=(isEntity(attr.getType())?"DTO":"")%> get<%=Util.capitalize(attr.getName())%>() { + return <%=attr.getName()%>; + } + +}*/ + } else { + String assocAttrName = GeneratorUtil.getAssocAttrName(attr); + if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); } +/*{ public void set<%=Util.capitalize(assocAttrName)%>(<%=attr.getAssociationClass().getQualifiedName()%>DTO association) { + this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%> = association; + } + + public <%=attr.getAssociationClass().getQualifiedName()%>DTO get<%=Util.capitalize(assocAttrName)%>() { + return <%=Util.toLowerCaseFirstLetter(assocAttrName)%>; + } + +}*/ + } + } else { //NMultiplicity + if (!attr.hasAssociationClass()) { //Méthodes remplacées par des accesseurs sur les classes d'assoc +/*{ public void set<%=Util.capitalize(attr.getName())%>(<%=attr.getType()%><%=(isEntity(attr.getType())?"DTO":"")%>[] values) { + this.<%=attr.getName()%> = values; + } + +}*/ + } else { + String assocAttrName = GeneratorUtil.getAssocAttrName(attr); + if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); } +/*{ public void set<%=Util.capitalize(assocAttrName)%>(<%=attr.getAssociationClass().getQualifiedName()%>DTO[] values) { + this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%> = values; + } + +}*/ + } + if (!attr.hasAssociationClass()) { +/*{ public <%=attr.getType()%><%=(isEntity(attr.getType())?"DTO":"")%>[] get<%=Util.capitalize(attr.getName())%>() { + return this.<%=attr.getName()%>; + } + +}*/ + } else { + String assocAttrName = GeneratorUtil.getAssocAttrName(attr); + if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); } +/*{ public <%=attr.getAssociationClass().getQualifiedName()%>DTO[] get<%=Util.capitalize(assocAttrName)%>() { + return this.<%=Util.toLowerCaseFirstLetter(assocAttrName)%>; + } + +}*/ + } + } + } + +/*{ /* (non-Javadoc) + * @see java.lang.Object#toString() + *) + public String toString() { + String result = new ToStringBuilder(this). +}*/ + for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { + ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); + //FIXME possibilité de boucles (non directes) + ObjectModelClass attrEntity = null; + if (model.hasClass(attr.getType())) { + attrEntity = model.getClass(attr.getType()); + } + boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)); + ObjectModelAttribute reverse = attr.getReverseAttribute(); + if ((isEntity && (reverse == null || !reverse.isNavigable()) && !attr.hasAssociationClass()) || (!isEntity)) { +/*{ append("<%=attr.getName()%>", this.<%=attr.getName()%>). +}*/ + } + } +/*{ toString(); + return result; + } + +} //<%=clazz.getName()%>DTO +}*/ + } + +} //EntityDTOGenerator