Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToServiceRouterGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ObjectModelToServiceRouterGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToServiceRouterGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,127 @@ +/* *##% + * 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. + *##%*/ + +/* * + * ObjectModelToServiceRouterGenerator.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +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 ObjectModelToServiceRouterGenerator extends TopiaAbstractObjectModelGenerator { // ObjectModelToServiceRouterGenerator + + public String getFilenameForClassifier(ObjectModelClassifier clazz) { + return super.getFilenameForClassifier(clazz) + "Dist.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 clazzifier) throws IOException { + ObjectModelClass clazz = (ObjectModelClass)clazzifier; +/*{ +/** +<%=clazz.getDocumentation()%> + *) +public class <%=clazz.getName()%>Dist implements <%=clazz.getName()%>}*/ + } + + ////////////////////////////////////////////////////////////////////// + // O P E R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateOperationDeclaration(Writer output, ObjectModelOperation operation) throws IOException { + String args = Util.getMethodParameterDeclaration(operation.getParameters()); +/*{ + /** + <%=operation.getDocumentation()%> + *) + <%=operation.getVisibility()%> <%=operation.getReturnType()%> <%=operation.getName()%> (<%=args%>) throws TopiaException}*/ + } + + public void generateOperationBody(Writer output, ObjectModelOperation operation) throws IOException { + // si la methode doit être appelé localement + if(!operation.isAbstract()){ + String args = Util.getMethodParameterListName(operation.getParameters()); +/*{ { + <%=("void".equals(operation.getReturnType())?"":"return ")%> getLocalPersistenceService().<%=operation.getName()%>(<%=args%>); + } +}*/ + // sinon + }else{ +/*{ { + TopiaArgument args = new TopiaArgument(); +}*/ + for(Iterator i=operation.getParameters().iterator(); i.hasNext();){ + ObjectModelParameter param = (ObjectModelParameter)i.next(); +/*{ args.addArg(<%=param.getName()%>); +}*/ + } +/*{ + + Object result = getContext().getDistributionHelper().call( + getPersistenceServiceClass(), operation.getName(), args); + <%=("void".equals(operation.getReturnType())?"":"return ")%> <%=Util.getCastValue(operation.getReturnType(), "result")%>; + } +}*/ + } + } + + ////////////////////////////////////////////////////////////////////// + // O T H E R + ////////////////////////////////////////////////////////////////////// + + public void generateOther(Writer output, ObjectModelClassifier clazz) throws IOException { +/*{ + protected Class getServiceClass(){ + return <%=clazz.getName()%>.class; + } + protected <%=clazz.getName()%> getLocalService(){ + return (<%=clazz.getName()%>)getContext().getService(getServiceClass(), true); + } +}*/ + } + +} // ObjectModelToServiceRouterGenerator + Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToContextPropertiesGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ObjectModelToContextPropertiesGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToContextPropertiesGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,74 @@ +/* *##% + * 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. + *##%*/ + +/* * + * ObjectModelToContextPropertiesGenerator.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelClass; +import org.codelutin.topia.generators.Util; + +public class ObjectModelToContextPropertiesGenerator extends ObjectModelGenerator { // ObjectModelToContextPropertiesGenerator + + public String getFilenameForModel(ObjectModel model){ + return model.getName() + "Context.properties"; + } + + public void generateFromModel(Writer output, ObjectModel model) throws IOException { +/*{ +context.class=<%=getProperty("defaultPackage")%>.<%=model.getName()%>Context +context.helper.persistence=org.codelutin.topia.persistence.jdo.JDOPersistenceHelper +context.helper.persistence.properties.file=<%=model.getName()%>JDOPersistenceHelper.properties +context.helper.distribution=org.codelutin.topia.distribution.local.LocalDistributionHelper +context.helper.hook=org.codelutin.topia.hook.DefaultHookHelper + +}*/ + for(Iterator i=model.getClasses().iterator(); i.hasNext();){ + ObjectModelClass clazz = (ObjectModelClass)i.next(); + if(Util.isEntity(clazz)){ +/*{mapping.implentation.<%=clazz.getQualifiedName()%>Operation=<%=clazz.getQualifiedName()%>OperationImpl +mapping.distribution.<%=clazz.getQualifiedName()%>Operation=<%=clazz.getQualifiedName()%>OperationDist +}*/ + } + if(Util.isService(clazz)){ +/*{mapping.implementation.<%=clazz.getQualifiedName()%>=<%=clazz.getQualifiedName()%>Impl +mapping.distribution.<%=clazz.getQualifiedName()%>=<%=clazz.getQualifiedName()%>Dist +}*/ + } + } + } + +} // ObjectModelToContextPropertiesGenerator + Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToApplicationContextGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ObjectModelToApplicationContextGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToApplicationContextGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,115 @@ +/* *##% + * 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. + *##%*/ + +/* * + * ObjectModelToApplicationContextGenerator.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; +import java.io.File; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelClassifier; +import org.codelutin.topia.generators.Util; + +public class ObjectModelToApplicationContextGenerator extends ObjectModelGenerator { // ObjectModelToApplicationContextGenerator + + public String getFilenameForModel(ObjectModel model){ + return (getProperty("defaultPackage")+".").replace('.', File.separatorChar) + + model.getName() + "Context.java"; + } + + public void generateFromModel(Writer output, ObjectModel model) throws IOException { + +/*{ +package <%=getProperty("defaultPackage")%>; + +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaContextFactory; +import org.codelutin.topia.TopiaException; +import java.util.Properties; + +public class <%=model.getName()%>Context extends TopiaContext { + + /** + *) + protected <%=model.getName()%>Context(Properties properties) { + super(properties); + } + + /** + * Method qui permet de recuperer un context pour l'application. + * Cette methode est en fait un appel a la factory de context. + * L'avantage d'utiliser cette methode est qu'elle vous evite un cast + *) + public static <%=model.getName()%>Context getContext() throws TopiaException { + String propName = "<%=model.getName()%>Context.properties"; + return (<%=model.getName()%>Context)TopiaContextFactory.getContext(propName); + } + + /** + * Method qui permet de recuperer un context pour l'application. + * Cette methode est en fait un appel a la factory de context. + * L'avantage d'utiliser cette methode est qu'elle vous evite un cast + *) + public static <%=model.getName()%>Context getContext(Properties prop) throws TopiaException { + return (<%=model.getName()%>Context)TopiaContextFactory.getContext(prop); + } + +}*/ + for (Iterator i=model.getClassifiers().iterator(); i.hasNext();) { + ObjectModelClassifier classifier = (ObjectModelClassifier)i.next(); + if(Util.isEntity(classifier)){ +/*{ + public <%=classifier.getQualifiedName()%>PersistenceService get<%=classifier.getName()%>PersistenceService() throws TopiaException { + return (<%=classifier.getQualifiedName()%>PersistenceService) getPersistenceService(<%=classifier.getQualifiedName()%>.class); + } +}*/ + } + if(Util.isService(classifier)){ +/*{ + public <%=classifier.getQualifiedName()%> get<%=classifier.getName()%>() throws TopiaException { + return (<%=classifier.getQualifiedName()%>) getService(<%=classifier.getQualifiedName()%>.class); + } +}*/ + } + } + +/*{ + // TODO Controls + +} +}*/ + } + +} // ObjectModelToApplicationContextGenerator + Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,98 @@ +/* *##% + * 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. + *##%*/ + +/* * + * ObjectModelToEntityOperationGenerator.java + * + * Created: 4 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +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 ObjectModelToEntityOperationGenerator extends TopiaAbstractObjectModelGenerator { // ObjectModelToEntityOperationGenerator + + public String getFilenameForClassifier(ObjectModelClassifier clazz) { + return super.getFilenameForClassifier(clazz) + "Operation.java"; + } + + public boolean accept(ObjectModelClassifier clazz){ + return Util.isEntity(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() + "Operation"%> extends TopiaEntityOperation}*/ + for (Iterator i = clazz.getInterfaces().iterator(); i.hasNext();) { + ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); +/*{, <%=interfacezz.getName()%>Operation }*/ + } + if(clazz instanceof ObjectModelClass){ + for (Iterator i=((ObjectModelClass)clazz).getSuperclasses().iterator(); i.hasNext();) { + ObjectModelClass superclass = (ObjectModelClass) i.next(); + /*{, <%=superclass.getName()%>Operation}*/ + } + } + } + + ////////////////////////////////////////////////////////////////////// + // O P E R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateOperationDeclaration(Writer output, ObjectModelOperation operation) throws IOException { + String args = Util.getMethodParameterDeclaration(operation.getParameters()); +/*{ + /** + <%=operation.getDocumentation()%> + *) + <%=operation.getVisibility()%> <%=operation.getReturnType()%> <%=operation.getName()%> (<%=operation.getDeclaringElement().getName()%> _self_<%=(args.equals("")?"":", ")%><%=args%>) throws TopiaException}*/ + } + + public void generateOperationBody(Writer output, ObjectModelOperation operation) throws IOException { +/*{; +}*/ + } + +} // ObjectModelToEntityOperationGenerator + 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 Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelTOServiceGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,99 @@ +/* *##% + * 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/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +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 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 + Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToTopiaMetaGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,105 @@ +/* *##% + * 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. + *##%*/ + +/* * + * ObjectModelToTopiaMetaGenerator.java + * + * Created: 4 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators; + +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModel; +import java.io.IOException; +import java.io.File; + +/** +* Meta generateur qui appelle tous les générateur de classe util pour le +* framework de base de ToPIA. C'est à dire les générateur qui ne sont +* pas spécifique à la persistence ou aux autre module. +*/ +public class ObjectModelToTopiaMetaGenerator extends ObjectModelGenerator { // ObjectModelToTopiaMetaGenerator + + public ObjectModelToTopiaMetaGenerator(){ + super(); + } + + public void generate(ObjectModel model, File destDir) throws IOException { + ObjectModelGenerator gen = null; + + System.out.println("Generation de ObjectModelToApplicationContextGenerator"); + gen = new ObjectModelToApplicationContextGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de ObjectModelToContextPropertiesGenerator"); + gen = new ObjectModelToContextPropertiesGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de ObjectModelToEntityGenerator"); + gen = new ObjectModelToEntityGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de ObjectModelToEntityImplGenerator"); + gen = new ObjectModelToEntityImplGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de ObjectModelToEntityOperationGenerator"); + gen = new ObjectModelToEntityOperationGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de ObjectModelToEntityOperationRouterGenerator"); + gen = new ObjectModelToEntityOperationRouterGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de ObjectModelToEntityPersistenceServiceGenerator"); + gen = new ObjectModelToEntityPersistenceServiceGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de OjectModelToEntityPersistenceServiceImplGenerator"); + gen = new OjectModelToEntityPersistenceServiceImplGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de ObjectModelToServiceRouterGenerator"); + gen = new ObjectModelToServiceRouterGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + + System.out.println("Generation de ObjectModelTOServiceGenerator"); + gen = new ObjectModelTOServiceGenerator(); + gen.setProperties(properties); + gen.generate(model, destDir); + } + +} // ObjectModelToTopiaMetaGenerator + Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,142 @@ +/* *##% + * 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. + *##%*/ + +/* * + * ObjectModelToEntityGenerator.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +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; + +public class ObjectModelToEntityGenerator extends TopiaAbstractObjectModelGenerator { // ObjectModelToEntityGenerator + + public String getFilenameForClassifier(ObjectModelClassifier clazz) { + return super.getFilenameForClassifier(clazz) + ".java"; + } + + public boolean accept(ObjectModelClassifier clazz){ + return true; + } + + ////////////////////////////////////////////////////////////////////// + // 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 TopiaEntity}*/ + 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()%>}*/ + } + } + } + + + ////////////////////////////////////////////////////////////////////// + // G E T A T T R I B U T E S A C C E S S O R S + ////////////////////////////////////////////////////////////////////// + + public void generateGetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; +}*/ + } + + public void generateGetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + /** + * @return an unmodifiable collection + *) + public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; +}*/ + + } + + ////////////////////////////////////////////////////////////////////// + // S E T A T T R I B U T E S A C C E S S O R S + ////////////////////////////////////////////////////////////////////// + + public void generateSetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException; +}*/ + } + + public void generateSetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; + + public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException; + + public void clear<%=Util.capitalize(attribute.getName())%>() throws TopiaException; +}*/ + } + + ////////////////////////////////////////////////////////////////////// + // 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 { + String args = Util.getMethodParameterListName(operation.getParameters()); +/*{; +}*/ + } + +} // ObjectModelToEntityGenerator + Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationRouterGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationRouterGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityOperationRouterGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,145 @@ +/* *##% + * 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. + *##%*/ + +/* * + * ObjectModelToEntityOperationRouterGenerator.java + * + * Created: 4 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +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 ObjectModelToEntityOperationRouterGenerator extends TopiaAbstractObjectModelGenerator { // ObjectModelToEntityOperationRouterGenerator + + public String getFilenameForClassifier(ObjectModelClassifier clazz) { + return super.getFilenameForClassifier(clazz) + "OperationRouter.java"; + } + + public boolean accept(ObjectModelClassifier clazz){ + return Util.isEntity(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 class <%=clazz.getName()%>OperationRouter extends AbstractTopiaElement implements <%=clazz.getName()%>Operation}*/ + } + + ////////////////////////////////////////////////////////////////////// + // O P E R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateOperationDeclaration(Writer output, ObjectModelOperation operation) throws IOException { + String args = Util.getMethodParameterDeclaration(operation.getParameters()); +/*{ + /** + <%=operation.getDocumentation()%> + *) + <%=operation.getVisibility()%> <%=operation.getReturnType()%> <%=operation.getName()%> (<%=operation.getDeclaringElement().getName()%> _self_<%=(args.equals("")?"":", ")%><%=args%>) throws TopiaException}*/ + } + + public void generateOperationBody(Writer output, ObjectModelOperation operation) throws IOException { + // si la methode doit être appelé localement + if(!operation.isAbstract()){ + String args = Util.getMethodParameterListName(operation.getParameters()); +/*{ { + <%=("void".equals(operation.getReturnType())?"":"return ")%> getLocalEntityOperation().<%=operation.getName()%>(_self_<%=(args.equals("")?"":", ")%><%=args%>); + } +}*/ + // sinon + }else{ +/*{ { + TopiaArgument args = new TopiaArgument().addArg(_self_); +}*/ + for(Iterator i=operation.getParameters().iterator(); i.hasNext();){ + ObjectModelParameter param = (ObjectModelParameter)i.next(); +/*{ args.addArg(<%=param.getName()%>); +}*/ + } +/*{ + + Object result = getContext().getDistributionHelper().call( + getEntityOperationClass(), operation.getName(), args); + <%=("void".equals(operation.getReturnType())?"":"return ")%> <%=Util.getCastValue(operation.getReturnType(), "result")%>; + } +}*/ + } + } + + public void generateInterfaceOperationDeclaration(Writer output, ObjectModelOperation operation) throws IOException { + generateOperationDeclaration(output, operation); + } + public void generateInterfaceOperationBody(Writer output, ObjectModelOperation operation) throws IOException { + generateOperationBody(output, operation); + } + + public void generateSuperclassOperationDeclaration(Writer output, ObjectModelOperation operation) throws IOException { + generateOperationDeclaration(output, operation); + } + public void generateSuperclassOperationBody(Writer output, ObjectModelOperation operation) throws IOException { + generateOperationBody(output, operation); + } + + ////////////////////////////////////////////////////////////////////// + // O T H E R + ////////////////////////////////////////////////////////////////////// + + public void generateOther(Writer output, ObjectModelClassifier clazz) throws IOException { +/*{ + protected Class getEntityOperationClass(){ + return <%=clazz.getName()%>Operation.class; + } + + protected Class getEntityClass(){ + return <%=clazz.getName()%>.class; + } + + private <%=clazz.getName()%>Operation getLocalEntityOperation()throws TopiaException { + return (<%=clazz.getName()%>Operation)getContext().getEntityOperation(getEntityClass(), true); + } +}*/ + } + +} // ObjectModelToEntityOperationRouterGenerator + Index: topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/generators/TopiaAbstractObjectModelGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,462 @@ +/* *##% + * 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. + *##%*/ + +/* * + * TopiaAbstractObjectModelGenerator.java + * + * Created: 4 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +import org.codelutin.generator.ObjectModelGenerator; +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; + +public abstract class TopiaAbstractObjectModelGenerator extends ObjectModelGenerator { // TopiaAbstractObjectModelGenerator + + /** + * if this method return false, nothing is generate + */ + abstract public boolean accept(ObjectModelClassifier clazz); + + public String getFilenameForClassifier(ObjectModelClassifier clazz){ + return clazz.getQualifiedName().replace('.', File.separatorChar); + } + + public void generateFromClassifier(Writer output, ObjectModelClassifier clazz) throws IOException { + // Consider only entities, return immediately if not an entity + if (! accept(clazz)) + return; + + // ------------- File Header + generatePackageStatement(output, clazz); + + // ------------- Imports + generateImportStatement(output, clazz); + + // ------------- Class start + generateClassDeclaration(output, clazz); +/*{ { +}*/ + + if(clazz instanceof ObjectModelClass){ + // ------------- Attributes + for (Iterator i=((ObjectModelClass)clazz).getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + generateAttributeDeclaration(output, attribute); + generateGetAttributeAccessor(output, attribute); + generateSetAttributeAccessor(output, attribute); + } + + // parcours les operations des super classes + for(Iterator i=((ObjectModelClass)clazz).getAllSuperclassOperations(true).iterator(); i.hasNext();){ + ObjectModelOperation operation = (ObjectModelOperation) i.next(); + if(!Util.isGeneratedOperation(clazz, operation)){ + generateSuperclassOperationDeclaration(output, operation); + generateSuperclassOperationBody(output, operation); + } + } + } + + // ------------- Operations declarations + for(Iterator i=clazz.getOperations().iterator(); i.hasNext();){ + ObjectModelOperation operation = (ObjectModelOperation) i.next(); + if(!Util.isGeneratedOperation(clazz, operation)){ + generateOperationDeclaration(output, operation); + generateOperationBody(output, operation); + } + } + + // parcours les operations des interfaces + for(Iterator i=clazz.getAllInterfaceOperations(true).iterator(); i.hasNext();){ + ObjectModelOperation operation = (ObjectModelOperation) i.next(); + if(!Util.isGeneratedOperation(clazz, operation)){ + generateInterfaceOperationDeclaration(output, operation); + generateInterfaceOperationBody(output, operation); + } + } +// + // ---------------- All that framework used + generateOther(output, clazz); +/*{ +} +}*/ + } + + ////////////////////////////////////////////////////////////////////// + // P A C K A G E + ////////////////////////////////////////////////////////////////////// + + /** + * Il faut absolument que les classes soit dans un package, sinon + * il faut revoir la modelisation :) + */ + public void generatePackageStatement(Writer output, ObjectModelClassifier clazz) + throws IOException { +/*{ +package <%=clazz.getPackageName()%>; + +}*/ + } + + /** + * Appelle la methode {@link #generatePackageStatement(Writer, ObjectModelClassifier)} + */ + public void generatePackageStatement(Writer output, ObjectModelClass clazz) + throws IOException { + generatePackageStatement(output, (ObjectModelClassifier)clazz); + } + + /** + * Appelle la methode {@link #generatePackageStatement(Writer, ObjectModelClassifier)} + */ + public void generatePackageStatement(Writer output, ObjectModelInterface interfacez) + throws IOException { + generatePackageStatement(output, (ObjectModelClassifier)interfacez); + } + + + ////////////////////////////////////////////////////////////////////// + // I M P O R T + ////////////////////////////////////////////////////////////////////// + + /** + * Importe les classes utilises utilisees le plus souvent + */ + public void generateImportStatement(Writer output, ObjectModelClassifier clazz) + throws IOException { + /*{ +import <%=getProperty("defaultPackage")%>.<%=model.getName()%>Context; +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaEntity; +import org.codelutin.topia.TopiaEntityOperation; +import org.codelutin.topia.AbstractTopiaEntity; +import org.codelutin.topia.AbstractTopiaElement; +import org.codelutin.topia.AbstractTopiaPersistenceService; +import org.codelutin.topia.TopiaUser; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.TopiaNotFoundException; +import org.codelutin.topia.TopiaPersistenceService; +import org.codelutin.topia.TopiaQuery; +import org.codelutin.topia.TopiaArgument; +import java.util.List; +import java.util.Collection; +import java.util.Collections; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.HashSet; +import java.util.Date; +import java.util.logging.Level; +import java.util.logging.Logger; + +}*/ + } + + /** + * Appelle la methode {@link #generateImportStatement(Writer, ObjectModelClassifier)} + */ + public void generateImportStatement(Writer output, ObjectModelClass clazz) + throws IOException { + generateImportStatement(output, (ObjectModelClassifier)clazz); + } + + /** + * Appelle la methode {@link #generateImportStatement(Writer, ObjectModelClassifier)} + */ + public void generateImportStatement(Writer output, ObjectModelInterface interfacez) + throws IOException { + generateImportStatement(output, (ObjectModelClassifier)interfacez); + } + + ////////////////////////////////////////////////////////////////////// + // C L A S S D E C L A R A T I O N + ////////////////////////////////////////////////////////////////////// + + abstract public void generateClassDeclaration(Writer output, ObjectModelClassifier clazz) throws IOException; + + ////////////////////////////////////////////////////////////////////// + // A T T R I B U T S D E C L A R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateAttributeDeclaration(Writer output, ObjectModelAttribute attribute) + throws IOException { + if(Util.isDerived(attribute)){ + generateDerivedAttributeDeclaration(output, attribute); + }else{ + if (!attribute.referenceClassifier()) { + if(!Util.isNMultiplicity(attribute)){ + generateNormalAttributeDeclaration(output, attribute); + }else{ + generateNormalNMultiplicityAttributeDeclaration(output, attribute); + } + }else{ + if(!Util.isNMultiplicity(attribute)){ + generateEntityAttributeDeclaration(output, attribute); + }else{ + generateEntityNMultiplicityAttributeDeclaration(output, attribute); + } + } + } + } + + /** + * For derived (calculated) attribute. Generate nothing + */ + public void generateDerivedAttributeDeclaration(Writer output, ObjectModelAttribute attribute) + throws IOException { + } + + /** + * For normal attribute, aka not entity or derived and with 0/1 cardinality. + */ + public void generateNormalAttributeDeclaration(Writer output, ObjectModelAttribute attribute) + throws IOException { + } + + /** + * For normal attribute, aka not entity or derived and with n cardinality. + * By default call {@link #generateNormalAttributeDeclaration} + */ + public void generateNormalNMultiplicityAttributeDeclaration(Writer output, ObjectModelAttribute attribute) + throws IOException { + generateNormalAttributeDeclaration(output, attribute); + } + + /** + * For entity attribute with 0/1 cardinality. By default call + * {@link #generateNormalAttributeDeclaration} + */ + public void generateEntityAttributeDeclaration(Writer output, ObjectModelAttribute attribute) + throws IOException { + generateNormalAttributeDeclaration(output, attribute); + } + + /** + * For entity attribute with n cardinality. By default call + * {@link #generateNormalAttributeDeclaration} + */ + public void generateEntityNMultiplicityAttributeDeclaration(Writer output, ObjectModelAttribute attribute) + throws IOException { + generateNormalNMultiplicityAttributeDeclaration(output, attribute); + } + + ////////////////////////////////////////////////////////////////////// + // G E T A T T R I B U T E S A C C E S S O R S + ////////////////////////////////////////////////////////////////////// + + public void generateGetAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + if(Util.isDerived(attribute)){ + generateGetDerivedAttributeAccessor(output, attribute); + }else{ + if (!attribute.referenceClassifier()) { + if(!Util.isNMultiplicity(attribute)){ + generateGetNormalAttributeAccessor(output, attribute); + }else{ + generateGetNormalNMultiplicityAttributeAccessor(output, attribute); + } + }else{ + if(!Util.isNMultiplicity(attribute)){ + generateGetEntityAttributeAccessor(output, attribute); + }else{ + generateGetEntityNMultiplicityAttributeAccessor(output, attribute); + } + } + } + } + + /** + * For derived (calculated) attribute. + */ + public void generateGetDerivedAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + } + + /** + * For normal attribute, aka not entity or derived. + */ + public void generateGetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + } + + /** + * For normal attribute, aka not entity or derived and with n cardinality. + * By default call {@link #generateNormalAttributeDeclaration} + */ + public void generateGetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + generateGetNormalAttributeAccessor(output, attribute); + } + + /** + * For entity attribute with 0/1 cardinality. By default call + * {@link #generateNormalAttributeDeclaration} + */ + public void generateGetEntityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + generateGetNormalAttributeAccessor(output, attribute); + } + + /** + * For entity attribute with n cardinality. By default call + * {@link #generateNormalNMultiplicityAttributeDeclaration} + */ + public void generateGetEntityNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + generateGetNormalNMultiplicityAttributeAccessor(output, attribute); + } + + ////////////////////////////////////////////////////////////////////// + // S E T A T T R I B U T E S A C C E S S O R S + ////////////////////////////////////////////////////////////////////// + + public void generateSetAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + if (!Util.isReadOnly(attribute)){ + if(Util.isDerived(attribute)){ + generateSetDerivedAttributeAccessor(output, attribute); + }else{ + if (!attribute.referenceClassifier()) { + if(!Util.isNMultiplicity(attribute)){ + generateSetNormalAttributeAccessor(output, attribute); + }else{ + generateSetNormalNMultiplicityAttributeAccessor(output, attribute); + } + }else{ + if(!Util.isNMultiplicity(attribute)){ + generateSetEntityAttributeAccessor(output, attribute); + }else{ + generateSetEntityNMultiplicityAttributeAccessor(output, attribute); + } + } + } + } + } + + /** + * For derived (calculated) attribute. + */ + public void generateSetDerivedAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + } + + /** + * For normal attribute, aka not entity or derived. + */ + public void generateSetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + } + + /** + * For normal attribute, aka not entity or derived and with n cardinality. + * By default call {@link #generateNormalAttributeDeclaration} + */ + public void generateSetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + } + + /** + * For entity attribute with 0/1 cardinality. By default call + * {@link #generateNormalAttributeDeclaration} + */ + public void generateSetEntityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + generateSetNormalAttributeAccessor(output, attribute); + } + + /** + * For entity attribute with n cardinality. By default call + * {@link #generateNormalNMultiplicityAttributeDeclaration} + */ + public void generateSetEntityNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { + generateSetNormalNMultiplicityAttributeAccessor(output, attribute); + } + + ////////////////////////////////////////////////////////////////////// + // O P E R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateOperationDeclaration(Writer output, ObjectModelOperation operation) + throws IOException { + } + + /** + * Generate the body of operation. include {, }, or ; + */ + public void generateOperationBody(Writer output, ObjectModelOperation operation) throws IOException { + } + + public void generateInterfaceOperationDeclaration(Writer output, ObjectModelOperation operation) + throws IOException { + } + + /** + * Generate the body of operation. include {, }, or ; + */ + public void generateInterfaceOperationBody(Writer output, ObjectModelOperation operation) throws IOException { + } + + public void generateSuperclassOperationDeclaration(Writer output, ObjectModelOperation operation) + throws IOException { + } + + /** + * Generate the body of operation. include {, }, or ; + */ + public void generateSuperclassOperationBody(Writer output, ObjectModelOperation operation) throws IOException { + } + + + ////////////////////////////////////////////////////////////////////// + // O T H E R + ////////////////////////////////////////////////////////////////////// + + /** + * generate nothing by default + */ + public void generateOther(Writer output, ObjectModelClassifier clazz) + throws IOException { + } + public void generateOther(Writer output, ObjectModelClass clazz) + throws IOException { + generateOther(output, (ObjectModelClassifier)clazz); + } + public void generateOther(Writer output, ObjectModelInterface interfacez) + throws IOException { + generateOther(output, (ObjectModelClassifier)interfacez); + } + +} // TopiaAbstractObjectModelGenerator + Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,275 @@ +/* *##% + * 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. + *##%*/ + +/* * + * ObjectModelToEntityImplGenerator.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +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; + +public class ObjectModelToEntityImplGenerator extends TopiaAbstractObjectModelGenerator { // ObjectModelToEntityImplGenerator + + public String getFilenameForClassifier(ObjectModelClassifier clazz) { + return super.getFilenameForClassifier(clazz) + "Impl.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 clazzifier) throws IOException { + ObjectModelClass clazz = (ObjectModelClass)clazzifier; +/*{ +/** +<%=clazz.getDocumentation()%> + *) +public class <%=clazz.getName() + "Impl"%>}*/ + Iterator i = clazz.getSuperclasses().iterator(); + if (i.hasNext()) { + ObjectModelClass superclass = (ObjectModelClass) i.next(); +/*{ extends <%=superclass.getName() + "Impl"%>}*/ + } else { +/*{ extends AbstractTopiaEntity}*/ + } + + /*{ implements <%=clazz.getName()%>}*/ + } + + ////////////////////////////////////////////////////////////////////// + // A T T R I B U T S D E C L A R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateNormalAttributeDeclaration(Writer output, ObjectModelAttribute attribute) throws IOException { +/*{ + protected <%=Util.getAttributeType(attribute)%> <%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; + protected boolean _<%=attribute.getName()%>Modified_ = false; +}*/ + } + + ////////////////////////////////////////////////////////////////////// + // G E T A T T R I B U T E S A C C E S S O R S + ////////////////////////////////////////////////////////////////////// + + public void generateGetDerivedAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + public abstract <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException; +}*/ + } + + public void generateGetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { +/*{ + public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + return <%=attribute.getName()%>; + } + public boolean is_<%=attribute.getName()%>Modified_(){ + return this._<%=attribute.getName()%>Modified_; + } +}*/ + } + + public void generateGetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + /** + * @return an unmodifiable collection + *) + public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + return Collections.unmodifiableCollection(<%=attribute.getName()%>); + } + public boolean is_<%=attribute.getName()%>Modified_(){ + return this._<%=attribute.getName()%>Modified_; + } +}*/ + } + + ////////////////////////////////////////////////////////////////////// + // S E T A T T R I B U T E S A C C E S S O R S + ////////////////////////////////////////////////////////////////////// + + public void generateSetDerivedAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + public abstract void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException; + +}*/ + } + + public void generateSetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException { + this._<%=attribute.getName()%>Modified_ = true; + this.<%=attribute.getName()%> = value; + } +}*/ + } + + public void generateSetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { + this._<%=attribute.getName()%>Modified_ = true; + this.<%=attribute.getName()%>.add(value); + } + + public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { + this._<%=attribute.getName()%>Modified_ = true; + this.<%=attribute.getName()%>.remove(value); + } + + public void clear<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + this._<%=attribute.getName()%>Modified_ = true; + this.<%=attribute.getName()%> = <%=Util.getInitValue(attribute)%>; + } +}*/ + } + + ////////////////////////////////////////////////////////////////////// + // 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 { + String args = Util.getMethodParameterListName(operation.getParameters()); +/*{ { + <%=("void".equals(operation.getReturnType())?"":"return ")%> getEntityOperation().<%=operation.getName()%>(this<%=(args.equals("")?"":", ")%> <%=args%>); + } +}*/ + } + + public void generateInterfaceOperationDeclaration(Writer output, ObjectModelOperation operation) throws IOException { + generateOperationDeclaration(output, operation); + } + public void generateInterfaceOperationBody(Writer output, ObjectModelOperation operation) throws IOException { + generateOperationBody(output, operation); + } + + ////////////////////////////////////////////////////////////////////// + // O T H E R + ////////////////////////////////////////////////////////////////////// + + public void generateOther(Writer output, ObjectModelClassifier clazz) throws IOException { + generateSetAllFrameworkProperties(output, (ObjectModelClass)clazz); + +/*{ + + public <%=clazz.getName()%>Impl()throws TopiaException { + } + + /** + * Return entity Class managed by this service + *) + public Class getEntityClass(){ + return <%=clazz.getName()%>.class; + } + + /** + * Retourne le persistenceService associé à cette entite. + *) + private <%=clazz.getName()%>PersistenceService getPersistenceService()throws TopiaException { + <%=clazz.getName()%>PersistenceService persistenceService = getAppContext().get<%=clazz.getName()%>PersistenceService(); + return persistenceService; + } + + /** + * Retourne le context d'application associe a cette entite + *) + public <%=model.getName()%>Context getAppContext(){ + <%=model.getName()%>Context context = (<%=model.getName()%>Context)getContext(); + return context; + } + + private <%=clazz.getName()%>Operation getEntityOperation() throws TopiaException { + return (<%=clazz.getName()%>Operation)getContext().getEntityOperation(getEntityClass()); + } +}*/ + } + + protected void generateSetAllFrameworkProperties(Writer output, ObjectModelClass clazz) throws IOException { +/*{ + /** + * Prend toutes les valeurs de l'objet passé en paramètre et les utilises + * comme valeur pour l'objet courant, ceci inclue l'id de l'objet + * Les modifications s'effectue au travers des methodes set. + *) + public void set_allProperties_(TopiaEntity topiaEntity) throws TopiaException { + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)topiaEntity; +}*/ + if(clazz.getSuperclasses().size() != 0){ +/*{ + super.set_allProperties_(entity); +}*/ + }else{ +/*{ + this._topiaId_ = entity.get_topiaId_(); + this._version_ = entity.get_version_(); + this._creationDate_ = entity.get_creationDate_(); + this._lastUpdateDate_ = entity.get_lastUpdateDate_(); + this._lastUpdateUser_ = entity.get_lastUpdateUser_(); +}*/ + } + + // Iterate on each attribute + for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + if(! Util.isDerived(attribute)){ +/*{ + this.<%=attribute.getName()%> = entity.get<%=Util.capitalize(attribute.getName())%>(); +}*/ + } + } +/*{ + } +}*/ + } + +} // ObjectModelToEntityImplGenerator + Index: topia/src/java/org/codelutin/topia/generators/OjectModelToEntityPersistenceServiceImplGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/OjectModelToEntityPersistenceServiceImplGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/generators/OjectModelToEntityPersistenceServiceImplGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,152 @@ +/* *##% + * 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/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +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.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 OjectModelToEntityPersistenceServiceImplGenerator extends TopiaAbstractObjectModelGenerator { // OjectModelToEntityPersistenceServiceImplGenerator + + 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 <%=(operations.size()==0?"":"abstract ")%>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 { + 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/ObjectModelToEntityPersistenceServiceGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityPersistenceServiceGenerator.java Fri Jul 30 14:38:58 2004 @@ -0,0 +1,128 @@ +/* *##% + * 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. + *##%*/ + +/* * + * ObjectModelToEntityPersistenceServiceGenerator.java + * + * Created: 3 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:58 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.generators; + +import java.io.IOException; +import java.io.Writer; +import java.util.Iterator; + +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; + +public class ObjectModelToEntityPersistenceServiceGenerator extends TopiaAbstractObjectModelGenerator { // ObjectModelToEntityPersistenceServiceGenerator + + public String getFilenameForClassifier(ObjectModelClassifier clazz) { + return super.getFilenameForClassifier(clazz) + "PersistenceService.java"; + } + + + public boolean accept(ObjectModelClassifier clazz){ + return Util.isEntity(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()%>PersistenceService extends TopiaPersistenceService}*/ + for (Iterator i = clazz.getInterfaces().iterator(); i.hasNext();) { + ObjectModelInterface interfacezz = (ObjectModelInterface) i.next(); +/*{, <%=interfacezz.getName()%>PersistenceService }*/ + } + if(clazz instanceof ObjectModelClass){ + for (Iterator i=((ObjectModelClass)clazz).getSuperclasses().iterator(); i.hasNext();) { + ObjectModelClass superclass = (ObjectModelClass) i.next(); + /*{, <%=superclass.getName()%>PersistenceService}*/ + } + } + } + + ////////////////////////////////////////////////////////////////////// + // O P E R A T I O N + ////////////////////////////////////////////////////////////////////// + + // TODO dans le futur les operations de nom find seront a mettre ici + // et pas dans l'entite + public void generateOperationDeclaration(Writer output, ObjectModelOperation operation) throws IOException { + } + + public void generateOperationBody(Writer output, ObjectModelOperation operation) throws IOException { + } + + public void generateNormalAttributeDeclaration(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + /** + * @return an entity + *) + public <%=attribute.getDeclaringElement().getName()%> findBy<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException; + + /** + * @return an unmodifiable collection + *) + public List findAllBy<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> <%=attribute.getName()%>) throws TopiaException; +}*/ + } + + 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 { + if(clazz instanceof ObjectModelClass){ +/*{ + /** + * Return new entity + *) + public <%=clazz.getName()%> create<%=clazz.getName()%>() throws TopiaException; + + public <%=clazz.getName()%> makePersistent(<%=clazz.getName()%> entity) throws TopiaException; +}*/ + } + } + +} // ObjectModelToEntityPersistenceServiceGenerator +