Author: tchemit Date: 2008-11-01 20:05:20 +0000 (Sat, 01 Nov 2008) New Revision: 1204 Added: topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java Modified: topia/trunk/changelog topia/trunk/pom.xml topia/trunk/src/main/java/org/codelutin/topia/generator/DAOAbstractGenerator.java topia/trunk/src/main/java/org/codelutin/topia/generator/DAOGenerator.java topia/trunk/src/main/java/org/codelutin/topia/generator/DAOHelperGenerator.java topia/trunk/src/main/java/org/codelutin/topia/generator/DAOImplGenerator.java topia/trunk/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java topia/trunk/src/main/java/org/codelutin/topia/generator/EntityImplGenerator.java topia/trunk/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java topia/trunk/src/main/java/org/codelutin/topia/generator/EntityProviderGenerator.java topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java topia/trunk/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java topia/trunk/src/main/java/org/codelutin/topia/generator/TopiaMetaGenerator.java Log: - bump lutingenerator to 0.61 - add a EntityEnum to have a generic way to access Entities. - improve generators : - can exclude some generators on TopiaMetaGenerator - refactor TopiaMetaGenerator to use a simple List of Generator to launch - refactor Generators to have a default public constructor Modified: topia/trunk/changelog =================================================================== --- topia/trunk/changelog 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/changelog 2008-11-01 20:05:20 UTC (rev 1204) @@ -1,4 +1,11 @@ ver-2-0-28 ?? 2008?? + * 20081101 [chemit] bump lutingenerator to 0.61 + * 20081101 [chemit] add a EntityEnum to have a generic way to access Entities. + * 20081101 [chemit] improve generators : + - can exclude some generators on TopiaMetaGenerator + - refactor TopiaMetaGenerator to use a simple List of Generator to launch + - refactor Generators to have a default public constructor + * 20081029 [chemit] fix infinitive recursion on method findByPrimaryKey and findByProperty in TopiaDAODeleagtor class * 20081026 [chemit] add dbName of table if explicit in javadoc * 20081024 [chemit] fix bug when no entity defined in model Modified: topia/trunk/pom.xml =================================================================== --- topia/trunk/pom.xml 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/pom.xml 2008-11-01 20:05:20 UTC (rev 1204) @@ -27,7 +27,7 @@ <dependency> <groupId>org.codelutin</groupId> <artifactId>lutingenerator</artifactId> - <version>0.60</version> + <version>0.61-SNAPSHOT</version> <scope>compile</scope> </dependency> Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/DAOAbstractGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/DAOAbstractGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/DAOAbstractGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -58,6 +58,10 @@ */ public class DAOAbstractGenerator extends ObjectModelGenerator { + public DAOAbstractGenerator() { + super(); + } + public DAOAbstractGenerator(Generator parent) { super(parent); } @@ -136,7 +140,7 @@ public void delete(E entity) throws TopiaException { }*/ - String providerFQN = getProperty("defaultPackage") + "." + model.getName() + "EntityProvider.getImpl"; + String providerFQN = getProperty("defaultPackage") + "." + model.getName() + "EntityEnum.getImplementationClass"; for (ObjectModelAttribute attr : clazz.getAttributes()) { ObjectModelAttribute reverse = attr.getReverseAttribute(); if (!attr.hasAssociationClass() && reverse != null && reverse.isNavigable() @@ -146,7 +150,7 @@ /*{ { - List<<%=attr.getType()%>> list = ((TopiaContextImplementor)getContext()).getHibernate().createSQLQuery( + List<<%=attr.getType()%>> list = getContext().getHibernate().createSQLQuery( "SELECT {main.*} " + "from <%=GeneratorUtil.getDBName(attr.getClassifier())%> main, <%=GeneratorUtil.getManyToManyTableName(attr)%> secondary " + "where main.topiaid=secondary.<%=GeneratorUtil.getDBName(attr)%>" + @@ -164,7 +168,7 @@ // TODO peut-etre qu'hibernate est capable de faire ca tout seul ? /*{ { - List<<%=attr.getType()%>> list = ((TopiaContextImplementor)getContext()) + List<<%=attr.getType()%>> list = getContext() .getDAO(<%=attr.getType()%>.class) .findAllByProperties("<%=reverse.getName()%>", entity); for (<%=attr.getType()%> item : list) { Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/DAOGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/DAOGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/DAOGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -39,6 +39,10 @@ public class DAOGenerator extends ObjectModelGenerator { + public DAOGenerator() { + super(); + } + public DAOGenerator(Generator parent) { super(parent); } Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/DAOHelperGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/DAOHelperGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/DAOHelperGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -47,12 +47,17 @@ * Ce generateur permet d'avoir une classe permettant de recuperer les DAO * sans cast. * @author poussin - * + * @see Deprecated you should prefer use the {@link EntityEnumGenerator} */ +@Deprecated public class DAOHelperGenerator extends ObjectModelGenerator { private Log log = LogFactory.getLog(DAOHelperGenerator.class); + public DAOHelperGenerator() { + super(); + } + public DAOHelperGenerator(Generator parent) { super(parent); } Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/DAOImplGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/DAOImplGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/DAOImplGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -39,6 +39,10 @@ public class DAOImplGenerator extends ObjectModelGenerator { + public DAOImplGenerator() { + super(); + } + public DAOImplGenerator(Generator parent) { super(parent); } Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -65,6 +65,10 @@ private static final Log log = LogFactory .getLog(EntityAbstractGenerator.class); + public EntityAbstractGenerator() { + super(); + } + public EntityAbstractGenerator(Generator parent) { super(parent); } Copied: topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java (from rev 1199, topia/trunk/src/main/java/org/codelutin/topia/generator/EntityProviderGenerator.java) =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java (rev 0) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -0,0 +1,220 @@ +/* *##% ToPIA - Tools for Portable and Independent Architecture + * Copyright (C) 2004 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ + +/******************************************************************************* + * EntityProviderGenerator.java + * + */ + +package org.codelutin.topia.generator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.generator.Generator; +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelClass; +import static org.codelutin.topia.generator.GeneratorUtil.STEREOTYPE_ENTITY; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +/** + * Ce generateur permet d'avoir une énumeration sur les entités du model. + * <p/> + * Chaque entité est associée à un {@link org.codelutin.topia.persistence.TopiaEntityEnumEntry}. + * + * @author chemit + * @see org.codelutin.topia.persistence.TopiaEntityEnumEntry + */ +public class EntityEnumGenerator extends ObjectModelGenerator { + + private Log log = LogFactory.getLog(EntityEnumGenerator.class); + + public EntityEnumGenerator() { + super(); + } + + public EntityEnumGenerator(Generator parent) { + super(parent); + } + + @Override + public String getFilenameForModel(ObjectModel model) { + return (getProperty("defaultPackage") + ".").replace('.', + File.separatorChar) + + model.getName() + "EntityEnum.java"; + } + + @Override + public void generateFromModel(Writer output, ObjectModel model) + throws IOException { + String copyright = GeneratorUtil.getCopyright(model); + String modelName = model.getName(); + String className = modelName + "EntityEnum"; + if (log.isDebugEnabled()) { + log.debug("generating " + className); + } + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } +/*{package <%=getProperty("defaultPackage")%>; + +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.persistence.TopiaDAO; +import org.codelutin.topia.persistence.TopiaEntity; +import org.codelutin.topia.persistence.TopiaEntityEnumEntry; + + +@SuppressWarnings({"unchecked"}) +}*/ + +/*{public enum <%=className%> { +}*/ + if (model.getClasses().isEmpty()) { +/*{ + TopiaEntity(TopiaEntity.class); +}*/ + } else { + for (Iterator i = model.getClasses().iterator(); i.hasNext();) { + ObjectModelClass clazz = (ObjectModelClass) i.next(); + if (clazz.hasStereotype(STEREOTYPE_ENTITY)) { + boolean hasNext = i.hasNext(); + if (log.isDebugEnabled()) { + log.debug("generating entry " + clazz + " (hasNext:" + hasNext + ")"); + } +/*{ <%=clazz.getName()%>(<%=clazz.getQualifiedName()%>.class)<%=(hasNext?",":";")%> +}*/ + } + } + } +/*{ + private TopiaEntityEnumEntry<TopiaEntity> entry; + + <%=className%>(Class<? extends TopiaEntity> contractClass) { + entry = new TopiaEntityEnumEntry(contractClass); + } + + public Class<? extends TopiaEntity> getContractClass() { + return entry.getContractClass(); + } + + public Class<? extends TopiaEntity> getImplementationClass() { + return entry.getImplementationClass(); + } + + public TopiaDAO getDAO(TopiaContext ctxt) throws TopiaException { + return entry.getDAO(ctxt); + } + + public TopiaEntity create(TopiaContext ctxt) throws IllegalAccessException, InstantiationException, TopiaException { + return entry.create(ctxt); + } + + public TopiaEntity update(TopiaEntity entity, TopiaContext ctxt) throws IllegalAccessException, InstantiationException, TopiaException { + return entry.update(entity, ctxt); + } + + public void delete(TopiaEntity entity, TopiaContext ctxt) throws IllegalAccessException, InstantiationException, TopiaException { + entry.delete(entity, ctxt); + } + + public static <%=className%> valueOf(TopiaEntity entity) { + return valueOf(entity.getClass()); + } + + public static <%=className%> valueOf(Class<?> klass) { + if (klass.isInterface()) { + return <%=modelName%>EntityEnum.valueOf(klass.getSimpleName()); + } + for (<%=className%> entityEnum : <%=className%>.values()) { + if (entityEnum.getContractClass().isAssignableFrom(klass)) { + return entityEnum; + } + } + throw new IllegalArgumentException("no entity defined for the class " + klass + " in : " + java.util.Arrays.toString(<%=className%>.values())); + } + + public static <T extends TopiaEntity> Class<T> getContractClass(Class<T> klass) throws TopiaException { + <%=className%> e = <%=className%>.valueOf(klass); + return (Class<T>) e.getContractClass(); + } + + public static <T extends TopiaEntity> Class<T> getImplementationClass(Class<T> klass) throws TopiaException { + <%=className%> e = <%=className%>.valueOf(klass); + return (Class<T>) e.getImplementationClass(); + } + + public static Class<? extends TopiaEntity>[] getContractClasses() { + <%=className%>[] values = <%=className%>.values(); + Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) java.lang.reflect.Array.newInstance(Class.class, values.length); + for (int i = 0; i < values.length; i++) { + result[i] = values[i].getContractClass(); + } + return result; + } + + public static Class<? extends TopiaEntity>[] getImplementationClasses() { + <%=className%>[] values = <%=className%>.values(); + Class<? extends TopiaEntity>[] result = (Class<? extends TopiaEntity>[]) java.lang.reflect.Array.newInstance(Class.class, values.length); + for (int i = 0; i < values.length; i++) { + result[i] = values[i].getImplementationClass(); + } + return result; + } + + public static String getImplementationClassesAsString() { + StringBuilder buffer = new StringBuilder(); + for (Class<? extends TopiaEntity> aClass : getImplementationClasses()) { + buffer.append(',').append(aClass.getName()); + } + return buffer.substring(1); + } + + public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDao(Class<T> klass, TopiaContext ctxt) throws TopiaException { + <%=className%> e = <%=className%>.valueOf(klass); + return (D) e.getDAO(ctxt); + } + + public static <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDao(T entity, TopiaContext ctxt) throws TopiaException { + <%=className%> e = <%=className%>.valueOf(entity); + return (D) e.getDAO(ctxt); + } + + public static <T extends TopiaEntity> T doCreate(Class<T> klass, TopiaContext ctxt) throws TopiaException, InstantiationException, IllegalAccessException { + <%=className%> e = <%=className%>.valueOf(klass); + return (T) e.create(ctxt); + } + + public static <T extends TopiaEntity> T doUpdate(T entity, TopiaContext ctxt) throws TopiaException, InstantiationException, IllegalAccessException { + <%=className%> e = <%=className%>.valueOf(entity); + return (T) e.update(entity, ctxt); + } + + public static <T extends TopiaEntity> void doDelete(T entity, TopiaContext ctxt) throws TopiaException, InstantiationException, IllegalAccessException { + <%=className%> e = <%=className%>.valueOf(entity); + e.delete(entity, ctxt); + } +} +}*/ + } + +} // EntityEnumGenerator Property changes on: topia/trunk/src/main/java/org/codelutin/topia/generator/EntityEnumGenerator.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/EntityImplGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/EntityImplGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/EntityImplGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -41,6 +41,10 @@ public class EntityImplGenerator extends ObjectModelGenerator { + public EntityImplGenerator() { + super(); + } + public EntityImplGenerator(Generator parent) { super(parent); } Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -65,6 +65,10 @@ private static final Log log = LogFactory .getLog(EntityInterfaceGenerator.class); + public EntityInterfaceGenerator() { + super(); + } + public EntityInterfaceGenerator(Generator parent) { super(parent); } Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/EntityProviderGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/EntityProviderGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/EntityProviderGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -43,11 +43,17 @@ * * @author chemit * + * @see Deprecated you should prefer use the {@link EntityEnumGenerator} */ +@Deprecated public class EntityProviderGenerator extends ObjectModelGenerator { - private Log log = LogFactory.getLog(DAOHelperGenerator.class); + private Log log = LogFactory.getLog(EntityProviderGenerator.class); + public EntityProviderGenerator() { + super(); + } + public EntityProviderGenerator(Generator parent) { super(parent); } Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -63,7 +63,11 @@ private static final Log log = LogFactory .getLog(ServiceAbstractGenerator.class); - + + public ServiceAbstractGenerator() { + super(); + } + public ServiceAbstractGenerator(Generator parent) { super(parent); } Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceImplGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -63,15 +63,21 @@ */ private static final Log log = LogFactory .getLog(ServiceImplGenerator.class); - + + public ServiceImplGenerator() { + super(); + } + public ServiceImplGenerator(Generator parent) { super(parent); } + @Override public String getFilenameForInterface(ObjectModelInterface interfacez) { return interfacez.getQualifiedName().replace('.', File.separatorChar) + "Impl.java"; } + @Override public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException { if (!interfacez.hasStereotype(GeneratorUtil.STEREOTYPE_SERVICE)) { Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/ServiceInterfaceGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -80,15 +80,21 @@ // methodes du service <signature methode> private List<String> methods = new ArrayList<String>(); - + + public ServiceInterfaceGenerator() { + super(); + } + public ServiceInterfaceGenerator(Generator parent) { super(parent); } + @Override public String getFilenameForInterface(ObjectModelInterface interfacez) { return interfacez.getQualifiedName().replace('.', File.separatorChar) + ".java"; } + @Override public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException { if (!interfacez.hasStereotype(GeneratorUtil.STEREOTYPE_SERVICE)) { Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -60,8 +60,7 @@ protected StateModel model; /** - * Constructeur - * @param parent Generateur parent + * Default Constructeur */ public TapestryWebGenerator() { assignedUseCaseStateNames = new ArrayList<String>(); @@ -73,7 +72,8 @@ * @param stateModel Le modele d'état * @param destDir le dossier de destination */ - public void generate(StateModel stateModel, File destDir) throws IOException { + @Override + public void generate(StateModel stateModel, File destDir) throws IOException { this.model = stateModel; Modified: topia/trunk/src/main/java/org/codelutin/topia/generator/TopiaMetaGenerator.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/generator/TopiaMetaGenerator.java 2008-11-01 15:20:26 UTC (rev 1203) +++ topia/trunk/src/main/java/org/codelutin/topia/generator/TopiaMetaGenerator.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -17,24 +17,19 @@ /******************************************************************************* * ObjectModelToEntityGenerator.java - * + * * Created: 3 juil. 2004 - * + * * @author Grégoire DESSARD <dessard@codelutin.com> Copyright Code Lutin, Grégoire * Dessard - * + * * @version $Revision$ - * + * * Mise a jour: $Date$ par : $Author$ */ package org.codelutin.topia.generator; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codelutin.generator.ObjectModelGenerator; @@ -43,6 +38,12 @@ import org.codelutin.generator.models.object.validator.ClassNamesValidator; import org.codelutin.generator.models.object.validator.ObjectModelValidator; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + /** * Cette classe est un Generateur qui constitue le point d'entree dans ToPIA. * Il repercute la generation de code sur chacun des generateurs de ToPIA en se @@ -51,8 +52,32 @@ public class TopiaMetaGenerator extends ObjectModelGenerator { protected static final Log log = LogFactory.getLog(TopiaMetaGenerator.class); + /** + * la liste des generateurs par defaut a utiliser + */ + protected static final List<Class<? extends ObjectModelGenerator>> DEFAULT_GENERATORS = + java.util.Collections.unmodifiableList(Arrays.asList( + + EntityInterfaceGenerator.class, + EntityAbstractGenerator.class, + EntityAbstractGenerator.class, + EntityImplGenerator.class, + EntityHibernateMappingGenerator.class, - private boolean validateModel(ObjectModel model) { + DAOGenerator.class, + DAOImplGenerator.class, + DAOAbstractGenerator.class, + + EntityProviderGenerator.class, + EntityEnumGenerator.class, + DAOHelperGenerator.class, + + ServiceInterfaceGenerator.class, + ServiceAbstractGenerator.class, + ServiceImplGenerator.class + )); + + protected boolean validateModel(ObjectModel model) { List<ObjectModelValidator> validators = new ArrayList<ObjectModelValidator>(); AttributeNamesValidator attrValidator = new AttributeNamesValidator(model); @@ -82,6 +107,7 @@ return isValid; } + @Override public void generate(ObjectModel model, File destDir) throws IOException { //On n'empeche pas la génération si le modèle n'est pas valide @@ -89,59 +115,26 @@ generatePersistence(model, destDir); } - + public void generatePersistence(ObjectModel model, File destDir) throws IOException { + for (Class<? extends ObjectModelGenerator> generatorClass : DEFAULT_GENERATORS) { + ObjectModelGenerator generator; + if (excludeTemplates.contains(generatorClass.getName())) { + // exclude generator + log.info("exclude generateur "+generatorClass); + continue; + } + try { + generator = generatorClass.newInstance(); + generator.setParent(this); - ObjectModelGenerator gen = null; - - // Génère les interfaces des entites - gen = new EntityInterfaceGenerator(this); - gen.generate(model, destDir); + } catch (Exception e) { + // should never happens + log.error(e); + throw new RuntimeException(e); + } + generator.generate(model, destDir); + } + } - // Génère les POJO des entités - gen = new EntityAbstractGenerator(this); - gen.generate(model, destDir); - - // Génère les Impl associés aux entités - gen = new EntityImplGenerator(this); - gen.generate(model, destDir); - - // Génère les mapping associés aux entités - gen = new EntityHibernateMappingGenerator(this); - gen.generate(model, destDir); - - // Génère les DAO par defaut des entités - gen = new DAOImplGenerator(this); - gen.generate(model, destDir); - - // Génère les DAO par defaut des entités - gen = new DAOGenerator(this); - gen.generate(model, destDir); - - // Génère les DAO des entités - gen = new DAOAbstractGenerator(this); - gen.generate(model, destDir); - - // Génère les DAOHelper des entités - gen = new DAOHelperGenerator(this); - gen.generate(model, destDir); - - // Génère le EntityProvider des entités (qui casse les dépendances vers les implantations) - gen = new EntityProviderGenerator(this); - gen.generate(model, destDir); - - // Génère les interfaces des services - gen = new ServiceInterfaceGenerator(this); - gen.generate(model, destDir); - - // Génère les classes abstraites des services - gen = new ServiceAbstractGenerator(this); - gen.generate(model, destDir); - - // Génère les classes impl des services - gen = new ServiceImplGenerator(this); - gen.generate(model, destDir); - - } - -} //MaloMetaGenerator +} //TopiaMetaGenerator Added: topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java =================================================================== --- topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java (rev 0) +++ topia/trunk/src/main/java/org/codelutin/topia/persistence/TopiaEntityEnumEntry.java 2008-11-01 20:05:20 UTC (rev 1204) @@ -0,0 +1,61 @@ +package org.codelutin.topia.persistence; + +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.framework.TopiaContextImplementor; + +/** @author chemit */ +public class TopiaEntityEnumEntry<T extends TopiaEntity> implements java.io.Serializable { + + /** the contract class of the entity's type. */ + protected Class<T> contractClass; + + /** the concrete implementation class of the entity's type. */ + protected Class<T> implementationClass; + + private static final long serialVersionUID = 1L; + + public TopiaEntityEnumEntry(Class<T> contractClass) { + this.contractClass = contractClass; + } + + public Class<T> getContractClass() { + return contractClass; + } + + @SuppressWarnings({"unchecked"}) + public Class<T> getImplementationClass() { + if (implementationClass == null) { + try { + implementationClass = (Class<T>) Class.forName(contractClass.getName() + "Impl"); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("could not find implementation for entity contract " + contractClass); + } + } + return implementationClass; + } + + public TopiaDAO<T> getDAO(TopiaContext ctxt) throws TopiaException { + TopiaContextImplementor ci = (TopiaContextImplementor) ctxt; + return ci.getDAO(contractClass); + } + + public T create(TopiaContext ctxt) throws IllegalAccessException, InstantiationException, TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + T newInstance = dao.create(); + // attach topia context to entity (to allow propertyChangeSupport for entity) + ((TopiaEntityAbstract)newInstance).setTopiaContext(ctxt); + return newInstance; + } + + public T update(T entity, TopiaContext ctxt) throws IllegalAccessException, InstantiationException, TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + return dao.update(entity); + } + + public void delete(T entity, TopiaContext ctxt) throws IllegalAccessException, InstantiationException, TopiaException { + TopiaDAO<T> dao = getDAO(ctxt); + dao.delete(entity); + } + +}