Index: topia/src/java/org/codelutin/topia/persistence/LazyEntityGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/LazyEntityGenerator.java:1.1 --- /dev/null Fri Jul 30 14:39:04 2004 +++ topia/src/java/org/codelutin/topia/persistence/LazyEntityGenerator.java Fri Jul 30 14:38:59 2004 @@ -0,0 +1,274 @@ +/* *##% + * 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. + *##%*/ + +/* * + * LazyEntityGenerator.java + * + * Created: 6 juil. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/07/30 14:38:59 $ + * par : $Author: pineau $ + */ + +package org.codelutin.topia.persistence; + +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.TopiaAbstractObjectModelGenerator; +import org.codelutin.topia.generators.Util; + +public class LazyEntityGenerator extends TopiaAbstractObjectModelGenerator { // LazyEntityGenerator + + public String getFilenameForClassifier(ObjectModelClassifier clazz) { + return (clazz.getPackageName()+".persistence.jdo.").replace('.', File.separatorChar)+clazz.getName()+"Lazy.java"; + } + + public boolean accept(ObjectModelClassifier clazz){ + return Util.isEntity(clazz); + } + + ////////////////////////////////////////////////////////////////////// + // P A C K A G E + ////////////////////////////////////////////////////////////////////// + + public void generatePackageStatement(Writer output, ObjectModelClassifier clazz) + throws IOException { +/*{ +package <%=clazz.getPackageName()%>.persistence.jdo; + +}*/ + } + + ////////////////////////////////////////////////////////////////////// + // C L A S S D E C L A R A T I O N + ////////////////////////////////////////////////////////////////////// + + public void generateImportStatement(Writer output, ObjectModelClassifier clazz) throws IOException { + super.generateImportStatement(output, clazz); +/*{ +import org.codelutin.topia.persistence.jdo.AbstractLazyEntity; +import <%=clazz.getPackageName()%>.*; +}*/ + } + + public void generateClassDeclaration(Writer output, ObjectModelClassifier clazzifier) throws IOException { +/*{ +/** +<%=clazzifier.getDocumentation()%> + *) +public class <%=clazzifier.getName()%>Lazy}*/ + if (clazzifier instanceof ObjectModelClass) { + ObjectModelClass clazz = (ObjectModelClass) clazzifier; + Iterator i = clazz.getSuperclasses().iterator(); + if (i.hasNext()) { + ObjectModelClass superclass = (ObjectModelClass) i.next(); +/*{ extends <%=superclass.getName()%>Lazy}*/ + } else { +/*{ extends AbstractLazyEntity}*/ + } + } else { +/*{ extends AbstractLazyEntity}*/ + } + + /*{ implements <%=clazzifier.getQualifiedName()%>}*/ + } + + ////////////////////////////////////////////////////////////////////// + // 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 <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException{ + load(); + return getTypedEntity().get<%=Util.capitalize(attribute.getName())%>(); + } +}*/ + } + + public void generateGetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { +/*{ + public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + load(); + return getTypedEntity().get<%=Util.capitalize(attribute.getName())%>(); + } +}*/ + } + + public void generateGetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + /** + * @return an unmodifiable collection + *) + public <%=Util.getAttributeType(attribute)%> get<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + load(); + return getTypedEntity().get<%=Util.capitalize(attribute.getName())%>(); + } +}*/ + } + + ////////////////////////////////////////////////////////////////////// + // 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{ + load(); + getTypedEntity().set<%=Util.capitalize(attribute.getName())%>(value); + } + +}*/ + } + + public void generateSetNormalAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException { + getTypedEntity().set<%=Util.capitalize(attribute.getName())%>(value); + } +}*/ + } + + public void generateSetNormalNMultiplicityAttributeAccessor(Writer output, ObjectModelAttribute attribute) + throws IOException { +/*{ + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { + getTypedEntity().add<%=Util.capitalize(attribute.getName())%>(value); + } + + public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { + getTypedEntity().remove<%=Util.capitalize(attribute.getName())%>(value); + } + + public void clear<%=Util.capitalize(attribute.getName())%>() throws TopiaException { + getTypedEntity().clear<%=Util.capitalize(attribute.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 { + String args = Util.getMethodParameterListName(operation.getParameters()); +/*{ { + <%=("void".equals(operation.getReturnType())?"":"return ")%> getTypedEntity().<%=operation.getName()%>(<%=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 clazzifier) throws IOException { +/*{ + public <%=clazzifier.getName()%>Lazy(TopiaContext context, String _topiaId_, String version)throws TopiaException { + super(context, _topiaId_, version); + } + + public <%=clazzifier.getName()%>Lazy(TopiaContext context, TopiaEntity entity) throws TopiaException { + super(context, entity); + } + + private <%=clazzifier.getName()%> getTypedEntity(){ + return (<%=clazzifier.getName()%>)getEntity(); + } + + /** + * Return entity Class managed by this service + *) + public Class getEntityClass(){ + return <%=clazzifier.getName()%>.class; + } + + /** + * Retourne le persistenceService associé à cette entite. + *) + private <%=clazzifier.getName()%>PersistenceService getPersistenceService()throws TopiaException { + <%=clazzifier.getName()%>PersistenceService persistenceService = getAppContext().get<%=clazzifier.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; + } + protected void setContextOnAllLazy(TopiaContext context) throws TopiaException { +}*/ + if (clazzifier instanceof ObjectModelClass) { + ObjectModelClass clazz = (ObjectModelClass)clazzifier; + for (Iterator i = clazz.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + if(! Util.isDerived(attribute) && attribute.referenceClassifier()){ + if (!Util.isNMultiplicity(attribute)) { +/*{ + get<%=Util.capitalize(attribute.getName())%>().setContext(context); +}*/ + }else{ +/*{ + for(Iterator i=get<%=Util.capitalize(attribute.getName())%>().iterator(); i.hasNext(); ){ + ((TopiaEntity)i.next()).setContext(context); + } +}*/ + } + } + } + } +/*{ + } +}*/ + } + +} // LazyEntityGenerator +