Index: topia2/src/java/org/codelutin/topia/generator/ServiceImplGenerator.java diff -u /dev/null topia2/src/java/org/codelutin/topia/generator/ServiceImplGenerator.java:1.1 --- /dev/null Wed Jun 27 09:51:05 2007 +++ topia2/src/java/org/codelutin/topia/generator/ServiceImplGenerator.java Wed Jun 27 09:51:00 2007 @@ -0,0 +1,149 @@ +/* *##% +* Copyright (C) 2002, 2003, 2004, 2005 Code Lutin, +* Benjamin Poussin, +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +package org.codelutin.topia.generator; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.generator.Generator; +import org.codelutin.generator.ObjectModelGenerator; +import org.codelutin.generator.models.object.ObjectModelClassifier; +import org.codelutin.generator.models.object.ObjectModelInterface; +import org.codelutin.generator.models.object.ObjectModelOperation; +import org.codelutin.generator.models.object.ObjectModelParameter; +import org.codelutin.topia.service.TopiaApplicationServiceAbstract; + +/** +* ServiceImplGenerator.java +* +* Created: 19 juin 2007 +* +* @author ndupont +* @version $Revision: 1.1 $ +* +* L'implantation du service herite du service abstrait et donc des methodes d'appel aux DAOs +* que celui-ci possede. +* +* Genere l'implantation du service, les methodes metiers avec un corps vide, le developpeur +* du service peut alors les deplacer dans ses sources et completer les methodes. Si le +* service se contente de faire appel aux DAOs la classe generee sera vide. +* +* @see ServiceInterfaceGenerator +* @see TopiaApplicationServiceAbstract +* +* Mise a jour: $Date: 2007/06/27 09:51:00 $ +* par : $Author: ndupont $ +*/ +public class ServiceImplGenerator extends ObjectModelGenerator { + + /** + * Logger for this class + */ + private static final Log log = LogFactory + .getLog(ServiceInterfaceGenerator.class); + + public ServiceImplGenerator(Generator parent) { + super(parent); + } + + public String getFilenameForInterface(ObjectModelInterface interfacez) { + return interfacez.getQualifiedName().replace('.', File.separatorChar) + "Impl.java"; + } + + public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException { + + if (!interfacez.hasStereotype(GeneratorUtil.STEREOTYPE_SERVICE)) { + return; + } + + generateInterfaceHeader(output, interfacez); + + generateInterfaceOperations(output, interfacez); + +/*{} //<%=interfacez.getName()%> +}*/ + } + + private void generateInterfaceHeader(Writer output, ObjectModelClassifier classifier) throws IOException { +/*{package <%=classifier.getPackageName()%>;}*/ + + if (GeneratorUtil.hasDocumentation(classifier)) { + +/*{ +/** + * + * <%=classifier.getDocumentation()%> + *) +}*/ + } +/*{ + +public class <%=classifier.getName()+"Impl"%> extends <%=classifier.getName()+"Abstract"%>{ }*/ + } + + private void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException { + for (Iterator it = classifier.getOperations().iterator(); it.hasNext();) { + ObjectModelOperation op = (ObjectModelOperation)it.next(); +/*{ + + /** + * Implementation a la charge du developpeur +}*/ + if (GeneratorUtil.hasDocumentation(op)) { +/*{ * <%=op.getName()%> : <%=op.getDocumentation()%> +}*/ + } + Collection params = (Collection)op.getParameters(); + for(ObjectModelParameter param : params) { + if(log.isTraceEnabled()) {log.trace("Param" + param);} +/*{ * @param <%=param.getName()%> <%=param.getDocumentation()%> + }*/ + } +/*{ *) + <%=op.getVisibility()%> <%=op.getReturnType()%> <%=op.getName()%>(}*/ + String vir = ""; + for(ObjectModelParameter param : params){ + if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);} +/*{<%=vir%><%=param.getType()%> <%=param.getName()%>}*/ + vir = ", "; + } +/*{)}*/ + Set exceptions = (Set)op.getExceptions(); + vir = " throws "; + for (String exception : exceptions) { + if(log.isTraceEnabled()) {log.trace("exception" + exception + " vir" + vir);} +/*{<%=vir%><%=exception%>}*/ + vir = ", "; + } +/*{{ + return null; + } +}*/ + } + } + +} //ServiceImplGenerator