r1265 - in topia/trunk/topia-persistence: . src/main/java/org/codelutin/topia/generator
Author: tchemit Date: 2008-12-11 16:33:58 +0000 (Thu, 11 Dec 2008) New Revision: 1265 Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/InterfaceGenerator.java Modified: topia/trunk/topia-persistence/changelog.txt Log: add a InterfaceGenerator to generate simple with no stereotype interfaces. Modified: topia/trunk/topia-persistence/changelog.txt =================================================================== --- topia/trunk/topia-persistence/changelog.txt 2008-12-10 16:30:17 UTC (rev 1264) +++ topia/trunk/topia-persistence/changelog.txt 2008-12-11 16:33:58 UTC (rev 1265) @@ -1,3 +1,6 @@ +2.1.1 ?? 200812?? +* 20081212 [chemit] - add a InterfaceGenerator to generate simple with no stereotype interfaces. + 2.1.0 chemit 20081210 * 20081205 [chemit] - improve poms, use lutinproject 3.2 - add some usefull methods in TopiaUtil to help with regex on topiaId expression \ No newline at end of file Copied: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/InterfaceGenerator.java (from rev 1250, topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java) =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/InterfaceGenerator.java (rev 0) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/InterfaceGenerator.java 2008-12-11 16:33:58 UTC (rev 1265) @@ -0,0 +1,186 @@ +/* *##% ToPIA - Tools for Portable and Independent Architecture + * Copyright (C) 2004 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ + +/* * +* EntityGenerator.java +* +* Created: 12 déc. 2005 +* +* @author Arnaud Thimel <thimel@codelutin.com> +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.codelutin.topia.generator; + +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.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.generator.models.object.ObjectModelParameter; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +public class InterfaceGenerator extends ObjectModelGenerator { //InterfaceGenerator + + /** Logger for this class */ + private static final Log log = LogFactory.getLog(InterfaceGenerator.class); + + public InterfaceGenerator() { + super(); + } + + public InterfaceGenerator(Generator parent) { + super(parent); + } + + @Override + public String getFilenameForClass(ObjectModelClass clazz) { + return clazz.getQualifiedName().replace('.', File.separatorChar) + ".java"; + } + + @Override + public String getFilenameForInterface(ObjectModelInterface interfacez) { + return interfacez.getQualifiedName().replace('.', File.separatorChar) + ".java"; + } + + @Override + public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException { + if (!interfacez.getStereotypes().isEmpty()) { + // can only generate an interface with there is no other stereotypes + return; + } + + // log + if (log.isDebugEnabled()) { + log.debug("Generating interface for : " + interfacez.getName()); + } + + generateInterfaceHeader(output, interfacez); + + generateInterfaceOperations(output, interfacez); + +/*{} //<%=interfacez.getName()%> +}*/ + } + + private String getStringRepresentation(List<String> strings) { + StringBuffer result = new StringBuffer(); + String doubleQuote = "\""; + String comma = ","; + Iterator<String> it = strings.iterator(); + while (it.hasNext()) { + result.append(doubleQuote); + result.append(it.next()); + result.append(doubleQuote); + if (it.hasNext()) { + result.append(comma); + } + } + return result.toString(); + } + + private void generateInterfaceHeader(Writer output, ObjectModelClassifier classifier) throws IOException { + String copyright = GeneratorUtil.getCopyright(model); + if (GeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } +/*{package <%=classifier.getPackageName()%>; + +}*/ + if (GeneratorUtil.hasDocumentation(classifier)) { +/*{ +/** + * <%=classifier.getDocumentation()%> + *) +}*/ + } +/*{public interface <%=classifier.getName()%> }*/ + String extendClass = ""; + if (!classifier.getInterfaces().isEmpty()) { + for (ObjectModelClassifier parent : classifier.getInterfaces()) { + extendClass += parent.getQualifiedName(); + extendClass += ", "; + } + if (log.isTraceEnabled()) { + log.trace("Interface : " + extendClass); + } + +/*{ extends <%=extendClass%> { + +}*/ + } +/*{ { +}*/ + } + + private void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException { + for (ObjectModelOperation op : classifier.getOperations()) { +/*{ /** +}*/ + if (GeneratorUtil.hasDocumentation(op)) { +/*{ * <%=op.getName()%> : <%=op.getDocumentation()%> +}*/ + } + Collection<ObjectModelParameter> params = 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<String> exceptions = op.getExceptions(); + vir = " throws "; + for (String exception : exceptions) { + if (log.isTraceEnabled()) { + log.trace("exception" + exception + " vir" + vir); + } +/*{<%=vir%><%=exception%>}*/ + vir = ", "; + } +/*{; + +}*/ + } + } + +} //InterfaceGenerator \ No newline at end of file Property changes on: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/InterfaceGenerator.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native
participants (1)
-
tchemit@users.labs.libre-entreprise.org