Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java:1.1 --- /dev/null Fri Aug 6 17:51:35 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceImplGenerator.java Fri Aug 6 17:51:30 2004 @@ -0,0 +1,165 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * OjectModelToEntityPersistenceServiceImplGenerator.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/08/06 17:51:30 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia.generators; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; +import java.util.Collection; + +import org.codelutin.generator.Generator; +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.topia.generators.Util; +import java.util.LinkedList; + +public class ObjectModelToEntityPersistenceServiceImplGenerator extends TopiaAbstractObjectModelGenerator { // OjectModelToEntityPersistenceServiceImplGenerator + + public ObjectModelToEntityPersistenceServiceImplGenerator(){ + super(); + } + + public ObjectModelToEntityPersistenceServiceImplGenerator(Generator parent){ + super(parent); + } + + public String getFilenameForClassifier(ObjectModelClassifier clazz) { + return super.getFilenameForClassifier(clazz) + "PersistenceServiceImpl.java"; + } + + public boolean accept(ObjectModelClassifier clazz){ + return Util.isEntity(clazz) && clazz instanceof ObjectModelClass; + } + + ////////////////////////////////////////////////////////////////////// + // C L A S S D E C L A R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateClassDeclaration(Writer output, ObjectModelClassifier clazz) throws IOException { + Collection operations = new LinkedList(); + operations.addAll(clazz.getOperations()); + operations.addAll(clazz.getAllOtherOperations(false)); +/*{ +/** +<%=clazz.getDocumentation()%> + *) +public class <%=clazz.getName() + "PersistenceServiceImpl"%> extends }*/ + if(clazz instanceof ObjectModelClass){ + Iterator i=((ObjectModelClass)clazz).getSuperclasses().iterator(); + if (i.hasNext()) { + ObjectModelClass superclass = (ObjectModelClass) i.next(); + /*{<%=superclass.getName()%>PersistenceServiceImpl}*/ + }else{ + /*{AbstractTopiaPersistenceService}*/ + } + } + + /*{ implements <%=clazz.getName()%>PersistenceService}*/ + } + + ////////////////////////////////////////////////////////////////////// + // O P E R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateNormalAttributeDeclaration(Writer output, ObjectModelAttribute attribute) throws IOException { + super.generateNormalAttributeDeclaration(output, attribute); +/*{ + /** + * @return an entity + *) + public <%=attribute.getDeclaringElement().getName()%> findBy<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException{ + List result = find(newQuery().where("<%=attribute.getName()%> = ?").addArg(value)); + if(result.size() == 0){ + throw new TopiaNotFoundException("Can't find object with attribute <%=attribute.getName()%> == " + value); + } + return (<%=attribute.getDeclaringElement().getName()%>)result.get(0); + } + + /** + * @return an unmodifiable collection + *) + public List findAllBy<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException{ + return find(newQuery().where("<%=attribute.getName()%> = ?").addArg(value)); + } +}*/ + } + + public void generateEntityAttributeDeclaration(Writer output, ObjectModelAttribute attribute) throws IOException { + generateNormalAttributeDeclaration(output, attribute); + } + + ////////////////////////////////////////////////////////////////////// + // O T H E R + ////////////////////////////////////////////////////////////////////// + + public void generateOther(Writer output, ObjectModelClassifier clazz) throws IOException { +/*{ + + /** + * Return new entity + *) + public <%=clazz.getName()%> create<%=clazz.getName()%>() throws TopiaException { + <% if(((ObjectModelClass)clazz).isAbstract()){ %> + throw new TopiaException("Abstract entity can't be instanciate"); + <% } else { %> + return (<%=clazz.getName()%>)super.create(); + <% } %> + } + + public <%=clazz.getName()%> makePersistent(<%=clazz.getName()%> entity) throws TopiaException{ + return (<%=clazz.getName()%>)super.makePersistent(entity); + } + + /** + * Return entity Class managed by this service + *) + public Class getEntityClass(){ + return <%=clazz.getName()%>.class; + } + + /** + * Retourne le context d'application associe a cette entite + *) + public <%=model.getName()%>Context getAppContext(){ + <%=model.getName()%>Context context = (<%=model.getName()%>Context)getContext(); + return context; + } + +}*/ + } + +} // OjectModelToEntityPersistenceServiceImplGenerator + Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToServiceGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ObjectModelToServiceGenerator.java:1.1 --- /dev/null Fri Aug 6 17:51:35 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToServiceGenerator.java Fri Aug 6 17:51:30 2004 @@ -0,0 +1,108 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * 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. + *##%*/ + +/* * + * ObjectModelTOServiceGenerator.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/08/06 17:51:30 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.topia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +import org.codelutin.generator.Generator; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelParameter; +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.topia.generators.Util; + +public class ObjectModelToServiceGenerator extends TopiaAbstractObjectModelGenerator { // ObjectModelToServiceGenerator + + public ObjectModelToServiceGenerator(){ + super(); + } + + public ObjectModelToServiceGenerator(Generator parent){ + super(parent); + } + + public String getFilenameForClassifier(ObjectModelClassifier clazz) { + return super.getFilenameForClassifier(clazz) + ".java"; + } + + public boolean accept(ObjectModelClassifier clazz){ + return Util.isService(clazz); + } + + ////////////////////////////////////////////////////////////////////// + // C L A S S D E C L A R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateClassDeclaration(Writer output, ObjectModelClassifier clazz) + throws IOException { +/*{ +/** +<%=clazz.getDocumentation()%> + *) +public interface <%=clazz.getName()%> extends TopiaService}*/ + for (Iterator i = clazz.getInterfaces().iterator(); i.hasNext();) { + ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); +/*{, <%=interfacezz.getName()%> }*/ + } + if(clazz instanceof ObjectModelClass){ + for (Iterator i=((ObjectModelClass)clazz).getSuperclasses().iterator(); i.hasNext();) { + ObjectModelClass superclass = (ObjectModelClass) i.next(); + /*{, <%=superclass.getName()%>}*/ + } + } + } + + + ////////////////////////////////////////////////////////////////////// + // O P E R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateOperationDeclaration(Writer output, ObjectModelOperation operation) + throws IOException { +/*{ + /** + <%=operation.getDocumentation()%> + *) + <%=operation.getVisibility()%> <%=operation.getReturnType()%> <%=operation.getName()%> (<%=Util.getMethodParameterDeclaration(operation.getParameters())%>) throws TopiaException}*/ + } + + public void generateOperationBody(Writer output, ObjectModelOperation operation) throws IOException { + /*{; + }*/ + } + +} // ObjectModelTOServiceGenerator +