Index: topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java:1.11 topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java:1.12 --- topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java:1.11 Wed Jun 27 09:51:54 2007 +++ topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java Tue Jul 29 14:40:45 2008 @@ -24,9 +24,9 @@ * @author Grégoire DESSARD Copyright Code Lutin, Grégoire * Dessard * - * @version $Revision: 1.11 $ + * @version $Revision: 1.12 $ * - * Mise a jour: $Date: 2007-06-27 09:51:54 $ par : $Author: ndupont $ + * Mise a jour: $Date: 2008-07-29 14:40:45 $ par : $Author: tchemit $ */ package org.codelutin.topia.generator; @@ -126,6 +126,10 @@ // 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); Index: topia2/src/java/org/codelutin/topia/generator/EntityProviderGenerator.java diff -u /dev/null topia2/src/java/org/codelutin/topia/generator/EntityProviderGenerator.java:1.1 --- /dev/null Tue Jul 29 14:40:50 2008 +++ topia2/src/java/org/codelutin/topia/generator/EntityProviderGenerator.java Tue Jul 29 14:40:45 2008 @@ -0,0 +1,126 @@ +/* + * *##% 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. ##% + */ + +/******************************************************************************* + * EntityProviderGenerator.java + * + */ + +package org.codelutin.topia.generator; + +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; + +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; + +/** + * Ce generateur permet d'avoir une classe permettant de recuperer les DAO + * sans cast. + * @author poussin + * + */ +public class EntityProviderGenerator extends ObjectModelGenerator { + + private Log log = LogFactory.getLog(DAOHelperGenerator.class); + + public EntityProviderGenerator(Generator parent) { + super(parent); + } + + @Override + public String getFilenameForModel(ObjectModel model) { + return (getProperty("defaultPackage") + ".").replace('.', + File.separatorChar) + + model.getName() + "EntityProvider.java"; + } + + @Override + public void generateFromModel(Writer output, ObjectModel model) + throws IOException { + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } +/*{package <%=getProperty("defaultPackage")%>; + +import org.codelutin.topia.persistence.TopiaEntity; +import java.util.Map; + +@SuppressWarnings({"unchecked"}) +public class <%=model.getName()%>EntityProvider { + + protected static java.util.Map, Class> cache; + + protected static Class[] entitiesClass = new Class[]{ +}*/ + String entitiesList = ""; + for (Iterator i=model.getClasses().iterator(); i.hasNext();) { + ObjectModelClass clazz = (ObjectModelClass)i.next(); + if(/*!clazz.isAbstract() && */clazz.hasStereotype(STEREOTYPE_ENTITY)){ + entitiesList += GeneratorUtil.getDOType(clazz, model) + (i.hasNext()?",":""); +/*{ <%=clazz.getQualifiedName()%>.class<%=(i.hasNext()?", ":"\n};")%> +}*/ + } + } +/*{ + public static Class getImpl(Class klazz) { + return (Class) getCache().get(klazz); + } + + protected static java.util.Map, Class> getCache() { + if (cache == null) { + initCache(); + } + return cache; + } + + private static void initCache() { + cache = new java.util.HashMap, Class>(); + for (Class entitiesClas : entitiesClass) { + String implFQN = entitiesClas.getName() + "Impl"; + try { + Class impl = (Class) Class.forName(implFQN); + cache.put(entitiesClas, impl); + } catch (ClassNotFoundException e) { + throw new RuntimeException("could not find entity implementation class " + implFQN); + } + + } + } + /** + * should have no instance + *) + protected <%=model.getName()%>EntityProvider() { + } +} +}*/ + } + +} // DAOGenerator