Author: tchemit Date: 2009-12-14 02:57:24 +0100 (Mon, 14 Dec 2009) New Revision: 749 Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/LICENSE.txt branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/README.txt branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/changelog.txt branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/invoker.properties branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/pom.xml branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/Megatron.java branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TestReader.java branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/models/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/models/dtotest.objectmodel branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/models/dtotest2.objectmodel branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/resources/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/resources/log4j.properties branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/java/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/java/org/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/java/org/nuiton/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/java/org/nuiton/eugene/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/java/org/nuiton/eugene/test/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/java/org/nuiton/eugene/test/generator/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/resources/ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/resources/log4j.properties branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/verify.groovy Removed: branches/eugene-2.0/eugene-test/pom.xml branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/Megatron.java branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestReader.java branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java branches/eugene-2.0/eugene-test/src/main/models/ branches/eugene-2.0/eugene-test/src/main/resources/log4j.properties branches/eugene-2.0/eugene-test/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java branches/eugene-2.0/eugene-test/src/test/resources/log4j.properties Modified: branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/java/JavaBuilder.java branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/java/JavaGenerator.java branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelModifier.java branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ExternalCacheExtension.java branches/eugene-2.0/maven-eugene-plugin/pom.xml branches/eugene-2.0/pom.xml Log: - must takes account of variable array in import manager - fix filename of a classifier with a generic declaration - move eugene-test to an integration test in maven-eugene-plugin - remove weaker exception Modified: branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/java/JavaBuilder.java =================================================================== --- branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/java/JavaBuilder.java 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/java/JavaBuilder.java 2009-12-14 01:57:24 UTC (rev 749) @@ -102,6 +102,11 @@ return; } ImportsManager manager = managers.getManager(classifier); + imports = imports.trim(); + // remove ... operator + if (imports.endsWith("...")) { + imports = imports.substring(0, imports.length() - 3); + } for (String oneType : GeneratorUtil.getTypesList(imports)) { manager.addImport(oneType); if (log.isDebugEnabled()) { Modified: branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/java/JavaGenerator.java =================================================================== --- branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/java/JavaGenerator.java 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/java/JavaGenerator.java 2009-12-14 01:57:24 UTC (rev 749) @@ -75,7 +75,12 @@ @Override public String getFilenameForClassifier(ObjectModelClassifier clazz) { - return clazz.getQualifiedName().replace('.', File.separatorChar) + ".java"; + String s = clazz.getQualifiedName(); + int index = s.indexOf("<"); + if (index > -1) { + s = s.substring(0, index); + } + return s.replace('.', File.separatorChar) + ".java"; } /** @@ -114,6 +119,9 @@ implement += ", "; } } + if (log.isInfoEnabled()) { + log.info(className+" : super : "+extend+", interfaces : "+implement); + } /*{ <%=prefix%>public<%=abstractStr%>class <%=className%>}*/ @@ -263,8 +271,8 @@ Arrays.fill(tmp, ' '); prefix = new String(tmp); } - if (log.isInfoEnabled()) { - log.info("prefix to use for classifier " + clazz.getName() + " : [" + prefix + "]"); + if (log.isDebugEnabled()) { + log.debug("prefix to use for classifier " + clazz.getName() + " : [" + prefix + "]"); } } Modified: branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelModifier.java =================================================================== --- branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelModifier.java 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelModifier.java 2009-12-14 01:57:24 UTC (rev 749) @@ -34,12 +34,22 @@ */ public enum ObjectModelModifier { - STATIC("static"), FINAL("final"), ABSTRACT("abstract"), - PUBLIC("public"), PROTECTED("protected"), PRIVATE("private"), PACKAGE(""), + STATIC("static"), + FINAL("final"), + ABSTRACT("abstract"), + + PUBLIC("public"), + PROTECTED("protected"), + PRIVATE("private"), + PACKAGE(""), - AGGREGATE("aggregate"), COMPOSITE("composite"), UNIQUE("unique"), - ORDERED("ordered"), NAVIGABLE("navigable"); + AGGREGATE("aggregate"), + COMPOSITE("composite"), + UNIQUE("unique"), + ORDERED("ordered"), + NAVIGABLE("navigable"); + private String stringValue; ObjectModelModifier(String stringValue) { @@ -60,18 +70,6 @@ @Override public String toString() { -// switch (this) { -// //case STATIC: return "static"; -// //case ABSTRACT: return "abstract"; -// //case FINAL: return "final"; -// case PUBLIC: return "public"; -// case PRIVATE: return "private"; -// case PROTECTED: return "protected"; -// case PACKAGE: return ""; -// case ORDERED: return "ordered"; -// case AGGREGATE: return "aggregate"; -// case COMPOSITE: return "composite"; -// } return stringValue; } Modified: branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ExternalCacheExtension.java =================================================================== --- branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ExternalCacheExtension.java 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ExternalCacheExtension.java 2009-12-14 01:57:24 UTC (rev 749) @@ -52,7 +52,7 @@ @SuppressWarnings("unchecked") public <C extends ObjectModelClassifierImpl> C getCache(ObjectModelImplRef reference, Class<C> classifierClass) - throws ClassCastException, RuntimeException { + throws RuntimeException { ObjectModelClassifierImpl classifier = cache.get(reference.getName()); C result; if (classifier != null && !classifierClass.isAssignableFrom(classifier.getClass())) { Deleted: branches/eugene-2.0/eugene-test/pom.xml =================================================================== --- branches/eugene-2.0/eugene-test/pom.xml 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene-test/pom.xml 2009-12-14 01:57:24 UTC (rev 749) @@ -1,175 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - - <!-- ************************************************************* --> - <!-- *** POM Relationships *************************************** --> - <!-- ************************************************************* --> - <parent> - <groupId>org.nuiton</groupId> - <artifactId>eugene</artifactId> - <version>2.0.0-beta-2-SNAPSHOT</version> - </parent> - - <groupId>org.nuiton.eugene</groupId> - <artifactId>eugene-test</artifactId> - - <dependencies> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>eugene</artifactId> - <version>${project.version}</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - - <name>EUGene :: Test</name> - <description>Test module for generators.</description> - <inceptionYear>2007</inceptionYear> - - <contributors> - <contributor> - <name>Florian Desbois</name> - <email>fdesbois@codelutin.com</email> - <timezone>+2</timezone> - <roles> - <role>Developpeur</role> - </roles> - </contributor> - </contributors> - - <!-- ************************************************************* --> - <!-- *** Build Settings ****************************************** --> - <!-- ************************************************************* --> - - <packaging>jar</packaging> - - <properties> - <processor.version>1.0.2-SNAPSHOT</processor.version> - - </properties> - - <build> - - <plugins> - - <plugin> - <groupId>org.nuiton.processor</groupId> - <artifactId>maven-processor-plugin</artifactId> - <executions> - <execution> - <phase>generate-sources</phase> - <goals> - <goal>process</goal> - </goals> - </execution> - </executions> - <configuration> - <includes>**/*.java</includes> - <filters> - org.nuiton.processor.filters.GeneratorTemplatesFilter - </filters> - </configuration> - </plugin> - - <plugin> - <groupId>org.nuiton.eugene</groupId> - <artifactId>maven-eugene-plugin</artifactId> - <version>${project.version}</version> - <executions> - <execution> - <id>Test Regression Generator</id> - <phase>generate-test-sources</phase> - <configuration> - <reader>org.nuiton.eugene.ObjectModelReader</reader> - <includes>dtotest.objectmodel</includes> - <templates>org.nuiton.eugene.test.generator.BeanGenerator</templates> - <defaultPackage>org.nuiton.eugene.test</defaultPackage> - <extraClassPathDirectory>target/classes</extraClassPathDirectory> - <generateResources> - <input>src/main/models</input> - </generateResources> - </configuration> - <goals> - <goal>generate</goal> - </goals> - </execution> - <execution> - <id>Test Java Generator</id> - <phase>generate-test-sources</phase> - <configuration> - <reader>org.nuiton.eugene.test.generator.TestReader</reader> - <templates>org.nuiton.eugene.java.JavaGenerator</templates> - <defaultPackage>org.nuiton.eugene.test</defaultPackage> - <extraClassPathDirectory>target/classes</extraClassPathDirectory> - <generateResources> - <input>src/main/models</input> - </generateResources> - </configuration> - <goals> - <goal>generate</goal> - </goals> - </execution> - <execution> - <id>Test Bean Transformer</id> - <phase>generate-test-sources</phase> - <configuration> - <reader>org.nuiton.eugene.ObjectModelReader</reader> - <includes>dtotest2.objectmodel</includes> - <templates>org.nuiton.eugene.test.generator.BeanTransformer</templates> - <defaultPackage>org.nuiton.eugene.test</defaultPackage> - <extraClassPathDirectory>target/classes</extraClassPathDirectory> - <generateResources> - <input>src/main/models</input> - </generateResources> - </configuration> - <goals> - <goal>generate</goal> - </goals> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.14</version> - </dependency> - </dependencies> - </plugin> - - <!--plugin> - <groupId>org.nuiton.i18n</groupId> - <artifactId>maven-i18n-plugin</artifactId> - <version>${i18n.version}</version> - </plugin> - - <plugin> - <artifactId>maven-site-plugin</artifactId> - <dependencies> - <dependency> - <groupId>org.nuiton.jrst</groupId> - <artifactId>doxia-module-jrst</artifactId> - <version>${jrst.version}</version> - </dependency> - </dependencies> - </plugin--> - - </plugins> - </build> - -</project> - - Deleted: branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java =================================================================== --- branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java 2009-12-14 01:57:24 UTC (rev 749) @@ -1,620 +0,0 @@ -/* *##% - * EUGene Test - * Copyright (C) 2007 - 2009 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>. - * ##%*/ - -/* * -* BeanGenerator.java -* -* Created: 17 avril 2009 -* -* @author tony Chemit <chemit@codelutin.com> -* @version $Revision: 1334 $ -* -* Mise a jour: $Date: 2009-01-29 16:47:42 +0100 (jeu 29 jan 2009) $ -* par : $Author: chemit $ -*/ - -package org.nuiton.eugene.test.generator; - -import static org.nuiton.eugene.test.generator.TopiaGeneratorUtil.TAG_ANNOTATION; - -import java.io.File; -import java.io.IOException; -import java.io.Serializable; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; - -import java.util.List; -import java.util.Set; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.eugene.ObjectModelGenerator; -import org.nuiton.eugene.GeneratorUtil; -import org.nuiton.eugene.ImportsManager; -import org.nuiton.eugene.models.object.ObjectModelAttribute; -import org.nuiton.eugene.models.object.ObjectModelClass; -import org.nuiton.eugene.models.object.ObjectModelClassifier; -import org.nuiton.eugene.models.object.ObjectModelDependency; -import org.nuiton.eugene.models.object.ObjectModelInterface; -import org.nuiton.eugene.models.object.ObjectModelOperation; -import org.nuiton.eugene.models.object.ObjectModelParameter; -//import org.nuiton.topia.persistence.TopiaEntity; -import static org.nuiton.eugene.test.generator.TopiaGeneratorUtil.isPrimitiveType; -import static org.nuiton.eugene.test.generator.TopiaGeneratorUtil.isDateType; - -/** - * DTO generator - */ -public class BeanGenerator extends ObjectModelGenerator { - - /** - * Logger for this class - */ - private static final Log log = LogFactory.getLog(BeanGenerator.class); - - public BeanGenerator() { - super(); - } - - @Override - public String getFilenameForClass(ObjectModelClass clazz) { - return clazz.getQualifiedName().replace('.', File.separatorChar) + ".java"; - } - - @Override - public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { - if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_BEAN) && - !clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) { - return; - } - // - // première phase : calcul des variables - // - String copyright = TopiaGeneratorUtil.getCopyright(model); - String clazzName = clazz.getName(); - String abstractStr = isAbstract(clazz) ? " abstract " : " "; - boolean needGetEntityMethod = false; - boolean generateToString = TopiaGeneratorUtil.generateToString(clazz, model); - - ImportsManager imports = new ImportsManager(); - - String extendClass = ""; - Iterator<ObjectModelClass> j = clazz.getSuperclasses().iterator(); - if (j.hasNext()) { - ObjectModelClassifier p = j.next(); - imports.addImport(p.getQualifiedName()); - extendClass += p.getName(); - } - String implInterface = ""; - for (Iterator<ObjectModelInterface> i=clazz.getInterfaces().iterator(); i.hasNext();) { - ObjectModelClassifier parentInterface = i.next(); - imports.addImport(parentInterface.getQualifiedName()); - implInterface += parentInterface.getName(); - if (i.hasNext()) { - implInterface += ", "; - } - } - // Add Serializable implements for DTO generation - if (clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) { - imports.addImport(Serializable.class); - if (!implInterface.isEmpty()) { - implInterface += ", "; - } - implInterface += Serializable.class.getName(); - } - String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", clazz, model); - - List<ObjectModelAttribute> attributes = new ArrayList<ObjectModelAttribute>(); - List<ObjectModelAttribute> multipleAttr = new ArrayList<ObjectModelAttribute>(); - - setAttributesForDTO(clazz, attributes,imports); - - boolean needListInImport=false; - - for (ObjectModelAttribute attr : clazz.getAttributes()) { - if (attr.isNavigable()) { - attributes.add(attr); - imports.addImport(attr.getType()); - if (GeneratorUtil.isNMultiplicity(attr)) { - multipleAttr.add(attr); - ObjectModelClass attrEntity = null; - if (model.hasClass(attr.getType())) { - attrEntity = model.getClass(attr.getType()); - } - boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)); - needGetEntityMethod |= isEntity; - if (attr.isOrdered()) { - needListInImport = true; - } - } - } - } - - imports.addImport(java.beans.PropertyChangeListener.class.getName()); - imports.addImport(java.beans.PropertyChangeSupport.class.getName()); - - for (ObjectModelOperation operation : clazz.getOperations()) { - imports.addImport(operation.getReturnType()); - for (ObjectModelParameter parameter : operation.getParameters()) { - imports.addImport(parameter.getType()); - } - } - - if (needGetEntityMethod) { - imports.addImport("org.nuiton.topia.persistence.TopiaEntity"); - } - if (!multipleAttr.isEmpty()) { - imports.addImport(Collection.class); - } - if (needListInImport) { - imports.addImport(List.class); - } - if (generateToString) { - imports.addImport(org.apache.commons.lang.builder.ToStringBuilder.class); - } - - boolean sortAttribute = TopiaGeneratorUtil.sortAttribute(clazz, model); - if (sortAttribute) { - Comparator<ObjectModelAttribute> comp = new Comparator<ObjectModelAttribute>(){ - - @Override - public int compare(ObjectModelAttribute o1, ObjectModelAttribute o2) { - return o1.getName().compareTo(o2.getName()); - } - }; - java.util.Collections.sort(attributes,comp); - java.util.Collections.sort(multipleAttr,comp); - } - // - // seconde phase : génération - // - - if (TopiaGeneratorUtil.notEmpty(copyright)) { -/*{<%=copyright%> -}*/ - } - -/*{package <%=clazz.getPackageName()%>; - - }*/ - - if (log.isDebugEnabled()) { - log.debug("imports for class <" + clazzName + ">"); - } - //for (String anImport : imports) { - for (String anImport : imports.getImports(clazz.getPackageName())) { - if (log.isDebugEnabled()) { - log.debug("import " + anImport); - } -/*{import <%=anImport%>; -}*/ - } -/*{ -public<%=abstractStr%>class <%=clazzName%>}*/ - -/* - * Définition de la super classe : il ne doit y avoir qu'une - */ - if (extendClass.length() > 0) { -/*{ extends <%=extendClass%>}*/ - } - - if (implInterface.length() > 0) { -/*{ implements <%=implInterface%> { - -}*/ - } else { - /*{ { - -}*/ - } - - - // TODO Calculer un serialVersionUID si il n'y en a pas - if (svUID != null) { -/*{ public static final long serialVersionUID = <%=svUID%>; - -}*/ - } - generateInterfaceOperations(output, clazz); - generateAttributes(output, attributes); -/*{ protected final PropertyChangeSupport pcs; - - /** - * Default constructor of <%=clazzName%>. - *) - public <%=clazzName%>() { - pcs = new PropertyChangeSupport(this); - } - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.removePropertyChangeListener(propertyName, listener); - } - -}*/ - generateGetters(output, attributes); - generateSetters(output, attributes); - generateGetChild(output, multipleAttr); - generateAddChild(output, multipleAttr); - generateRemoveChild(output, multipleAttr); - if (generateToString) { - generateToString(output, clazz); - } - if (!multipleAttr.isEmpty()) { -/*{ - - protected <T> T getChild(Collection<T> childs, int index) { - if (childs != null) { - int i = 0; - for (T o : childs) { - if (index == i) { - return o; - } - i++; - } - } - return null; - } - - }*/ - if (needGetEntityMethod) { -/*{ protected <T extends TopiaEntity> T getEntity(Collection<T> childs, String topiaId) { - if (childs != null) { - for (T o : childs) { - if (topiaId.equals(o.getTopiaId())) { - return o; - } - } - } - return null; - } - }*/ - } - } - -/*{ - protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - pcs.firePropertyChange(propertyName, oldValue, newValue); - } - -} //<%=clazz.getName()%> -}*/ - } - - protected void generateAttributes(Writer output, List<ObjectModelAttribute> attributes) throws IOException { - - for (ObjectModelAttribute attr : attributes) { - - if (!(attr.isNavigable() - || attr.hasAssociationClass())) { - continue; - } - - if (TopiaGeneratorUtil.hasDocumentation(attr)) { -/*{ /** - * <%=attr.getDocumentation()%> - *) -}*/ - } - String annotation = attr.getTagValue(TAG_ANNOTATION); - if (annotation != null && annotation.length() > 0) { -/*{ <%=annotation%> -}*/ - } - String attrName = attr.getName(); - String attrVisibility = attr.getVisibility(); - String attrType = attr.getType(); - if (attr.hasAssociationClass()) { - String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); - attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName); - attrType = attr.getAssociationClass().getName(); - } - int dot = attrType.lastIndexOf("."); - if (dot>-1) { - attrType = attrType.substring(dot + 1); - } - if (GeneratorUtil.isNMultiplicity(attr)) { - attrType = getCollection(attr, attrType); - } - -/*{ <%=attrVisibility%> <%=attrType%> <%=attrName%>; -}*/ - } - } - - protected void generateGetters(Writer output, List<ObjectModelAttribute> attributes) throws IOException { - /* - * Définition des getteurs et setteurs - */ - for (ObjectModelAttribute attr : attributes) { - - if (!attr.isNavigable()) { - continue; - } - - String attrName = attr.getName(); - String attrType = attr.getType(); - if (attr.hasAssociationClass()) { - String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); - attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName); - attrType = attr.getAssociationClass().getName(); - } - String attrNameCapitalized = GeneratorUtil.capitalize(attrName); - int dot = attrType.lastIndexOf("."); - if (dot>-1) { - attrType = attrType.substring(dot + 1); - } - if (GeneratorUtil.isNMultiplicity(attr)) { - attrType = getCollection(attr, attrType); - } -/*{ public <%=attrType%> get<%=attrNameCapitalized%>() { - return <%=attrName%>; - } - -}*/ - } - } - - protected void generateSetters(Writer output, List<ObjectModelAttribute> attributes) throws IOException { - /* - * Définition des getteurs et setteurs - */ - for (ObjectModelAttribute attr : attributes) { - - if (!attr.isNavigable()) { - continue; - } - - String attrName = attr.getName(); - String attrType = attr.getType(); - - if (attr.hasAssociationClass()) { - String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); - attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName); - attrType = attr.getAssociationClass().getName(); - } - String attrNameCapitalized = GeneratorUtil.capitalize(attrName); - int dot = attrType.lastIndexOf("."); - if (dot>-1) { - attrType = attrType.substring(dot + 1); - } - if (GeneratorUtil.isNMultiplicity(attr)) { - attrType = getCollection(attr, attrType); - } -/*{ public void set<%=attrNameCapitalized%>(<%=attrType%> newValue) { - <%=attrType%> oldValue = get<%=attrNameCapitalized%>(); - this.<%=attrName%> = newValue; - firePropertyChange("<%=attrName%>", oldValue, newValue); - } - -}*/ - } - } - - protected void generateGetChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException { - - for (ObjectModelAttribute attr : multipleAttr) { - - String attrName = attr.getName(); - String attrNameCapitalized = GeneratorUtil.capitalize(attrName); - String attrType = attr.getType(); - int dot = attrType.lastIndexOf("."); - if (dot>-1) { - attrType = attrType.substring(dot + 1); - } - ObjectModelClass attrEntity=null; - if (model.hasClass(attr.getType())) { - attrEntity = model.getClass(attr.getType()); - } - boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)); -/*{ public <%=attrType%> get<%=attrNameCapitalized%>(int index) { - <%=attrType%> o = getChild(<%=attrName%>, index); - return o; - } - -}*/ - if (isEntity) { -/*{ public <%=attrType%> get<%=attrNameCapitalized%>(String topiaId) { - <%=attrType%> o = getEntity(<%=attrName%>, topiaId); - return o; - } - -}*/ - } - } - } - protected void generateAddChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException { - for (ObjectModelAttribute attr : multipleAttr) { - - String attrName = attr.getName(); - String attrNameCapitalized = GeneratorUtil.capitalize(attrName); - String attrType = attr.getType(); - int dot = attrType.lastIndexOf("."); - if (dot>-1) { - attrType = attrType.substring(dot + 1); - } -/*{ public <%=attrType%> add<%=attrNameCapitalized%>(<%=attrType%> <%=attrName%>) { - get<%=attrNameCapitalized%>().add(<%=attrName%>); - firePropertyChange("<%=attrName%>", null, <%=attrName%>); - return <%=attrName%>; - } - -}*/ - } - } - - protected void generateRemoveChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException { - for (ObjectModelAttribute attr : multipleAttr) { - String attrName = attr.getName(); - String attrNameCapitalized = GeneratorUtil.capitalize(attrName); - String attrType = attr.getType(); - int dot = attrType.lastIndexOf("."); - if (dot>-1) { - attrType = attrType.substring(dot + 1); - } -/*{ public boolean remove<%=attrNameCapitalized%>(<%=attrType%> <%=attrName%>) { - boolean removed = get<%=attrNameCapitalized%>().remove(<%=attrName%>); - if (removed) { - firePropertyChange("<%=attrName%>", <%=attrName%>, null); - } - return removed; - } - -}*/ - } - } - - protected void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException { - for (ObjectModelOperation op : classifier.getOperations()) { - String opName = op.getName(); -/*{ /** -}*/ - if (TopiaGeneratorUtil.hasDocumentation(op)) { - String opDocumentation = op.getDocumentation(); -/*{ * <%=opName%> : <%=opDocumentation%> -}*/ - } - Collection<ObjectModelParameter> params = op.getParameters(); - for (ObjectModelParameter param : params) { - String paramName = param.getName(); - String paramDocumentation = param.getDocumentation(); -/*{ * @param <%=paramName%> <%=paramDocumentation%> - }*/ - } - String opVisibility = op.getVisibility(); - String opType = op.getReturnType(); -/*{ *) - <%=opVisibility%> abstract <%=opType%> <%=opName%>(}*/ - String comma = ""; - for (ObjectModelParameter param : params) { - String paramName = param.getName(); - String paramType = param.getType(); -/*{<%=comma%><%=paramType%> <%=paramName%>}*/ - comma = ", "; - } -/*{)}*/ - Set<String> exceptions = op.getExceptions(); - comma = " throws "; - for (String exception : exceptions) { -/*{<%=comma%><%=exception%>}*/ - comma = ", "; - } -/*{; - -}*/ - } - } - protected void generateToString(Writer output, ObjectModelClass clazz) throws IOException { -/*{ - @Override - public String toString() { - String result = new ToStringBuilder(this). -}*/ - for (ObjectModelAttribute attr : clazz.getAttributes()) { - if (!(attr.isNavigable() || attr.hasAssociationClass())) { - continue; - } - //FIXME possibilité de boucles (non directes) - String attrName = attr.getName(); -/*{ append("<%=attrName%>", this.<%=attrName%>). -}*/ - } -/*{ toString(); - return result; - } - }*/ - } - - protected String getCollection(ObjectModelAttribute attr, String attrType) { - String nMultType; - if (attr.isOrdered()) { - nMultType = "List<"; - } else { - nMultType = "Collection<"; - } - nMultType += attrType; - nMultType += ">"; - return nMultType; - } - - protected boolean isAbstract(ObjectModelClass clazz) { - if (clazz.isAbstract()) { - return true; - } - return !clazz.getOperations().isEmpty(); - } - - /** - * Dependecy gestion for DTO generation. - * All primitives attributes (and dates) of dependencies entities of the DTO are - * copied in the DTO. This method only prepare a list of attributes to be generated. - * @param clazz DTO ObjectModelClass - * @param attributes list of attributes for the generation (may be not empty) - * @param imports the ImportsManager used to generate the header imports of the DTO - * @return the same list of attributes in parameter with attributes from entities dependencies - * @see org.nuiton.eugene.ImportsManager - * @see org.nuiton.eugene.models.object.ObjectModelDependency - */ - private List<ObjectModelAttribute> setAttributesForDTO(ObjectModelClass clazz, - List<ObjectModelAttribute> attributes, ImportsManager imports) { - - if (clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) { - if (log.isInfoEnabled()) { - log.info("DTO dependency gestion"); - } - for (ObjectModelDependency dependency : clazz.getDependencies()) { - ObjectModelClass supplier = (ObjectModelClass)dependency.getSupplier(); - - // ENTITY dependency - // Copy all primitives attributes from the Entity (supplier) to the DTO - // Prepare a list to future generation of all object generated attributes - if (supplier.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) { - if (log.isInfoEnabled()) { - log.info("Create primitive and date fields in DTO from Entity : " - + supplier.getQualifiedName()); - } - for (ObjectModelAttribute attr : supplier.getAttributes()) { - if (isPrimitiveType(attr) || isDateType(attr)) { - attributes.add(attr); - imports.addImport(attr.getType()); - } - if (GeneratorUtil.isNMultiplicity(attr)) { - imports.addImport("java.util.Collection"); - } - } - } - } - } - return attributes; - } -} //BeanGenerator Deleted: branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java =================================================================== --- branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java 2009-12-14 01:57:24 UTC (rev 749) @@ -1,342 +0,0 @@ -/* - * *##% - * EUGene Test - * Copyright (C) 2007 - 2009 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>. - * ##%* - */ -package org.nuiton.eugene.test.generator; - -import org.apache.commons.lang.StringUtils; -import org.nuiton.eugene.GeneratorUtil; -import org.nuiton.eugene.java.ObjectModelTransformerToJava; -import org.nuiton.eugene.models.object.*; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -/*{generator option: parentheses = false}*/ - -/*{generator option: writeString = +}*/ -/** - * BeanTransformer - * <p/> - * Created: 28 oct. 2009 - * - * @author fdesbois - * @version $Revision$ - * <p/> - * Mise a jour: $Date$ - * par : $Author$ - */ -public class BeanTransformer extends ObjectModelTransformerToJava { - - public BeanTransformer() { - super(); - } - - @Override - public void transformFromClass(ObjectModelClass clazz) { - if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_BEAN) && - !clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) { - return; - } - - ObjectModelClass resultClass = null; - if (!clazz.getOperations().isEmpty()) { - resultClass = createAbstractClass(clazz.getName(), clazz.getPackageName()); - } else { - resultClass = createClass(clazz.getName(), clazz.getPackageName()); - } - - createForDTO(resultClass, clazz); - - // Set superclass - Iterator<ObjectModelClass> j = clazz.getSuperclasses().iterator(); - if (j.hasNext()) { - ObjectModelClass p = j.next(); - setSuperClass(resultClass, p.getQualifiedName()); - } - - // Add interfaces from inputModel - for (Iterator<ObjectModelInterface> i = clazz.getInterfaces().iterator(); i.hasNext();) { - ObjectModelClassifier parentInterface = i.next(); - addInterface(resultClass, parentInterface.getQualifiedName()); - } - - createListeners(resultClass, clazz); - - boolean hasEntity = false; - boolean hasMultipleAttribute = false; - - // Add attributes with getter/setter - for (ObjectModelAttribute attr : clazz.getAttributes()) { - - if (attr.isNavigable()/* || attr.hasAssociationClass()*/) { - String attrType = attr.getType(); - String simpleType = GeneratorUtil.getSimpleName(attrType); - String attrName = attr.getName(); - String attrNameCapitalized = StringUtils.capitalize(attrName); - - // multiple attribute - if (GeneratorUtil.isNMultiplicity(attr)) { - hasMultipleAttribute = true; - - // Add getChild - ObjectModelOperation getChild = addOperation(resultClass, "get" + attrNameCapitalized, - attrType, ObjectModelModifier.PUBLIC); - addParameter(getChild, "int", "index"); - setOperationBody(getChild, "" - /*{ - <%=simpleType%> o = getChild(<%=attrName%>, index); - return o; - }*/ - ); - - // Add getEntity - ObjectModelClass attrEntity = null; - if (getModel().hasClass(attr.getType())) { - attrEntity = getModel().getClass(attr.getType()); - } - boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)); - - if (isEntity) { - hasEntity = true; - ObjectModelOperation getChildEntity = addOperation(resultClass, "get" + attrNameCapitalized, - attrType, ObjectModelModifier.PUBLIC); - addParameter(getChildEntity, String.class.getName(), "topiaId"); - setOperationBody(getChildEntity, "" - /*{ - <%=simpleType%> o = getEntity(<%=attrName%>, topiaId); - return o; - }*/ - ); - } - - // Add addChild - ObjectModelOperation addChild = addOperation(resultClass, "add" + attrNameCapitalized, - attrType, ObjectModelModifier.PUBLIC); - addParameter(addChild, attrType, attrName); - setOperationBody(addChild, "" - - /*{ - get<%=attrNameCapitalized%>().add(<%=attrName%>); - firePropertyChange("<%=attrName%>", null, <%=attrName%>); - return <%=attrName%>; - }*/ - ); - - // Add removeChild - ObjectModelOperation removeChild = addOperation(resultClass, "remove" + attrNameCapitalized, - "boolean", ObjectModelModifier.PUBLIC); - addParameter(removeChild, attrType, attrName); - setOperationBody(removeChild, "" - - /*{ - boolean removed = get<%=attrNameCapitalized%>().remove(<%=attrName%>); - if (removed) { - firePropertyChange("<%=attrName%>", <%=attrName%>, null); - } - return removed; - }*/ - ); - - // Change type for Multiple attribute - if (attr.isOrdered()) { - attrType = List.class.getName() + "<" + attrType + ">"; - } else { - attrType = Collection.class.getName() + "<" + attrType + ">"; - } - simpleType = GeneratorUtil.getSimpleName(attrType); - } - - if (attr.hasAssociationClass()) { - String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); - attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName); - attrType = attr.getAssociationClass().getName(); - } - - // Add attribute - String visibility = attr.getVisibility(); - addAttribute(resultClass, attrName, attrType, "", ObjectModelModifier.toValue(visibility)); - - // Add getter - ObjectModelOperation getter = addOperation(resultClass, "get" + attrNameCapitalized, attrType, - ObjectModelModifier.PUBLIC); - setOperationBody(getter, "" - /*{ - return this.<%=attrName%>; - }*/ - ); - - // Add setter - ObjectModelOperation setter = addOperation(resultClass, "set" + attrNameCapitalized, "void", - ObjectModelModifier.PUBLIC); - addParameter(setter, attrType, "newValue"); - setOperationBody(setter, "" - /*{ - <%=simpleType%> oldValue = get<%=attrNameCapitalized%>(); - this.<%=attrName%> = newValue; - firePropertyChange("<%=attrName%>", oldValue, newValue); - }*/ - ); - - } - } - - // Add helper methods - if (hasMultipleAttribute) { - ObjectModelOperation getChild = addOperation(resultClass, "getChild", "<T> T", - ObjectModelModifier.PROTECTED); - addParameter(getChild, "java.util.Collection<T>", "childs"); - addParameter(getChild, "int", "index"); - setOperationBody(getChild, "" - /*{ - if (childs != null) { - int i = 0; - for (T o : childs) { - if (index == i) { - return o; - } - i++; - } - } - return null; - }*/ - ); - } - - if (hasEntity) { - ObjectModelOperation getEntity = addOperation(resultClass, "getEntity", - "<T extends org.nuiton.topia.persistence.TopiaEntity> T", ObjectModelModifier.PROTECTED); - addParameter(getEntity, "java.util.Collection<T>", "childs"); - addParameter(getEntity, "java.lang.String", "topiaId"); - setOperationBody(getEntity, "" - /*{ - if (childs != null) { - for (T o : childs) { - if (topiaId.equals(o.getTopiaId())) { - return o; - } - } - } - return null; - }*/ - ); - } - - // Add operations - for (ObjectModelOperation op : clazz.getOperations()) { - String visibility = op.getVisibility(); - ObjectModelOperation resultOperation = addOperation(resultClass, op.getName(), op.getReturnType(), - ObjectModelModifier.toValue(visibility), ObjectModelModifier.ABSTRACT); - - for (ObjectModelParameter param : op.getParameters()) { - addParameter(resultOperation, param.getType(), param.getName()); - } - - for (String exception : op.getExceptions()) { - addException(resultOperation, exception); - } - } - - - } - - private void createForDTO(ObjectModelClass resultClass, ObjectModelClass inputClass) { - - // Add Serializable implements for DTO generation - if (inputClass.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) { - addInterface(resultClass, "java.io.Serializable"); - } - - String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", inputClass, getModel()); - if (svUID != null) { - addConstant(resultClass, "serialVersionUID", "long", svUID, ObjectModelModifier.PUBLIC); - } - } - - protected void createListeners(ObjectModelClass resultClass, ObjectModelClass inputClass) { - - addAttribute(resultClass, "pcs", "java.beans.PropertyChangeSupport", "", - ObjectModelModifier.PROTECTED, ObjectModelModifier.FINAL); - - // Default constructor - ObjectModelOperation constructor = addConstructor(resultClass, ObjectModelModifier.PUBLIC); - setOperationBody(constructor, "" - /*{ - pcs = new PropertyChangeSupport(this); - }*/ - ); - - // Add PropertyListener - String propType = "java.beans.PropertyChangeListener"; - String strType = String.class.getName(); - String objectType = Object.class.getName(); - - ObjectModelOperation addPropertyChangeListener = addOperation(resultClass, - "addPropertyChangeListener", "void", ObjectModelModifier.PUBLIC); - addParameter(addPropertyChangeListener, propType, "listener"); - setOperationBody(addPropertyChangeListener, "" - /*{ - pcs.addPropertyChangeListener(listener); - }*/ - ); - - ObjectModelOperation addPropertyChangeListenerPlus = addOperation(resultClass, - "addPropertyChangeListener", "void", ObjectModelModifier.PUBLIC); - addParameter(addPropertyChangeListenerPlus, strType, "propertyName"); - addParameter(addPropertyChangeListenerPlus, propType, "listener"); - setOperationBody(addPropertyChangeListenerPlus, "" - /*{ - pcs.addPropertyChangeListener(propertyName, listener); - }*/ - ); - - ObjectModelOperation removePropertyChangeListener = addOperation(resultClass, - "removePropertyChangeListener", "void", ObjectModelModifier.PUBLIC); - addParameter(removePropertyChangeListener, propType, "listener"); - setOperationBody(removePropertyChangeListener, "" - /*{ - pcs.removePropertyChangeListener(listener); - }*/ - ); - - ObjectModelOperation removePropertyChangeListenerPlus = addOperation(resultClass, - "removePropertyChangeListener", "void", ObjectModelModifier.PUBLIC); - addParameter(removePropertyChangeListenerPlus, strType, "propertyName"); - addParameter(removePropertyChangeListenerPlus, propType, "listener"); - setOperationBody(removePropertyChangeListenerPlus, "" - /*{ - pcs.removePropertyChangeListener(propertyName, listener); - }*/ - ); - - ObjectModelOperation firePropertyChange = addOperation(resultClass, - "firePropertyChange", "void", ObjectModelModifier.PROTECTED); - addParameter(firePropertyChange, strType, "propertyName"); - addParameter(firePropertyChange, objectType, "oldValue"); - addParameter(firePropertyChange, objectType, "newValue"); - setOperationBody(firePropertyChange, "" - /*{ - pcs.firePropertyChange(propertyName, oldValue, newValue); - }*/ - ); - } - - -} Deleted: branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/Megatron.java =================================================================== --- branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/Megatron.java 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/Megatron.java 2009-12-14 01:57:24 UTC (rev 749) @@ -1,41 +0,0 @@ - -package org.nuiton.eugene.test.generator; - -import org.nuiton.eugene.java.ObjectModelTransformerToJava; -import org.nuiton.eugene.models.object.ObjectModelClass; - -/** - * Megatron - * - * Chainage des transformer : Modele de depart -> transformation dans BeanTransformer = modele d'entrée de Megatron - * - * Created: 12 nov. 2009 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -public class Megatron extends ObjectModelTransformerToJava { - - public Megatron() { - super(); - } - - /* - CAS modele de sortie vide : modele d'entree transformee par BeanTransformer - */ - @Override - protected ObjectModelTransformerToJava initPreviousTransformer() { - return new BeanTransformer(); - } - - @Override - public void transformFromClass(ObjectModelClass clazz) { - - - - } - -} Deleted: branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java =================================================================== --- branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java 2009-12-14 01:57:24 UTC (rev 749) @@ -1,93 +0,0 @@ -/* - * *##% - * EUGene Test - * Copyright (C) 2007 - 2009 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>. - * ##%* - */ - -package org.nuiton.eugene.test.generator; - -import org.nuiton.eugene.java.JavaBuilder; -import org.nuiton.eugene.models.object.ObjectModelClass; -import org.nuiton.eugene.models.object.ObjectModelModifier; -import org.nuiton.eugene.models.object.ObjectModelOperation; - -/*{generator option: parentheses = false}*/ -/*{generator option: writeString = +}*/ -/** - * TestBuilder - * - * Created: 25 oct. 2009 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -public class TestBuilder extends JavaBuilder { - - public TestBuilder() { - super("TestModel"); - } - - //@Override - public void build() { - createRole(); - createPerson(); - } - - private void createRole() { - ObjectModelClass roleClass = createClass("Role", "org.chorem.bonzoms"); - - addAttribute(roleClass, "name", "java.lang.String"); - - //this.addImportForClassifier(roleClass, Date.class); - addAttribute(roleClass, "fromDate", "java.util.Date"); - addAttribute(roleClass, "thruDate", "java.util.Date"); - } - - private void createPerson() { - ObjectModelClass personneClass = createClass("Person", "org.chorem.bonzoms"); - - addAttribute(personneClass, "lastName", "java.lang.String"); - addAttribute(personneClass, "firstName", "java.lang.String", "\"2.0\""); - - //this.addImportForClassifier(personneClass, List.class); - addAttribute(personneClass, "roles", "java.util.List<org.chorem.bonzoms.Role>", - "new java.util.ArrayList<org.chorem.bonzoms.Role>()"); - - - ObjectModelOperation setLastName = addOperation(personneClass, "setLastName", "void", - ObjectModelModifier.PUBLIC); - addParameter(setLastName, "java.lang.String", "lastName"); - setOperationBody(setLastName, "" - /*{ - this.lastName = lastName; - }*/ - ); - - ObjectModelOperation getLastName = addOperation(personneClass, "getLastName", "java.lang.String", - ObjectModelModifier.PUBLIC); - setOperationBody(getLastName, "" - /*{ - return this.lastName; - }*/ - ); - } - -} Deleted: branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestReader.java =================================================================== --- branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestReader.java 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestReader.java 2009-12-14 01:57:24 UTC (rev 749) @@ -1,51 +0,0 @@ -/* - * *##% - * EUGene Test - * Copyright (C) 2007 - 2009 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>. - * ##%* - */ - -package org.nuiton.eugene.test.generator; - -import java.io.File; -import org.nuiton.eugene.ModelReader; -import org.nuiton.eugene.models.object.ObjectModel; - -/** - * TestReader - * - * Created: 27 oct. 2009 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -public class TestReader extends ModelReader<ObjectModel> { - - - @Override - public ObjectModel read(File[] file) { - TestBuilder builder = new TestBuilder(); - - builder.build(); - - return builder.getModel(); - } - -} Deleted: branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java =================================================================== --- branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java 2009-12-14 01:57:24 UTC (rev 749) @@ -1,948 +0,0 @@ -/* *##% - * EUGene Test - * Copyright (C) 2007 - 2009 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>. - * ##%*/ -/******************************************************************************* - * GeneratorUtil.java - * - * Created: 13 déc. 2005 - * - * @author Arnaud Thimel <thimel@codelutin.com> - * - * @version $Revision: 1298 $ - * - * Mise a jour: $Date: 2009-01-15 00:01:45 +0100 (jeu 15 jan 2009) $ par : $Author: tchemit $ - */ -package org.nuiton.eugene.test.generator; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import org.apache.commons.lang.StringUtils; -import org.nuiton.eugene.Template; -import org.nuiton.eugene.GeneratorUtil; -import org.nuiton.eugene.models.Model; -import org.nuiton.eugene.models.object.ObjectModel; -import org.nuiton.eugene.models.object.ObjectModelAssociationClass; -import org.nuiton.eugene.models.object.ObjectModelAttribute; -import org.nuiton.eugene.models.object.ObjectModelClass; -import org.nuiton.eugene.models.object.ObjectModelElement; -import org.nuiton.eugene.models.object.ObjectModelInterface; -import org.nuiton.eugene.models.object.ObjectModelOperation; -import org.nuiton.eugene.models.object.ObjectModelParameter; - -/** Classe regroupant divers méthodes utiles pour la génération des entités */ -public class TopiaGeneratorUtil extends GeneratorUtil { - - /** Stéréotype pour les interfaces devant être générées sous forme de facades */ - public final static String STEREOTYPE_FACADE = "facade"; - /** Stéréotype pour les objets devant être générées sous forme d'entités */ - public static final String STEREOTYPE_ENTITY = "entity"; - /** Stéréotype pour les objets devant être générées sous forme de DTO */ - public static final String STEREOTYPE_DTO = "dto"; - /** Stéréotype pour les objets devant être générées sous forme de bean */ - public static final String STEREOTYPE_BEAN = "bean"; - /** - * Stéréotype pour les interfaces devant être générées sous forme de - * services - */ - public static final String STEREOTYPE_SERVICE = "service"; - /** Stéréotype pour les interfaces devant être générées sous forme de DAO */ - public static final String STEREOTYPE_DAO = "dao"; - /** Stéréotype pour les attributs à indexer en base */ - public static final String STEREOTYPE_INDEXED = "indexed"; - /** Stéréotype pour les collections avec unicité */ - public static final String STEREOTYPE_UNIQUE = "unique"; - /** Stéréotype pour les attributs étant des clés primaires */ - public static final String STEREOTYPE_PRIMARYKAY = "primaryKey"; - /** Tag pour le type de persistence */ - public static final String TAG_PERSISTENCE_TYPE = "persistenceType"; - /** Tag pour le nom du champ / entité en BD */ - public static final String TAG_DB_NAME = "dbName"; - /** Tag pour le nom du schema en BD */ - public static final String TAG_SCHEMA_NAME = "dbSchema"; - /** Tag pour la taille du champ en BD */ - public static final String TAG_LENGTH = "length"; - /** Tag pour ajouter une annotation à un champ */ - public static final String TAG_ANNOTATION = "annotation"; - /** Tag pour ajouter specifier le copyright d'un fichier */ - public static final String TAG_COPYRIGHT = "copyright"; - /** Tag pour specfier le type d'acces a un champ */ - public static final String TAG_ACCESS = "access"; - /** Tag pour specfier si on doit générer i18n */ - public static final String TAG_I18N_PREFIX = "i18n"; - /** Tag pour ajouter un attribut dans une clef métier */ - public static final String TAG_NATURAL_ID = "naturalId"; - /** Tag pour specifier si une clef metier est mutable */ - public static final String TAG_NATURAL_ID_MUTABLE = "naturalIdMutable"; - /** Tag pour spécifier la caractèrelazy d'une association multiple */ - public static final String TAG_LAZY = "lazy"; - /** Tag pour spécifier la caractère fetch d'une association multiple */ - public static final String TAG_FETCH = "fetch"; - /** Tag pour spécifier la caractère order-by d'une association multiple */ - public static final String TAG_ORDER_BY = "orderBy"; - /** Tag pour spécifier la caractère not-null d'un attribut */ - public static final String TAG_NOT_NULL = "notNull"; - /** Tag pour spécifier la caractère embed-xml d'une association */ - public static final String TAG_EMBED_XML = "embedXml"; - /** - * Tag pour configurer l'interface du proxy sur autre chose que l'implementation par defaut. - * - * Par defaut : - * null > generere le proxy sur l'interface de l'implementation - * Autre valeur : - * "none" > laisse la configuration par defaut d'hibernate - */ - public static final String TAG_PROXY_INTERFACE = "hibernateProxyInterface"; - /** Tag pour spécifier le permissions à la création */ - public static final String TAG_SECURITY_CREATE = "securityCreate"; - /** Tag pour spécifier le permissions au chargement */ - public static final String TAG_SECURITY_LOAD = "securityLoad"; - /** Tag pour spécifier le permissions à la mise à jour */ - public static final String TAG_SECURITY_UPDATE = "securityUpdate"; - /** Tag pour spécifier le permissions à la suppression */ - public static final String TAG_SECURITY_DELETE = "securityDelete"; - /** Tag pour specifier de ne pas generer la methode toString */ - public static final String TAG_NOT_GENERATE_TO_STRING = "notGenerateToString"; - /** Tag pour specifier de trier les attributs par nom lors de la generation */ - public static final String TAG_SORT_ATTRIBUTE = "sortAttribute"; - /** Tag pour specfier si on doit générer la methode getOperator dans les daohelpers )*/ - public static final String TAG_GENERATE_OPERATOR_FOR_DAO_HELPER = "generateOperatorForDAOHelper"; - /** Type de persistence Hibernate */ - public static final String PERSISTENCE_TYPE_HIBERNATE = "hibernate"; - /** Type de persistence LDAP */ - public static final String PERSISTENCE_TYPE_LDAP = "ldap"; - /** Type de persistence par défaut (si aucun précisé) */ - public static final String PERSISTENCE_TYPE_DEFAULT = PERSISTENCE_TYPE_HIBERNATE; - /** Propriété des générateurs indiquant le package par défaut */ - public static final String PROPERTY_DEFAULT_PACKAGE = "defaultPackage"; - /** Le package par défaut si aucun n'est spécifié */ - public static final String DEFAULT_PACKAGE = "org.codelutin.malo"; - - /** - * Renvoie le package par défaut pour le générateur donné - * - * @param generator le générateur donné - * @return le package par défaut du générator donné - */ - public static String getDefaultPackage(Template generator) { - String packageName = generator.getProperty(PROPERTY_DEFAULT_PACKAGE); - if (packageName == null || "".equals(packageName)) { - packageName = DEFAULT_PACKAGE; - } - return packageName; - } - - /** - * @see GeneratorUtil#hasDocumentation - * @deprecated - */ - @Deprecated - public static boolean hasDocumentation(ObjectModelElement element) { - return notEmpty(element.getDocumentation()); - } - - /** - * @see GeneratorUtil#notEmpty - * @deprecated - */ - @Deprecated - public static boolean notEmpty(String s) { - return (s != null && !"".equals(s)); - } - - /** - * Renvoie l'interface DAO associée à la classe passée en paramètre - * - * @param clazz la classe à tester - * @param model le modele utilisé - * @return l'interface trouvée ou null sinon - */ - public static ObjectModelInterface getDAOInterface(ObjectModelClass clazz, - ObjectModel model) { - for (Object o : model.getInterfaces()) { - ObjectModelInterface daoInterface = (ObjectModelInterface) o; - if (daoInterface.getName().equals(clazz.getName() + "DAO")) { - if (daoInterface.hasStereotype(STEREOTYPE_DAO)) { - return daoInterface; - } - } - } - return null; - } - - /** - * Renvoie le type de persistence pour l'élément donné. Si aucun n'est - * trouvé, le type par défaut est utilisé - * - * @param element l'élément à tester - * @return le type de persitence pour l'élément donné. - */ - public static String getPersistenceType(ObjectModelElement element) { - String tag = element.getTagValue(TAG_PERSISTENCE_TYPE); - if (tag == null) { - tag = PERSISTENCE_TYPE_DEFAULT; - } - return tag; - } - - public static String getReverseDBName(ObjectModelAttribute attr) { - if (attr.getReverseAttribute() != null) { - return getDBName(attr.getReverseAttribute()); - } else { - return getDBName(attr) + "_id"; - } - } - - /** - * Renvoie le nom BD de l'élement passé en paramètre. Elle se base sur le - * tag associé si il existe, sinon sur le nom de l'élément - * - * @param element l'élément à tester - * @return le nom de table - */ - public static String getDBName(ObjectModelElement element) { - if (element == null) { - return null; - } - if (notEmpty(element.getTagValue(TAG_DB_NAME))) { - return element.getTagValue(TAG_DB_NAME); - } - return toLowerCaseFirstLetter(element.getName()); - } - - /** - * Cherche et renvoie le schema a utiliser sur cet element, sinon sur le model. - * - * @param element l'élément à tester - * @param model le modele utilisé - * @return le nom du schema ou null - */ - public static String getSchemaName(ObjectModelElement element, - ObjectModel model) { - return findTagValue(TAG_SCHEMA_NAME, element, model); - } - - /** - * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model. - * - * @param element l'élément à tester - * @param model le modele utilisé - * @return le prefix i18n ou <code>null</code> si non spécifié - */ - public static String getI18nPrefix(ObjectModelElement element, - ObjectModel model) { - return GeneratorUtil.findTagValue(TAG_I18N_PREFIX, element, model); - } - - /** - * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model. - * - * @param element l'élément à tester - * @param model le modele utilisé - * @return le prefix i18n ou <code>null</code> si non spécifié - */ - public static boolean shouldgenerateOperatorForDAOHelper(ObjectModelElement element, - ObjectModel model) { - String tagValue = GeneratorUtil.findTagValue(TAG_GENERATE_OPERATOR_FOR_DAO_HELPER, element, model); - boolean generate = GeneratorUtil.notEmpty(tagValue) && Boolean.valueOf(tagValue); - return generate; - } - - /** - * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe. - * - * @param clazz la classe à tester - * @return la liste des attributs de la clef métier ou null si pas de clef métier. - */ - public static List<String> getNaturalId(ObjectModelClass clazz) { - String value = clazz.getTagValue(TAG_NATURAL_ID); - if (value == null || value.trim().isEmpty()) { - return java.util.Collections.emptyList(); - } - List<String> result = new ArrayList<String>(); - for (String attribute : value.split(",")) { - result.add(attribute.trim()); - } - return result; - } - - /** - * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe. - * - * @param clazz la classe à tester - * @param model le modele - * @return la liste des attributs de la clef métier ou null si pas de clef métier. - */ - public static boolean generateToString(ObjectModelClass clazz, - ObjectModel model) { - String value; - value = model.getTagValue(TAG_NOT_GENERATE_TO_STRING); - if (value != null && !value.trim().isEmpty()) { - return false; - } - value = clazz.getTagValue(TAG_NOT_GENERATE_TO_STRING); - if (value != null && !value.trim().isEmpty()) { - return false; - } - return true; - } - - /** - * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe. - * - * @param clazz la classe à tester - * @param model le modele - * @return la liste des attributs de la clef métier ou null si pas de clef métier. - */ - public static boolean sortAttribute(ObjectModelClass clazz, - ObjectModel model) { - String value; - value = clazz.getTagValue(TAG_SORT_ATTRIBUTE); - if (value == null || value.trim().isEmpty() || "false".equals(value.trim())) { - return false; - } - if (value != null && "true".equals(value.trim())) { - return true; - } - - value = model.getTagValue(TAG_SORT_ATTRIBUTE); - if (value == null || value.trim().isEmpty() || "false".equals(value.trim())) { - return false; - } - if (value != null && "true".equals(value.trim())) { - return true; - } - return true; - } - - /** - * Detecte si un attribut fait partie d'une clef metier. - * - * @param attribute l'attribut à tester - * @return <code>true</code> si l'attribut fait partie d'une clef metier, <code>false</cdoe> sinon. - */ - public static boolean isNaturalId(ObjectModelAttribute attribute) { - String value = attribute.getTagValue(TAG_NATURAL_ID); - if (!GeneratorUtil.notEmpty(value)) { - // valeur null, donc pas positionnee - return false; - } - try { - return Boolean.valueOf(value.trim()); - } catch (Exception e) { - // on a pas reussi a convertir en boolean. - //todo peut-être declancher une exception ? - return false; - } - } - - /** - * Cherches et renvoie le copyright a utiliser sur le model. - * - * @param model le modele utilisé - * @return le texte du copyright ou null - */ - public static String getCopyright(Model model) { - return findTagValue(TAG_COPYRIGHT, null, model); - } - - /** - * @see GeneratorUtil#findTagValue - * @deprecated - */ - @Deprecated - public static String findTagValue(String tagName, - ObjectModelElement element, Model model) { - if (element == null) { - if (model != null) { - if (notEmpty(model.getTagValue(tagName))) { - return model.getTagValue(tagName); - } - } - return null; - } - if (notEmpty(element.getTagValue(tagName))) { - return element.getTagValue(tagName); - } - //On va chercher sur l'element declarant - return findTagValue(tagName, element.getDeclaringElement(), model); - } - - public static <Type extends ObjectModelElement> Collection<Type> getElementsWithStereotype( - Collection<Type> elements, String... stereotypes) { - Collection<Type> result = new ArrayList<Type>(); - for (Type element : elements) { - if (hasStereotypes(element, stereotypes)) { - result.add(element); - } - } - return result; - } - - public static boolean hasStereotypes(ObjectModelElement element, - String... stereotypes) { - for (String stereotype : stereotypes) { - if (!element.hasStereotype(stereotype)) { - return false; - } - } - return true; - } - - public static String getPrimaryKeyAttributesListDeclaration( - ObjectModelClass clazz, boolean includeName) { - String attributes = ""; - for (ObjectModelAttribute attr : getElementsWithStereotype(clazz.getAttributes(), STEREOTYPE_PRIMARYKAY)) { - attributes += attr.getType(); - if (includeName) { - attributes += " " + attr.getName(); - } - attributes += ", "; - } - if (attributes.length() > 0) { - attributes = attributes.substring(0, attributes.length() - 2); - } - return attributes; - } - - public static String capitalize(String s) { - return StringUtils.capitalize(s); - } - - public static boolean isAssociationClassDoublon(ObjectModelAttribute attr) { - return (attr.getReverseAttribute() != null) && (attr.getDeclaringElement().equals(attr.getReverseAttribute().getDeclaringElement())) && (!GeneratorUtil.isFirstAttribute(attr)); - } - - /** - * Renvoie le nom de l'attribut de classe d'association en fonction des cas: - * Si l'attribut porte le même nom que le type (extrémité inverse de - * l'association), on lui ajoute le nom de la classe d'association - * - * @param attr l'attribut a traiter - * @return le nom de l'attribut de classe d'association - */ - public static String getAssocAttrName(ObjectModelAttribute attr) { - String typeName = attr.getType().substring( - attr.getType().lastIndexOf(".") + 1); - String result = attr.getName(); - if (attr.getName().equalsIgnoreCase(typeName)) { - result += capitalize(attr.getAssociationClass().getName()); - } - return result; - } - - public static String getDOType(ObjectModelElement elem, ObjectModel model) { - String type = elem.getName(); - if (elem instanceof ObjectModelAttribute) { - type = ((ObjectModelAttribute) elem).getType(); - } - if (elem instanceof ObjectModelClass) { - type = ((ObjectModelClass) elem).getQualifiedName(); - } - return getDOType(type, model); - } - - public static String getDOType(String type, ObjectModel model) { - if (!model.hasClass(type)) { - return type; - } - ObjectModelClass clazz = model.getClass(type); - if (clazz.hasStereotype(STEREOTYPE_ENTITY)) { - if (shouldBeAbstract(clazz)) { - type += "Abstract"; - } else { - type += "Impl"; - } - } - return type; - } - private static final Set<String> numberTypes = new HashSet<String>(); - private static final Set<String> textTypes = new HashSet<String>(); - private static final Set<String> booleanTypes = new HashSet<String>(); - private static final Set<String> primitiveTypes = new HashSet<String>(); - private static final String VOID_TYPE = "void"; - - static { - numberTypes.add("byte"); - numberTypes.add("java.lang.Byte"); - numberTypes.add("Byte"); - numberTypes.add("short"); - numberTypes.add("java.lang.Short"); - numberTypes.add("Short"); - numberTypes.add("int"); - numberTypes.add("java.lang.Integer"); - numberTypes.add("Integer"); - numberTypes.add("long"); - numberTypes.add("java.lang.Long"); - numberTypes.add("Long"); - numberTypes.add("float"); - numberTypes.add("java.lang.Float"); - numberTypes.add("Float"); - numberTypes.add("double"); - numberTypes.add("java.lang.Double"); - numberTypes.add("Double"); - - textTypes.add("char"); - textTypes.add("java.lang.Char"); - textTypes.add("Char"); - textTypes.add("java.lang.String"); - textTypes.add("String"); - - booleanTypes.add("boolean"); - booleanTypes.add("java.lang.Boolean"); - booleanTypes.add("Boolean"); - - primitiveTypes.addAll(numberTypes); - primitiveTypes.addAll(textTypes); - primitiveTypes.addAll(booleanTypes); - } - - public static boolean isNumericType(ObjectModelAttribute attr) { - return numberTypes.contains(attr.getType()); - } - - public static boolean isTextType(ObjectModelAttribute attr) { - return textTypes.contains(attr.getType()); - } - - public static boolean isDateType(ObjectModelAttribute attr) { - return "java.util.Date".equals(attr.getType()); - } - - public static boolean isBooleanType(ObjectModelAttribute attr) { - return booleanTypes.contains(attr.getType()); - } - - public static boolean isPrimitiveType(ObjectModelAttribute attr) { - return primitiveTypes.contains(attr.getType()); - } - - /** - * Indique si la classe specifiee n'a aucune ou que des methodes abstraites - * - * @param clazz l'instance de ObjectModelClass - * @return true si la classe n'a que des operations abstraite ou aucune - * operation - */ - public static boolean hasNothingOrAbstractMethods(ObjectModelClass clazz) { - boolean result = true; - Iterator<?> operations = clazz.getOperations().iterator(); - while (result && operations.hasNext()) { - ObjectModelOperation op = (ObjectModelOperation) operations.next(); - result = op.isAbstract(); - } - return result; - } - - /** - * Indique si la classe specifiee devrait etre abstraite - * - * @param clazz l'instance de ObjectModelClass - * @return true dans ce cas, false sinon - */ - public static boolean shouldBeAbstract(ObjectModelClass clazz) { - return clazz != null && (clazz.isAbstract() && hasNothingOrAbstractMethods(clazz)); - } - - /** - * <p> - * Cette méthode permet de détecter si - * - l'attribut représente une relation 1-n - * - cette relation est unidirectionnelle - * - le type de l'attribut représente un entité - * - cette entité a des sous-classes dans le modèle - * <p/> - * Ce cas correspond à une incompatibilité d'Hibernate qui nous oblige a - * adopter un comportement particulier. - * </p> - * - * @param attr l'attribut a tester - * @param model le model - * @return true si et seulement si il s'agit bien de ce type de relation - */ - public static boolean hasUnidirectionalRelationOnAbstractType( - ObjectModelAttribute attr, ObjectModel model) { - ObjectModelAttribute reverse = attr.getReverseAttribute(); - //relation 1-n - if (reverse != null && isNMultiplicity(attr) && !isNMultiplicity(reverse)) { - //Pas de navigabilité - if (!reverse.isNavigable()) { - //Il s'agit d'une entity - ObjectModelClass clazz = model.getClass(attr.getType()); - if (clazz != null && clazz.hasStereotype(STEREOTYPE_ENTITY)) { - //Cette classe a des sous-classes dans le modèle - for (ObjectModelClass subClass : model.getClasses()) { - if (subClass.getSuperclasses().contains(clazz)) { - return true; - } - } - } - } - } - return false; - } - - /** - * Renvoie le nom unique de table pour une relation ManyToMany en fonction - * de l'attribut <code>attr</code> - * <p/> - * Plusieurs cas de figure: - * <li> - * - * @param attr l'attribut servant de base au calcul du nom - * @return le nom de la table - */ - public static String getManyToManyTableName(ObjectModelAttribute attr) { - String result; - - if (attr.hasAssociationClass()) { - result = TopiaGeneratorUtil.getDBName(attr.getAssociationClass()); - } else { - String name = attr.getName(); - String revers = attr.getReverseAttributeName(); - - if (name.compareToIgnoreCase(revers) < 0) { - result = name + "_" + revers; - } else { - result = revers + "_" + name; - } - } - // String result; - // if (!Util.isFirstAttribute(attr)) { - // result = attr.getDeclaringElement().getName() + "_" + attr.getReverseAttribute().getDeclaringElement().getName(); - // } else { - // result = attr.getReverseAttribute().getDeclaringElement().getName() + "_" + attr.getDeclaringElement().getName(); - // } - return result.toLowerCase(); - } - - /** - * Renvoie le type d'interface à utiliser en fonction de l'attribut - * - * @param attr l'attribut a traiter - * @return String - */ - public static String getNMultiplicityInterfaceType(ObjectModelAttribute attr) { - if (attr.hasStereotype(STEREOTYPE_UNIQUE)) { - return Set.class.getName(); - } else if (attr.isIndexed() || attr.isOrdered()) { - return List.class.getName(); - } - return Collection.class.getName(); - } - - /** - * Renvoie le type d'objet (instance) à utiliser en fonction de l'attribut - * - * @param attr l'attribut a traiter - * @return String - */ - public static String getNMultiplicityObjectType(ObjectModelAttribute attr) { - if (attr.hasStereotype(STEREOTYPE_UNIQUE)) { - return HashSet.class.getName(); - } else if (attr.isIndexed() || attr.isOrdered()) { - //On considère qu'on ne sait pas traiter vraiment l'attribut "ordered" - // puisqu'on va conserver l'ordre d'insertion, et non un ordre en - // fonction d'un élément donné. Donc on renvoi une ArrayList - return ArrayList.class.getName(); - } - LinkedList.class.getName(); - return ArrayList.class.getName(); - } - - /** - * Renvoie le type d'interface à utiliser en fonction de l'attribut - * - * @param attr l'attribut a traiter - * @return String - */ - public static String getNMultiplicityHibernateType(ObjectModelAttribute attr) { - if (attr.hasStereotype(STEREOTYPE_UNIQUE)) { - return "set"; - } else if (attr.isIndexed()) { - return "list"; - } - //attr.isOrdered() - On génère le ordered en bag - return "bag"; - } - - /** - * Obtain the list of entities classes with the possibility to sort the result. - * - * @param model the current model to scan - * @param sort flag to allow sort the result - * @return the list of filtred classes by their stereotype - */ - public static List<ObjectModelClass> getEntityClasses(ObjectModel model, - boolean sort) { - return getClassesByStereotype(STEREOTYPE_ENTITY, model, sort); - } - - /** - * Obtain the list of classes for a given stereotype with the possibility to sort the result. - * - * @param stereotype filter stereotype - * @param model the current model to scan - * @param sort flag to allow sort the result - * @return the list of filtred classes by their stereotype - */ - public static List<ObjectModelClass> getClassesByStereotype( - String stereotype, ObjectModel model, boolean sort) { - List<ObjectModelClass> classes = new ArrayList<ObjectModelClass>(); - for (ObjectModelClass clazz : model.getClasses()) { - if (clazz.hasStereotype(stereotype)) { - classes.add(clazz); - } - } - if (sort && !classes.isEmpty()) { - java.util.Collections.sort(classes, - new java.util.Comparator<ObjectModelClass>() { - - @Override - public int compare(ObjectModelClass o1, - ObjectModelClass o2) { - return o1.getQualifiedName().compareTo( - o2.getQualifiedName()); - } - }); - } - return classes; - } - - /** - * Detecte si la clef metier d'une classe est mutable ou pas. - * <p/> - * On respecte la valeur par defaut d'hibernate, à savoir que par default une clef metier est non mutable. - * - * @param clazz la classe a tester - * @return <code>true</code> si le tag value a ete positionne sur la classe via le tag - * {@link #TAG_NATURAL_ID_MUTABLE}, , <code>false</code> sinon. - */ - public static boolean isNaturalIdMutable(ObjectModelClass clazz) { - String value = clazz.getTagValue(TAG_NATURAL_ID_MUTABLE); - if (!notEmpty(value)) { - // valeur null, donc par default positionnee - return false; - } - try { - return Boolean.valueOf(value.trim()); - } catch (Exception e) { - // on a pas reussi a convertir en boolean. - //todo peut-être declancher une exception ? - return false; - } - } - - /** - * Obtain the list of fqn of object involed in the given class. - * - * @param aClass the clazz to inspect - * @param incomingFqns incoming fqns - * @return the list of fqn of attributes - */ - public static List<String> getImports(ObjectModelClass aClass, String... incomingFqns) { - Set<String> tmp = new HashSet<String>(); - tmp.addAll(Arrays.asList(incomingFqns)); - getImports(aClass, tmp); - List<String> result = cleanImports(aClass.getPackageName(), tmp); - return result; - } - - /** - * Obtain the list of fqn of object involed in the given interface. - * - * @param anInterface the interface to inspect - * @param incomingFqns incoming fqns - * @return the list of fqn of attributes - */ - public static List<String> getImports(ObjectModelInterface anInterface, String... incomingFqns) { - Set<String> tmp = new HashSet<String>(); - tmp.addAll(Arrays.asList(incomingFqns)); - getImports(anInterface, tmp); - List<String> result = cleanImports(anInterface.getPackageName(), tmp); - return result; - } - - public static String getSimpleName(String fqn) { - int lasIndex = fqn.lastIndexOf("."); - if (lasIndex == 1) { - // primitive type - return fqn; - } - return fqn.substring(lasIndex + 1); - /*if (lasIndex == aClass.getPackageName().length()) { - // same package - return fqn.substring(lasIndex + 1); - } - - return fqn;*/ - } - - /** - * Obtain the list of fqn of object involed in the given class. - * - * @param aClass the class to inspect - * @param fqns where to store found fqns - */ - protected static void getImports(ObjectModelClass aClass, Set<String> fqns) { - // scan attributes - for (ObjectModelAttribute attr : aClass.getAttributes()) { - fqns.add(attr.getType()); - if (isNMultiplicity(attr)) { - String collectionType = getNMultiplicityInterfaceType(attr); - fqns.add(collectionType); - String collectionObject = getNMultiplicityObjectType(attr); - fqns.add(collectionObject); - } - } - for (ObjectModelAttribute attribute : aClass.getAllOtherAttributes()) { - fqns.add(attribute.getType()); - } - // scan associations - if (aClass instanceof ObjectModelAssociationClass) { - ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) aClass; - for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) { - if (attr == null) { - continue; - } - fqns.add(attr.getType()); - if (isNMultiplicity(attr)) { - String collectionType = getNMultiplicityInterfaceType(attr); - fqns.add(collectionType); - String collectionObject = getNMultiplicityObjectType(attr); - fqns.add(collectionObject); - } - } - } - // scan operations - for (ObjectModelOperation operation : aClass.getOperations()) { - getImports(operation, fqns); - } - // scan super interfaces - for (ObjectModelInterface modelInterface : aClass.getInterfaces()) { - fqns.add(modelInterface.getQualifiedName()); - getImports(modelInterface, fqns); - } - // scan super classes - for (ObjectModelClass modelClass : aClass.getSuperclasses()) { - fqns.add(modelClass.getQualifiedName()); - getImports(modelClass); - } - } - - /** - * Obtain the list of fqn of object involed in the given interface. - * - * @param anInterface the interface to inspect - * @param fqns where to store found fqns - */ - protected static void getImports(ObjectModelInterface anInterface, Set<String> fqns) { - // scan operations - for (ObjectModelOperation operation : anInterface.getOperations()) { - getImports(operation, fqns); - } - // scan super interfaces - for (ObjectModelInterface modelInterface : anInterface.getInterfaces()) { - fqns.add(modelInterface.getQualifiedName()); - getImports(modelInterface, fqns); - } - } - - /** - * Obtain the fqn's list of all involed type in a givne operation. - * - * @param operation operation to inspect - * @param fqns where to store found fqns - */ - protected static void getImports(ObjectModelOperation operation, Set<String> fqns) { - String fqn = operation.getReturnType(); - fqns.add(fqn); - for (ObjectModelParameter parameter : operation.getParameters()) { - fqns.add(parameter.getType()); - } - } - - /** - * Clean a set of fqns, transform it into a {@link List} and sort it. - * - * @param packageName the current package name - * @param fqns the dirty set of fqns - * @return the sorted cleaned list of fqns. - */ - protected static List<String> cleanImports(String packageName, Set<String> fqns) { - fqns.removeAll(primitiveTypes); - fqns.remove(VOID_TYPE); - int packageLength = packageName.length(); - List<String> genericType = new ArrayList<String>(); - for (Iterator<String> it = fqns.iterator(); it.hasNext();) { - String fqn = it.next(); - int lastIndex = fqn.lastIndexOf("."); - if (lastIndex == packageLength && fqn.startsWith(packageName)) { - // same package - it.remove(); - continue; - } - int genericIndex = fqn.indexOf('<'); - if (genericIndex != -1) { - genericType.add(fqn.substring(0, genericIndex)); - it.remove(); - } - } - fqns.addAll(genericType); - - ArrayList<String> result = new ArrayList<String>(fqns); - java.util.Collections.sort(result); - return result; - } - - /** - * Convertit un nom de variable en nom de constante. - * - * @param variableName le nom de variable a convertir - * @return le nom de la constante à partir du nom de la variable - */ - public static String convertVariableNameToConstantName(String variableName) { - //TODO Faire des tests pour savoir si variableName est non null et valide - //TODO Ameliorer l'algo pour tenir compte des caractères non alpha - //TODO pour le moment cela convient, donc... - StringBuilder buffer = new StringBuilder(); - boolean lastCarIsUp = false; - for (int i = 0, j = variableName.length(); i < j; i++) { - char c = variableName.charAt(i); - boolean carIsUp = Character.isUpperCase(c); - if (i > 0 && !lastCarIsUp && carIsUp) { - // ajout d'un _ - buffer.append('_'); - } - if (carIsUp) { - buffer.append(c); - } else { - buffer.append(Character.toUpperCase(c)); - } - lastCarIsUp = carIsUp; - } - return buffer.toString(); - } -} // GeneratorUtil - Deleted: branches/eugene-2.0/eugene-test/src/main/resources/log4j.properties =================================================================== --- branches/eugene-2.0/eugene-test/src/main/resources/log4j.properties 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene-test/src/main/resources/log4j.properties 2009-12-14 01:57:24 UTC (rev 749) @@ -1,12 +0,0 @@ -# Global logging configuration -log4j.rootLogger=ERROR, stdout - -# Console output... -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n - -# package level -log4j.logger.org.nuiton.eugene=DEBUG -log4j.logger.org.nuiton.eugene.test=DEBUG -log4j.logger.org.nuiton.processor=DEBUG Deleted: branches/eugene-2.0/eugene-test/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java =================================================================== --- branches/eugene-2.0/eugene-test/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene-test/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java 2009-12-14 01:57:24 UTC (rev 749) @@ -1,91 +0,0 @@ -/* - * *##% - * EUGene Test - * Copyright (C) 2007 - 2009 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>. - * ##%* - */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.nuiton.eugene.test.generator; - -import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; -import org.nuiton.eugene.models.object.ObjectModel; -import org.nuiton.eugene.models.object.ObjectModelClass; -import org.nuiton.eugene.models.object.ObjectModelOperation; - -/** - * - * @author fdesbois - */ -public class TestBuilderTest { - - private static final Log log = LogFactory.getLog(TestBuilderTest.class); - - public TestBuilderTest() { - } - - @BeforeClass - public static void setUpClass() throws Exception { - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - /** - * Test of build method, of class TestBuilder. - */ - @Test - public void testBuild() { - System.out.println("build"); - TestBuilder instance = new TestBuilder(); - - instance.build(); - - ObjectModel result = instance.getModel(); - assertNotNull(result); - assertEquals(result.getClasses().size(), 2); - ObjectModelClass clazz = result.getClass("org.chorem.bonzoms.Person"); - assertNotNull(clazz); - assertEquals(clazz.getAttributes().size(), 3); - assertEquals(clazz.getOperations().size(), 2); - List<ObjectModelOperation> operations = (List<ObjectModelOperation>)clazz.getOperations(); - ObjectModelOperation operation = operations.get(0); - log.debug("Body code [" + operation.getName() + "] : " + operation.getBodyCode()); - assertFalse(operation.getBodyCode().isEmpty()); - } - -} \ No newline at end of file Deleted: branches/eugene-2.0/eugene-test/src/test/resources/log4j.properties =================================================================== --- branches/eugene-2.0/eugene-test/src/test/resources/log4j.properties 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/eugene-test/src/test/resources/log4j.properties 2009-12-14 01:57:24 UTC (rev 749) @@ -1,12 +0,0 @@ -# Global logging configuration -log4j.rootLogger=ERROR, stdout - -# Console output... -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n - -# package level -log4j.logger.org.nuiton.eugene=DEBUG -log4j.logger.org.nuiton.eugene.test=DEBUG -log4j.logger.org.nuiton.processor=DEBUG Modified: branches/eugene-2.0/maven-eugene-plugin/pom.xml =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/pom.xml 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/maven-eugene-plugin/pom.xml 2009-12-14 01:57:24 UTC (rev 749) @@ -508,7 +508,7 @@ <id>run-its</id> <activation> <property> - <name>performRedmineRelease</name> + <name>performRelease</name> <value>true</value> </property> </activation> @@ -518,6 +518,7 @@ <artifactId>maven-invoker-plugin</artifactId> <configuration> <pomIncludes> + <!--<pomInclude>generate/generators/pom.xml</pomInclude>--> <pomInclude>**/pom.xml</pomInclude> </pomIncludes> <postBuildHookScript>verify</postBuildHookScript> Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/LICENSE.txt =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/LICENSE.txt (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/LICENSE.txt 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/README.txt =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/README.txt (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/README.txt 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,2 @@ +To deploy new version of pom: mvn deploy +To install localy: mvn install Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/changelog.txt =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/changelog.txt (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/changelog.txt 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,53 @@ +1.0.0 xxx xxx + * Add multiple models loading and restricted package generation + * Recode EugenePlugin without ant + * Move to org.nuiton groupid + * Rename project to Eugene + +0.64 chemit 20090218 + * 20090211 [chatellier] add testPhase property in mojo to specify when using it in test phase + * 20090210 [chatellier] add info and debug maven log messages + * 20090210 [chatellier] add default value on all non required parameters + * 20090209 [chemit] fix bug when using sibling dependencies in a multi-module project + * 20090129 [chemit] use lutinproject 3.4 (suppress javadoc plugin invocation) + +0.63 chemit 20081215 + * 20081215 [chemit] follow lutingenerator release + +0.62 chemit 20081210 + * 20081210 [chemit] use lutinpluginproject 3.2 + * 20081203 [chemit] add a encoding goal property to be dispatched in all generator to control file generation encoding + * 20081118 [chemit] use lutinproject 3.1 + * 20081117 [chemit] + - add extraClassPathDirectory parameter to can specify an extra directory to add in classLoader + - bump lutingenerator version + +0.61 chatellier 20081114 + * 20081107 [chatellier] + - add test compile dir and test resources in generation gaol + * 20081101 [chemit] + - add an excludeTemplates property on GeneratorPlugin to permit exclusion of generators for some composite generator + - bump lutingenerator to 0.61 + +0.60 chemit 20081013 + * 20081013 [chemit] + - remove addCompileDirectory option (always done) + add dynamic resources + - use lutingenerator 0.60 + - clean pom + +0.51 thimel 20080925 + * 20080925 [thimel] Refactor pom using the correct architecture + * 20080925 [thimel] Switched License to LGPL + * 20080723 [chemit] + - add generated sources in maven project's compilation directories via addCompilationDirectory plugin property + + * 20070525 [chatellier] + - add Xmi2StateModel goal + - improve Xmi2Model Hierarchy + * 20070525 [chatellier] update ant dependency to 1.7.0 + * 20070525 [chatellier] replacing lutinxml.XSLAntTask by Ant.XSLTProcess + +0.50 ??? ??? + + * 20070420 [chatellier] add goal to copy a set of generated files + * 20070420 [chatellier] update lutingenerator depencency to 0.50 \ No newline at end of file Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/invoker.properties =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/invoker.properties (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/invoker.properties 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,21 @@ +# A comma or space separated list of goals/phases to execute, may +# specify an empty list to execute the default goal of the IT project +invoker.goals=clean test + +# Optionally, a list of goals to run during further invocations of Maven +#invoker.goals.2=${project.groupId}:${project.artifactId}:${project.version}:run + +# A comma or space separated list of profiles to activate +#invoker.profiles=run-all run-once + +# The value for the environment variable MAVEN_OPTS +#invoker.mavenOpts=-Dfile.encoding=UTF-16 -Xms32m -Xmx256m + +# Possible values are "fail-fast" (default), "fail-at-end" and "fail-never" +invoker.failureBehavior=fail-at-end + +# The expected result of the build, possible values are "success" (default) and "failure" +#invoker.buildResult=success + +# A boolean value controlling the -N flag, defaults to "false" +#invoker.nonRecursive=false Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/pom.xml =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/pom.xml (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/pom.xml 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,155 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <!-- ************************************************************* --> + <!-- *** POM Relationships *************************************** --> + <!-- ************************************************************* --> + + <parent> + <groupId>org.nuiton</groupId> + <artifactId>eugene</artifactId> + <version>@pom.version@</version> + </parent> + + <groupId>org.nuiton.test</groupId> + <artifactId>eugene-test-modelreader</artifactId> + + <dependencies> + <dependency> + <groupId>org.nuiton.eugene</groupId> + <artifactId>eugene</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + + <name>EUGene :: Test</name> + <description>Test module for generators.</description> + <inceptionYear>2007</inceptionYear> + + <contributors> + <contributor> + <name>Florian Desbois</name> + <email>fdesbois@codelutin.com</email> + <timezone>+2</timezone> + <roles> + <role>Developpeur</role> + </roles> + </contributor> + </contributors> + + <!-- ************************************************************* --> + <!-- *** Build Settings ****************************************** --> + <!-- ************************************************************* --> + + <packaging>jar</packaging> + + <build> + + <plugins> + + <plugin> + <groupId>org.nuiton.processor</groupId> + <artifactId>maven-processor-plugin</artifactId> + <executions> + <execution> + <phase>generate-sources</phase> + <goals> + <goal>process</goal> + </goals> + </execution> + </executions> + <configuration> + <includes>**/*.java</includes> + <filters> + org.nuiton.processor.filters.GeneratorTemplatesFilter + </filters> + </configuration> + </plugin> + + <plugin> + <groupId>org.nuiton.eugene</groupId> + <artifactId>maven-eugene-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <id>Test Regression Generator</id> + <phase>generate-test-sources</phase> + <configuration> + <reader>org.nuiton.eugene.ObjectModelReader</reader> + <includes>dtotest.objectmodel</includes> + <templates>org.nuiton.eugene.test.generator.BeanGenerator</templates> + <defaultPackage>org.nuiton.eugene.test</defaultPackage> + <extraClassPathDirectory>target/classes</extraClassPathDirectory> + <generateResources> + <input>src/main/models</input> + </generateResources> + </configuration> + <goals> + <goal>generate</goal> + </goals> + </execution> + <execution> + <id>Test Java Generator</id> + <phase>generate-test-sources</phase> + <configuration> + <reader>org.nuiton.eugene.test.generator.TestReader</reader> + <templates>org.nuiton.eugene.java.JavaGenerator</templates> + <defaultPackage>org.nuiton.eugene.test</defaultPackage> + <extraClassPathDirectory>target/classes</extraClassPathDirectory> + <generateResources> + <input>src/main/models</input> + </generateResources> + </configuration> + <goals> + <goal>generate</goal> + </goals> + </execution> + <execution> + <id>Test Bean Transformer</id> + <phase>generate-test-sources</phase> + <configuration> + <reader>org.nuiton.eugene.ObjectModelReader</reader> + <includes>dtotest2.objectmodel</includes> + <templates>org.nuiton.eugene.test.generator.BeanTransformer</templates> + <defaultPackage>org.nuiton.eugene.test</defaultPackage> + <extraClassPathDirectory>target/classes</extraClassPathDirectory> + <generateResources> + <input>src/main/models</input> + </generateResources> + </configuration> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.14</version> + </dependency> + </dependencies> + </plugin> + + </plugins> + + </build> + +</project> + + Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,621 @@ +/* *##% + * EUGene Test + * Copyright (C) 2007 - 2009 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>. + * ##%*/ + +/* * +* BeanGenerator.java +* +* Created: 17 avril 2009 +* +* @author tony Chemit <chemit@codelutin.com> +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author: chemit $ +*/ + +package org.nuiton.eugene.test.generator; + +import org.apache.commons.lang.StringUtils; +import static org.nuiton.eugene.test.generator.TopiaGeneratorUtil.TAG_ANNOTATION; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; + +import java.util.List; +import java.util.Set; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.eugene.ObjectModelGenerator; +import org.nuiton.eugene.GeneratorUtil; +import org.nuiton.eugene.ImportsManager; +import org.nuiton.eugene.models.object.ObjectModelAttribute; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelClassifier; +import org.nuiton.eugene.models.object.ObjectModelDependency; +import org.nuiton.eugene.models.object.ObjectModelInterface; +import org.nuiton.eugene.models.object.ObjectModelOperation; +import org.nuiton.eugene.models.object.ObjectModelParameter; +//import org.nuiton.topia.persistence.TopiaEntity; +import static org.nuiton.eugene.test.generator.TopiaGeneratorUtil.isPrimitiveType; +import static org.nuiton.eugene.test.generator.TopiaGeneratorUtil.isDateType; + +/** + * DTO generator + */ +public class BeanGenerator extends ObjectModelGenerator { + + /** + * Logger for this class + */ + private static final Log log = LogFactory.getLog(BeanGenerator.class); + + public BeanGenerator() { + super(); + } + + @Override + public String getFilenameForClass(ObjectModelClass clazz) { + return clazz.getQualifiedName().replace('.', File.separatorChar) + ".java"; + } + + @Override + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_BEAN) && + !clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) { + return; + } + // + // première phase : calcul des variables + // + String copyright = TopiaGeneratorUtil.getCopyright(model); + String clazzName = clazz.getName(); + String abstractStr = isAbstract(clazz) ? " abstract " : " "; + boolean needGetEntityMethod = false; + boolean generateToString = TopiaGeneratorUtil.generateToString(clazz, model); + + ImportsManager imports = new ImportsManager(); + + String extendClass = ""; + Iterator<ObjectModelClass> j = clazz.getSuperclasses().iterator(); + if (j.hasNext()) { + ObjectModelClassifier p = j.next(); + imports.addImport(p.getQualifiedName()); + extendClass += p.getName(); + } + String implInterface = ""; + for (Iterator<ObjectModelInterface> i=clazz.getInterfaces().iterator(); i.hasNext();) { + ObjectModelClassifier parentInterface = i.next(); + imports.addImport(parentInterface.getQualifiedName()); + implInterface += parentInterface.getName(); + if (i.hasNext()) { + implInterface += ", "; + } + } + // Add Serializable implements for DTO generation + if (clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) { + imports.addImport(Serializable.class); + if (!implInterface.isEmpty()) { + implInterface += ", "; + } + implInterface += Serializable.class.getName(); + } + String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", clazz, model); + + List<ObjectModelAttribute> attributes = new ArrayList<ObjectModelAttribute>(); + List<ObjectModelAttribute> multipleAttr = new ArrayList<ObjectModelAttribute>(); + + setAttributesForDTO(clazz, attributes,imports); + + boolean needListInImport=false; + + for (ObjectModelAttribute attr : clazz.getAttributes()) { + if (attr.isNavigable()) { + attributes.add(attr); + imports.addImport(attr.getType()); + if (GeneratorUtil.isNMultiplicity(attr)) { + multipleAttr.add(attr); + ObjectModelClass attrEntity = null; + if (model.hasClass(attr.getType())) { + attrEntity = model.getClass(attr.getType()); + } + boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)); + needGetEntityMethod |= isEntity; + if (attr.isOrdered()) { + needListInImport = true; + } + } + } + } + + imports.addImport(java.beans.PropertyChangeListener.class.getName()); + imports.addImport(java.beans.PropertyChangeSupport.class.getName()); + + for (ObjectModelOperation operation : clazz.getOperations()) { + imports.addImport(operation.getReturnType()); + for (ObjectModelParameter parameter : operation.getParameters()) { + imports.addImport(parameter.getType()); + } + } + + if (needGetEntityMethod) { + imports.addImport("org.nuiton.topia.persistence.TopiaEntity"); + } + if (!multipleAttr.isEmpty()) { + imports.addImport(Collection.class); + } + if (needListInImport) { + imports.addImport(List.class); + } + if (generateToString) { + imports.addImport(org.apache.commons.lang.builder.ToStringBuilder.class); + } + + boolean sortAttribute = TopiaGeneratorUtil.sortAttribute(clazz, model); + if (sortAttribute) { + Comparator<ObjectModelAttribute> comp = new Comparator<ObjectModelAttribute>(){ + + @Override + public int compare(ObjectModelAttribute o1, ObjectModelAttribute o2) { + return o1.getName().compareTo(o2.getName()); + } + }; + java.util.Collections.sort(attributes,comp); + java.util.Collections.sort(multipleAttr,comp); + } + // + // seconde phase : génération + // + + if (TopiaGeneratorUtil.notEmpty(copyright)) { +/*{<%=copyright%> +}*/ + } + +/*{package <%=clazz.getPackageName()%>; + + }*/ + + if (log.isDebugEnabled()) { + log.debug("imports for class <" + clazzName + ">"); + } + //for (String anImport : imports) { + for (String anImport : imports.getImports(clazz.getPackageName())) { + if (log.isDebugEnabled()) { + log.debug("import " + anImport); + } +/*{import <%=anImport%>; +}*/ + } +/*{ +public<%=abstractStr%>class <%=clazzName%>}*/ + +/* + * Définition de la super classe : il ne doit y avoir qu'une + */ + if (extendClass.length() > 0) { +/*{ extends <%=extendClass%>}*/ + } + + if (implInterface.length() > 0) { +/*{ implements <%=implInterface%> { + +}*/ + } else { + /*{ { + +}*/ + } + + + // TODO Calculer un serialVersionUID si il n'y en a pas + if (svUID != null) { +/*{ public static final long serialVersionUID = <%=svUID%>; + +}*/ + } + generateInterfaceOperations(output, clazz); + generateAttributes(output, attributes); +/*{ protected final PropertyChangeSupport pcs; + + /** + * Default constructor of <%=clazzName%>. + *) + public <%=clazzName%>() { + pcs = new PropertyChangeSupport(this); + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + pcs.addPropertyChangeListener(listener); + } + + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + pcs.addPropertyChangeListener(propertyName, listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + pcs.removePropertyChangeListener(listener); + } + + public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + pcs.removePropertyChangeListener(propertyName, listener); + } + +}*/ + generateGetters(output, attributes); + generateSetters(output, attributes); + generateGetChild(output, multipleAttr); + generateAddChild(output, multipleAttr); + generateRemoveChild(output, multipleAttr); + if (generateToString) { + generateToString(output, clazz); + } + if (!multipleAttr.isEmpty()) { +/*{ + + protected <T> T getChild(Collection<T> childs, int index) { + if (childs != null) { + int i = 0; + for (T o : childs) { + if (index == i) { + return o; + } + i++; + } + } + return null; + } + + }*/ + if (needGetEntityMethod) { +/*{ protected <T extends TopiaEntity> T getEntity(Collection<T> childs, String topiaId) { + if (childs != null) { + for (T o : childs) { + if (topiaId.equals(o.getTopiaId())) { + return o; + } + } + } + return null; + } + }*/ + } + } + +/*{ + protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + pcs.firePropertyChange(propertyName, oldValue, newValue); + } + +} //<%=clazz.getName()%> +}*/ + } + + protected void generateAttributes(Writer output, List<ObjectModelAttribute> attributes) throws IOException { + + for (ObjectModelAttribute attr : attributes) { + + if (!(attr.isNavigable() + || attr.hasAssociationClass())) { + continue; + } + + if (TopiaGeneratorUtil.hasDocumentation(attr)) { +/*{ /** + * <%=attr.getDocumentation()%> + *) +}*/ + } + String annotation = attr.getTagValue(TAG_ANNOTATION); + if (annotation != null && annotation.length() > 0) { +/*{ <%=annotation%> +}*/ + } + String attrName = attr.getName(); + String attrVisibility = attr.getVisibility(); + String attrType = attr.getType(); + if (attr.hasAssociationClass()) { + String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); + attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName); + attrType = attr.getAssociationClass().getName(); + } + int dot = attrType.lastIndexOf("."); + if (dot>-1) { + attrType = attrType.substring(dot + 1); + } + if (GeneratorUtil.isNMultiplicity(attr)) { + attrType = getCollection(attr, attrType); + } + +/*{ <%=attrVisibility%> <%=attrType%> <%=attrName%>; +}*/ + } + } + + protected void generateGetters(Writer output, List<ObjectModelAttribute> attributes) throws IOException { + /* + * Définition des getteurs et setteurs + */ + for (ObjectModelAttribute attr : attributes) { + + if (!attr.isNavigable()) { + continue; + } + + String attrName = attr.getName(); + String attrType = attr.getType(); + if (attr.hasAssociationClass()) { + String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); + attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName); + attrType = attr.getAssociationClass().getName(); + } + String attrNameCapitalized = StringUtils.capitalize(attrName); + int dot = attrType.lastIndexOf("."); + if (dot>-1) { + attrType = attrType.substring(dot + 1); + } + if (GeneratorUtil.isNMultiplicity(attr)) { + attrType = getCollection(attr, attrType); + } +/*{ public <%=attrType%> get<%=attrNameCapitalized%>() { + return <%=attrName%>; + } + +}*/ + } + } + + protected void generateSetters(Writer output, List<ObjectModelAttribute> attributes) throws IOException { + /* + * Définition des getteurs et setteurs + */ + for (ObjectModelAttribute attr : attributes) { + + if (!attr.isNavigable()) { + continue; + } + + String attrName = attr.getName(); + String attrType = attr.getType(); + + if (attr.hasAssociationClass()) { + String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); + attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName); + attrType = attr.getAssociationClass().getName(); + } + String attrNameCapitalized = StringUtils.capitalize(attrName); + int dot = attrType.lastIndexOf("."); + if (dot>-1) { + attrType = attrType.substring(dot + 1); + } + if (GeneratorUtil.isNMultiplicity(attr)) { + attrType = getCollection(attr, attrType); + } +/*{ public void set<%=attrNameCapitalized%>(<%=attrType%> newValue) { + <%=attrType%> oldValue = get<%=attrNameCapitalized%>(); + this.<%=attrName%> = newValue; + firePropertyChange("<%=attrName%>", oldValue, newValue); + } + +}*/ + } + } + + protected void generateGetChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException { + + for (ObjectModelAttribute attr : multipleAttr) { + + String attrName = attr.getName(); + String attrNameCapitalized = StringUtils.capitalize(attrName); + String attrType = attr.getType(); + int dot = attrType.lastIndexOf("."); + if (dot>-1) { + attrType = attrType.substring(dot + 1); + } + ObjectModelClass attrEntity=null; + if (model.hasClass(attr.getType())) { + attrEntity = model.getClass(attr.getType()); + } + boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)); +/*{ public <%=attrType%> get<%=attrNameCapitalized%>(int index) { + <%=attrType%> o = getChild(<%=attrName%>, index); + return o; + } + +}*/ + if (isEntity) { +/*{ public <%=attrType%> get<%=attrNameCapitalized%>(String topiaId) { + <%=attrType%> o = getEntity(<%=attrName%>, topiaId); + return o; + } + +}*/ + } + } + } + protected void generateAddChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException { + for (ObjectModelAttribute attr : multipleAttr) { + + String attrName = attr.getName(); + String attrNameCapitalized = StringUtils.capitalize(attrName); + String attrType = attr.getType(); + int dot = attrType.lastIndexOf("."); + if (dot>-1) { + attrType = attrType.substring(dot + 1); + } +/*{ public <%=attrType%> add<%=attrNameCapitalized%>(<%=attrType%> <%=attrName%>) { + get<%=attrNameCapitalized%>().add(<%=attrName%>); + firePropertyChange("<%=attrName%>", null, <%=attrName%>); + return <%=attrName%>; + } + +}*/ + } + } + + protected void generateRemoveChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException { + for (ObjectModelAttribute attr : multipleAttr) { + String attrName = attr.getName(); + String attrNameCapitalized = StringUtils.capitalize(attrName); + String attrType = attr.getType(); + int dot = attrType.lastIndexOf("."); + if (dot>-1) { + attrType = attrType.substring(dot + 1); + } +/*{ public boolean remove<%=attrNameCapitalized%>(<%=attrType%> <%=attrName%>) { + boolean removed = get<%=attrNameCapitalized%>().remove(<%=attrName%>); + if (removed) { + firePropertyChange("<%=attrName%>", <%=attrName%>, null); + } + return removed; + } + +}*/ + } + } + + protected void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException { + for (ObjectModelOperation op : classifier.getOperations()) { + String opName = op.getName(); +/*{ /** +}*/ + if (TopiaGeneratorUtil.hasDocumentation(op)) { + String opDocumentation = op.getDocumentation(); +/*{ * <%=opName%> : <%=opDocumentation%> +}*/ + } + Collection<ObjectModelParameter> params = op.getParameters(); + for (ObjectModelParameter param : params) { + String paramName = param.getName(); + String paramDocumentation = param.getDocumentation(); +/*{ * @param <%=paramName%> <%=paramDocumentation%> + }*/ + } + String opVisibility = op.getVisibility(); + String opType = op.getReturnType(); +/*{ *) + <%=opVisibility%> abstract <%=opType%> <%=opName%>(}*/ + String comma = ""; + for (ObjectModelParameter param : params) { + String paramName = param.getName(); + String paramType = param.getType(); +/*{<%=comma%><%=paramType%> <%=paramName%>}*/ + comma = ", "; + } +/*{)}*/ + Set<String> exceptions = op.getExceptions(); + comma = " throws "; + for (String exception : exceptions) { +/*{<%=comma%><%=exception%>}*/ + comma = ", "; + } +/*{; + +}*/ + } + } + protected void generateToString(Writer output, ObjectModelClass clazz) throws IOException { +/*{ + @Override + public String toString() { + String result = new ToStringBuilder(this). +}*/ + for (ObjectModelAttribute attr : clazz.getAttributes()) { + if (!(attr.isNavigable() || attr.hasAssociationClass())) { + continue; + } + //FIXME possibilité de boucles (non directes) + String attrName = attr.getName(); +/*{ append("<%=attrName%>", this.<%=attrName%>). +}*/ + } +/*{ toString(); + return result; + } + }*/ + } + + protected String getCollection(ObjectModelAttribute attr, String attrType) { + String nMultType; + if (attr.isOrdered()) { + nMultType = "List<"; + } else { + nMultType = "Collection<"; + } + nMultType += attrType; + nMultType += ">"; + return nMultType; + } + + protected boolean isAbstract(ObjectModelClass clazz) { + if (clazz.isAbstract()) { + return true; + } + return !clazz.getOperations().isEmpty(); + } + + /** + * Dependecy gestion for DTO generation. + * All primitives attributes (and dates) of dependencies entities of the DTO are + * copied in the DTO. This method only prepare a list of attributes to be generated. + * @param clazz DTO ObjectModelClass + * @param attributes list of attributes for the generation (may be not empty) + * @param imports the ImportsManager used to generate the header imports of the DTO + * @return the same list of attributes in parameter with attributes from entities dependencies + * @see org.nuiton.eugene.ImportsManager + * @see org.nuiton.eugene.models.object.ObjectModelDependency + */ + private List<ObjectModelAttribute> setAttributesForDTO(ObjectModelClass clazz, + List<ObjectModelAttribute> attributes, ImportsManager imports) { + + if (clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) { + if (log.isInfoEnabled()) { + log.info("DTO dependency gestion"); + } + for (ObjectModelDependency dependency : clazz.getDependencies()) { + ObjectModelClass supplier = (ObjectModelClass)dependency.getSupplier(); + + // ENTITY dependency + // Copy all primitives attributes from the Entity (supplier) to the DTO + // Prepare a list to future generation of all object generated attributes + if (supplier.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) { + if (log.isInfoEnabled()) { + log.info("Create primitive and date fields in DTO from Entity : " + + supplier.getQualifiedName()); + } + for (ObjectModelAttribute attr : supplier.getAttributes()) { + if (isPrimitiveType(attr) || isDateType(attr)) { + attributes.add(attr); + imports.addImport(attr.getType()); + } + if (GeneratorUtil.isNMultiplicity(attr)) { + imports.addImport("java.util.Collection"); + } + } + } + } + } + return attributes; + } +} //BeanGenerator Property changes on: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,341 @@ +/* + * *##% + * EUGene Test + * Copyright (C) 2007 - 2009 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>. + * ##%* + */ +package org.nuiton.eugene.test.generator; + +import org.apache.commons.lang.StringUtils; +import org.nuiton.eugene.GeneratorUtil; +import org.nuiton.eugene.java.ObjectModelTransformerToJava; +import org.nuiton.eugene.models.object.*; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +/*{generator option: parentheses = false}*/ + +/*{generator option: writeString = +}*/ +/** + * BeanTransformer + * <p/> + * Created: 28 oct. 2009 + * + * @author fdesbois + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ + * par : $Author: fdesbois $ + */ +public class BeanTransformer extends ObjectModelTransformerToJava { + + public BeanTransformer() { + super(); + } + + @Override + public void transformFromClass(ObjectModelClass clazz) { + if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_BEAN) && + !clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) { + return; + } + + ObjectModelClass resultClass; + if (!clazz.getOperations().isEmpty()) { + resultClass = createAbstractClass(clazz.getName(), clazz.getPackageName()); + } else { + resultClass = createClass(clazz.getName(), clazz.getPackageName()); + } + + createForDTO(resultClass, clazz); + + // Set superclass + Iterator<ObjectModelClass> j = clazz.getSuperclasses().iterator(); + if (j.hasNext()) { + ObjectModelClass p = j.next(); + setSuperClass(resultClass, p.getQualifiedName()); + } + + // Add interfaces from inputModel + for (ObjectModelInterface parentInterface : clazz.getInterfaces()) { + addInterface(resultClass, parentInterface.getQualifiedName()); + } + + createListeners(resultClass, clazz); + + boolean hasEntity = false; + boolean hasMultipleAttribute = false; + + // Add attributes with getter/setter + for (ObjectModelAttribute attr : clazz.getAttributes()) { + + if (attr.isNavigable()/* || attr.hasAssociationClass()*/) { + String attrType = attr.getType(); + String simpleType = GeneratorUtil.getSimpleName(attrType); + String attrName = attr.getName(); + String attrNameCapitalized = StringUtils.capitalize(attrName); + + // multiple attribute + if (GeneratorUtil.isNMultiplicity(attr)) { + hasMultipleAttribute = true; + + // Add getChild + ObjectModelOperation getChild = addOperation(resultClass, "get" + attrNameCapitalized, + attrType, ObjectModelModifier.PUBLIC); + addParameter(getChild, "int", "index"); + setOperationBody(getChild, "" + /*{ + <%=simpleType%> o = getChild(<%=attrName%>, index); + return o; + }*/ + ); + + // Add getEntity + ObjectModelClass attrEntity = null; + if (getModel().hasClass(attr.getType())) { + attrEntity = getModel().getClass(attr.getType()); + } + boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)); + + if (isEntity) { + hasEntity = true; + ObjectModelOperation getChildEntity = addOperation(resultClass, "get" + attrNameCapitalized, + attrType, ObjectModelModifier.PUBLIC); + addParameter(getChildEntity, String.class.getName(), "topiaId"); + setOperationBody(getChildEntity, "" + /*{ + <%=simpleType%> o = getEntity(<%=attrName%>, topiaId); + return o; + }*/ + ); + } + + // Add addChild + ObjectModelOperation addChild = addOperation(resultClass, "add" + attrNameCapitalized, + attrType, ObjectModelModifier.PUBLIC); + addParameter(addChild, attrType, attrName); + setOperationBody(addChild, "" + + /*{ + get<%=attrNameCapitalized%>().add(<%=attrName%>); + firePropertyChange("<%=attrName%>", null, <%=attrName%>); + return <%=attrName%>; + }*/ + ); + + // Add removeChild + ObjectModelOperation removeChild = addOperation(resultClass, "remove" + attrNameCapitalized, + "boolean", ObjectModelModifier.PUBLIC); + addParameter(removeChild, attrType, attrName); + setOperationBody(removeChild, "" + + /*{ + boolean removed = get<%=attrNameCapitalized%>().remove(<%=attrName%>); + if (removed) { + firePropertyChange("<%=attrName%>", <%=attrName%>, null); + } + return removed; + }*/ + ); + + // Change type for Multiple attribute + if (attr.isOrdered()) { + attrType = List.class.getName() + "<" + attrType + ">"; + } else { + attrType = Collection.class.getName() + "<" + attrType + ">"; + } + simpleType = GeneratorUtil.getSimpleName(attrType); + } + + if (attr.hasAssociationClass()) { + String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr); + attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName); + attrType = attr.getAssociationClass().getName(); + } + + // Add attribute + String visibility = attr.getVisibility(); + addAttribute(resultClass, attrName, attrType, "", ObjectModelModifier.toValue(visibility)); + + // Add getter + ObjectModelOperation getter = addOperation(resultClass, "get" + attrNameCapitalized, attrType, + ObjectModelModifier.PUBLIC); + setOperationBody(getter, "" + /*{ + return this.<%=attrName%>; + }*/ + ); + + // Add setter + ObjectModelOperation setter = addOperation(resultClass, "set" + attrNameCapitalized, "void", + ObjectModelModifier.PUBLIC); + addParameter(setter, attrType, "newValue"); + setOperationBody(setter, "" + /*{ + <%=simpleType%> oldValue = get<%=attrNameCapitalized%>(); + this.<%=attrName%> = newValue; + firePropertyChange("<%=attrName%>", oldValue, newValue); + }*/ + ); + + } + } + + // Add helper methods + if (hasMultipleAttribute) { + ObjectModelOperation getChild = addOperation(resultClass, "getChild", "<T> T", + ObjectModelModifier.PROTECTED); + addParameter(getChild, "java.util.Collection<T>", "childs"); + addParameter(getChild, "int", "index"); + setOperationBody(getChild, "" + /*{ + if (childs != null) { + int i = 0; + for (T o : childs) { + if (index == i) { + return o; + } + i++; + } + } + return null; + }*/ + ); + } + + if (hasEntity) { + ObjectModelOperation getEntity = addOperation(resultClass, "getEntity", + "<T extends org.nuiton.topia.persistence.TopiaEntity> T", ObjectModelModifier.PROTECTED); + addParameter(getEntity, "java.util.Collection<T>", "childs"); + addParameter(getEntity, "java.lang.String", "topiaId"); + setOperationBody(getEntity, "" + /*{ + if (childs != null) { + for (T o : childs) { + if (topiaId.equals(o.getTopiaId())) { + return o; + } + } + } + return null; + }*/ + ); + } + + // Add operations + for (ObjectModelOperation op : clazz.getOperations()) { + String visibility = op.getVisibility(); + ObjectModelOperation resultOperation = addOperation(resultClass, op.getName(), op.getReturnType(), + ObjectModelModifier.toValue(visibility), ObjectModelModifier.ABSTRACT); + + for (ObjectModelParameter param : op.getParameters()) { + addParameter(resultOperation, param.getType(), param.getName()); + } + + for (String exception : op.getExceptions()) { + addException(resultOperation, exception); + } + } + + + } + + private void createForDTO(ObjectModelClass resultClass, ObjectModelClass inputClass) { + + // Add Serializable implements for DTO generation + if (inputClass.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) { + addInterface(resultClass, "java.io.Serializable"); + } + + String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", inputClass, getModel()); + if (svUID != null) { + addConstant(resultClass, "serialVersionUID", "long", svUID, ObjectModelModifier.PUBLIC); + } + } + + protected void createListeners(ObjectModelClass resultClass, ObjectModelClass inputClass) { + + addAttribute(resultClass, "pcs", "java.beans.PropertyChangeSupport", "", + ObjectModelModifier.PROTECTED, ObjectModelModifier.FINAL); + + // Default constructor + ObjectModelOperation constructor = addConstructor(resultClass, ObjectModelModifier.PUBLIC); + setOperationBody(constructor, "" + /*{ + pcs = new PropertyChangeSupport(this); + }*/ + ); + + // Add PropertyListener + String propType = "java.beans.PropertyChangeListener"; + String strType = String.class.getName(); + String objectType = Object.class.getName(); + + ObjectModelOperation addPropertyChangeListener = addOperation(resultClass, + "addPropertyChangeListener", "void", ObjectModelModifier.PUBLIC); + addParameter(addPropertyChangeListener, propType, "listener"); + setOperationBody(addPropertyChangeListener, "" + /*{ + pcs.addPropertyChangeListener(listener); + }*/ + ); + + ObjectModelOperation addPropertyChangeListenerPlus = addOperation(resultClass, + "addPropertyChangeListener", "void", ObjectModelModifier.PUBLIC); + addParameter(addPropertyChangeListenerPlus, strType, "propertyName"); + addParameter(addPropertyChangeListenerPlus, propType, "listener"); + setOperationBody(addPropertyChangeListenerPlus, "" + /*{ + pcs.addPropertyChangeListener(propertyName, listener); + }*/ + ); + + ObjectModelOperation removePropertyChangeListener = addOperation(resultClass, + "removePropertyChangeListener", "void", ObjectModelModifier.PUBLIC); + addParameter(removePropertyChangeListener, propType, "listener"); + setOperationBody(removePropertyChangeListener, "" + /*{ + pcs.removePropertyChangeListener(listener); + }*/ + ); + + ObjectModelOperation removePropertyChangeListenerPlus = addOperation(resultClass, + "removePropertyChangeListener", "void", ObjectModelModifier.PUBLIC); + addParameter(removePropertyChangeListenerPlus, strType, "propertyName"); + addParameter(removePropertyChangeListenerPlus, propType, "listener"); + setOperationBody(removePropertyChangeListenerPlus, "" + /*{ + pcs.removePropertyChangeListener(propertyName, listener); + }*/ + ); + + ObjectModelOperation firePropertyChange = addOperation(resultClass, + "firePropertyChange", "void", ObjectModelModifier.PROTECTED); + addParameter(firePropertyChange, strType, "propertyName"); + addParameter(firePropertyChange, objectType, "oldValue"); + addParameter(firePropertyChange, objectType, "newValue"); + setOperationBody(firePropertyChange, "" + /*{ + pcs.firePropertyChange(propertyName, oldValue, newValue); + }*/ + ); + } + + +} Property changes on: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/Megatron.java =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/Megatron.java (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/Megatron.java 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,40 @@ +package org.nuiton.eugene.test.generator; + +import org.nuiton.eugene.java.ObjectModelTransformerToJava; +import org.nuiton.eugene.models.object.ObjectModelClass; + +/** + * Megatron + * + * Chainage des transformer : Modele de depart -> transformation dans BeanTransformer = modele d'entrée de Megatron + * + * Created: 12 nov. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class Megatron extends ObjectModelTransformerToJava { + + public Megatron() { + super(); + } + + /* + CAS modele de sortie vide : modele d'entree transformee par BeanTransformer + */ + @Override + protected ObjectModelTransformerToJava initPreviousTransformer() { + return new BeanTransformer(); + } + + @Override + public void transformFromClass(ObjectModelClass clazz) { + + + + } + +} Property changes on: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/Megatron.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,93 @@ +/* + * *##% + * EUGene Test + * Copyright (C) 2007 - 2009 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>. + * ##%* + */ + +package org.nuiton.eugene.test.generator; + +import org.nuiton.eugene.java.JavaBuilder; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelModifier; +import org.nuiton.eugene.models.object.ObjectModelOperation; + +/*{generator option: parentheses = false}*/ +/*{generator option: writeString = +}*/ +/** + * TestBuilder + * + * Created: 25 oct. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author: fdesbois $ + */ +public class TestBuilder extends JavaBuilder { + + public TestBuilder() { + super("TestModel"); + } + + //@Override + public void build() { + createRole(); + createPerson(); + } + + private void createRole() { + ObjectModelClass roleClass = createClass("Role", "org.chorem.bonzoms"); + + addAttribute(roleClass, "name", "java.lang.String"); + + //this.addImportForClassifier(roleClass, Date.class); + addAttribute(roleClass, "fromDate", "java.util.Date"); + addAttribute(roleClass, "thruDate", "java.util.Date"); + } + + private void createPerson() { + ObjectModelClass personneClass = createClass("Person", "org.chorem.bonzoms"); + + addAttribute(personneClass, "lastName", "java.lang.String"); + addAttribute(personneClass, "firstName", "java.lang.String", "\"2.0\""); + + //this.addImportForClassifier(personneClass, List.class); + addAttribute(personneClass, "roles", "java.util.List<org.chorem.bonzoms.Role>", + "new java.util.ArrayList<org.chorem.bonzoms.Role>()"); + + + ObjectModelOperation setLastName = addOperation(personneClass, "setLastName", "void", + ObjectModelModifier.PUBLIC); + addParameter(setLastName, "java.lang.String", "lastName"); + setOperationBody(setLastName, "" + /*{ + this.lastName = lastName; + }*/ + ); + + ObjectModelOperation getLastName = addOperation(personneClass, "getLastName", "java.lang.String", + ObjectModelModifier.PUBLIC); + setOperationBody(getLastName, "" + /*{ + return this.lastName; + }*/ + ); + } + +} Property changes on: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TestReader.java =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TestReader.java (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TestReader.java 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,51 @@ +/* + * *##% + * EUGene Test + * Copyright (C) 2007 - 2009 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>. + * ##%* + */ + +package org.nuiton.eugene.test.generator; + +import java.io.File; +import org.nuiton.eugene.ModelReader; +import org.nuiton.eugene.models.object.ObjectModel; + +/** + * TestReader + * + * Created: 27 oct. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author: fdesbois $ + */ +public class TestReader extends ModelReader<ObjectModel> { + + + @Override + public ObjectModel read(File[] file) { + TestBuilder builder = new TestBuilder(); + + builder.build(); + + return builder.getModel(); + } + +} Property changes on: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TestReader.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,948 @@ +/* *##% + * EUGene Test + * Copyright (C) 2007 - 2009 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>. + * ##%*/ +/******************************************************************************* + * GeneratorUtil.java + * + * Created: 13 déc. 2005 + * + * @author Arnaud Thimel <thimel@codelutin.com> + * + * @version $Revision$ + * + * Mise a jour: $Date$ par : $Author: tchemit $ + */ +package org.nuiton.eugene.test.generator; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.nuiton.eugene.Template; +import org.nuiton.eugene.GeneratorUtil; +import org.nuiton.eugene.models.Model; +import org.nuiton.eugene.models.object.ObjectModel; +import org.nuiton.eugene.models.object.ObjectModelAssociationClass; +import org.nuiton.eugene.models.object.ObjectModelAttribute; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelElement; +import org.nuiton.eugene.models.object.ObjectModelInterface; +import org.nuiton.eugene.models.object.ObjectModelOperation; +import org.nuiton.eugene.models.object.ObjectModelParameter; + +/** Classe regroupant divers méthodes utiles pour la génération des entités */ +public class TopiaGeneratorUtil extends GeneratorUtil { + + /** Stéréotype pour les interfaces devant être générées sous forme de facades */ + public final static String STEREOTYPE_FACADE = "facade"; + /** Stéréotype pour les objets devant être générées sous forme d'entités */ + public static final String STEREOTYPE_ENTITY = "entity"; + /** Stéréotype pour les objets devant être générées sous forme de DTO */ + public static final String STEREOTYPE_DTO = "dto"; + /** Stéréotype pour les objets devant être générées sous forme de bean */ + public static final String STEREOTYPE_BEAN = "bean"; + /** + * Stéréotype pour les interfaces devant être générées sous forme de + * services + */ + public static final String STEREOTYPE_SERVICE = "service"; + /** Stéréotype pour les interfaces devant être générées sous forme de DAO */ + public static final String STEREOTYPE_DAO = "dao"; + /** Stéréotype pour les attributs à indexer en base */ + public static final String STEREOTYPE_INDEXED = "indexed"; + /** Stéréotype pour les collections avec unicité */ + public static final String STEREOTYPE_UNIQUE = "unique"; + /** Stéréotype pour les attributs étant des clés primaires */ + public static final String STEREOTYPE_PRIMARYKAY = "primaryKey"; + /** Tag pour le type de persistence */ + public static final String TAG_PERSISTENCE_TYPE = "persistenceType"; + /** Tag pour le nom du champ / entité en BD */ + public static final String TAG_DB_NAME = "dbName"; + /** Tag pour le nom du schema en BD */ + public static final String TAG_SCHEMA_NAME = "dbSchema"; + /** Tag pour la taille du champ en BD */ + public static final String TAG_LENGTH = "length"; + /** Tag pour ajouter une annotation à un champ */ + public static final String TAG_ANNOTATION = "annotation"; + /** Tag pour ajouter specifier le copyright d'un fichier */ + public static final String TAG_COPYRIGHT = "copyright"; + /** Tag pour specfier le type d'acces a un champ */ + public static final String TAG_ACCESS = "access"; + /** Tag pour specfier si on doit générer i18n */ + public static final String TAG_I18N_PREFIX = "i18n"; + /** Tag pour ajouter un attribut dans une clef métier */ + public static final String TAG_NATURAL_ID = "naturalId"; + /** Tag pour specifier si une clef metier est mutable */ + public static final String TAG_NATURAL_ID_MUTABLE = "naturalIdMutable"; + /** Tag pour spécifier la caractèrelazy d'une association multiple */ + public static final String TAG_LAZY = "lazy"; + /** Tag pour spécifier la caractère fetch d'une association multiple */ + public static final String TAG_FETCH = "fetch"; + /** Tag pour spécifier la caractère order-by d'une association multiple */ + public static final String TAG_ORDER_BY = "orderBy"; + /** Tag pour spécifier la caractère not-null d'un attribut */ + public static final String TAG_NOT_NULL = "notNull"; + /** Tag pour spécifier la caractère embed-xml d'une association */ + public static final String TAG_EMBED_XML = "embedXml"; + /** + * Tag pour configurer l'interface du proxy sur autre chose que l'implementation par defaut. + * + * Par defaut : + * null > generere le proxy sur l'interface de l'implementation + * Autre valeur : + * "none" > laisse la configuration par defaut d'hibernate + */ + public static final String TAG_PROXY_INTERFACE = "hibernateProxyInterface"; + /** Tag pour spécifier le permissions à la création */ + public static final String TAG_SECURITY_CREATE = "securityCreate"; + /** Tag pour spécifier le permissions au chargement */ + public static final String TAG_SECURITY_LOAD = "securityLoad"; + /** Tag pour spécifier le permissions à la mise à jour */ + public static final String TAG_SECURITY_UPDATE = "securityUpdate"; + /** Tag pour spécifier le permissions à la suppression */ + public static final String TAG_SECURITY_DELETE = "securityDelete"; + /** Tag pour specifier de ne pas generer la methode toString */ + public static final String TAG_NOT_GENERATE_TO_STRING = "notGenerateToString"; + /** Tag pour specifier de trier les attributs par nom lors de la generation */ + public static final String TAG_SORT_ATTRIBUTE = "sortAttribute"; + /** Tag pour specfier si on doit générer la methode getOperator dans les daohelpers )*/ + public static final String TAG_GENERATE_OPERATOR_FOR_DAO_HELPER = "generateOperatorForDAOHelper"; + /** Type de persistence Hibernate */ + public static final String PERSISTENCE_TYPE_HIBERNATE = "hibernate"; + /** Type de persistence LDAP */ + public static final String PERSISTENCE_TYPE_LDAP = "ldap"; + /** Type de persistence par défaut (si aucun précisé) */ + public static final String PERSISTENCE_TYPE_DEFAULT = PERSISTENCE_TYPE_HIBERNATE; + /** Propriété des générateurs indiquant le package par défaut */ + public static final String PROPERTY_DEFAULT_PACKAGE = "defaultPackage"; + /** Le package par défaut si aucun n'est spécifié */ + public static final String DEFAULT_PACKAGE = "org.codelutin.malo"; + + /** + * Renvoie le package par défaut pour le générateur donné + * + * @param generator le générateur donné + * @return le package par défaut du générator donné + */ + public static String getDefaultPackage(Template generator) { + String packageName = generator.getProperty(PROPERTY_DEFAULT_PACKAGE); + if (packageName == null || "".equals(packageName)) { + packageName = DEFAULT_PACKAGE; + } + return packageName; + } + +// /** +// * @see GeneratorUtil#hasDocumentation +// * @deprecated +// */ +// @Deprecated +// public static boolean hasDocumentation(ObjectModelElement element) { +// return notEmpty(element.getDocumentation()); +// } + +// /** +// * @see GeneratorUtil#notEmpty +// * @deprecated +// */ +// @Deprecated +// public static boolean notEmpty(String s) { +// return (s != null && !"".equals(s)); +// } + + /** + * Renvoie l'interface DAO associée à la classe passée en paramètre + * + * @param clazz la classe à tester + * @param model le modele utilisé + * @return l'interface trouvée ou null sinon + */ + public static ObjectModelInterface getDAOInterface(ObjectModelClass clazz, + ObjectModel model) { + for (Object o : model.getInterfaces()) { + ObjectModelInterface daoInterface = (ObjectModelInterface) o; + if (daoInterface.getName().equals(clazz.getName() + "DAO")) { + if (daoInterface.hasStereotype(STEREOTYPE_DAO)) { + return daoInterface; + } + } + } + return null; + } + + /** + * Renvoie le type de persistence pour l'élément donné. Si aucun n'est + * trouvé, le type par défaut est utilisé + * + * @param element l'élément à tester + * @return le type de persitence pour l'élément donné. + */ + public static String getPersistenceType(ObjectModelElement element) { + String tag = element.getTagValue(TAG_PERSISTENCE_TYPE); + if (tag == null) { + tag = PERSISTENCE_TYPE_DEFAULT; + } + return tag; + } + + public static String getReverseDBName(ObjectModelAttribute attr) { + if (attr.getReverseAttribute() != null) { + return getDBName(attr.getReverseAttribute()); + } else { + return getDBName(attr) + "_id"; + } + } + + /** + * Renvoie le nom BD de l'élement passé en paramètre. Elle se base sur le + * tag associé si il existe, sinon sur le nom de l'élément + * + * @param element l'élément à tester + * @return le nom de table + */ + public static String getDBName(ObjectModelElement element) { + if (element == null) { + return null; + } + if (notEmpty(element.getTagValue(TAG_DB_NAME))) { + return element.getTagValue(TAG_DB_NAME); + } + return toLowerCaseFirstLetter(element.getName()); + } + + /** + * Cherche et renvoie le schema a utiliser sur cet element, sinon sur le model. + * + * @param element l'élément à tester + * @param model le modele utilisé + * @return le nom du schema ou null + */ + public static String getSchemaName(ObjectModelElement element, + ObjectModel model) { + return findTagValue(TAG_SCHEMA_NAME, element, model); + } + + /** + * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model. + * + * @param element l'élément à tester + * @param model le modele utilisé + * @return le prefix i18n ou <code>null</code> si non spécifié + */ + public static String getI18nPrefix(ObjectModelElement element, + ObjectModel model) { + return GeneratorUtil.findTagValue(TAG_I18N_PREFIX, element, model); + } + + /** + * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model. + * + * @param element l'élément à tester + * @param model le modele utilisé + * @return le prefix i18n ou <code>null</code> si non spécifié + */ + public static boolean shouldgenerateOperatorForDAOHelper(ObjectModelElement element, + ObjectModel model) { + String tagValue = GeneratorUtil.findTagValue(TAG_GENERATE_OPERATOR_FOR_DAO_HELPER, element, model); + boolean generate = GeneratorUtil.notEmpty(tagValue) && Boolean.valueOf(tagValue); + return generate; + } + + /** + * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe. + * + * @param clazz la classe à tester + * @return la liste des attributs de la clef métier ou null si pas de clef métier. + */ + public static List<String> getNaturalId(ObjectModelClass clazz) { + String value = clazz.getTagValue(TAG_NATURAL_ID); + if (value == null || value.trim().isEmpty()) { + return java.util.Collections.emptyList(); + } + List<String> result = new ArrayList<String>(); + for (String attribute : value.split(",")) { + result.add(attribute.trim()); + } + return result; + } + + /** + * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe. + * + * @param clazz la classe à tester + * @param model le modele + * @return la liste des attributs de la clef métier ou null si pas de clef métier. + */ + public static boolean generateToString(ObjectModelClass clazz, + ObjectModel model) { + String value; + value = model.getTagValue(TAG_NOT_GENERATE_TO_STRING); + if (value != null && !value.trim().isEmpty()) { + return false; + } + value = clazz.getTagValue(TAG_NOT_GENERATE_TO_STRING); + if (value != null && !value.trim().isEmpty()) { + return false; + } + return true; + } + + /** + * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe. + * + * @param clazz la classe à tester + * @param model le modele + * @return la liste des attributs de la clef métier ou null si pas de clef métier. + */ + public static boolean sortAttribute(ObjectModelClass clazz, + ObjectModel model) { + String value; + value = clazz.getTagValue(TAG_SORT_ATTRIBUTE); + if (value == null || value.trim().isEmpty() || "false".equals(value.trim())) { + return false; + } + if (value != null && "true".equals(value.trim())) { + return true; + } + + value = model.getTagValue(TAG_SORT_ATTRIBUTE); + if (value == null || value.trim().isEmpty() || "false".equals(value.trim())) { + return false; + } + if (value != null && "true".equals(value.trim())) { + return true; + } + return true; + } + + /** + * Detecte si un attribut fait partie d'une clef metier. + * + * @param attribute l'attribut à tester + * @return <code>true</code> si l'attribut fait partie d'une clef metier, <code>false</cdoe> sinon. + */ + public static boolean isNaturalId(ObjectModelAttribute attribute) { + String value = attribute.getTagValue(TAG_NATURAL_ID); + if (!GeneratorUtil.notEmpty(value)) { + // valeur null, donc pas positionnee + return false; + } + try { + return Boolean.valueOf(value.trim()); + } catch (Exception e) { + // on a pas reussi a convertir en boolean. + //todo peut-être declancher une exception ? + return false; + } + } + + /** + * Cherches et renvoie le copyright a utiliser sur le model. + * + * @param model le modele utilisé + * @return le texte du copyright ou null + */ + public static String getCopyright(Model model) { + return findTagValue(TAG_COPYRIGHT, null, model); + } + +// /** +// * @see GeneratorUtil#findTagValue +// * @deprecated +// */ +// @Deprecated +// public static String findTagValue(String tagName, +// ObjectModelElement element, Model model) { +// if (element == null) { +// if (model != null) { +// if (notEmpty(model.getTagValue(tagName))) { +// return model.getTagValue(tagName); +// } +// } +// return null; +// } +// if (notEmpty(element.getTagValue(tagName))) { +// return element.getTagValue(tagName); +// } +// //On va chercher sur l'element declarant +// return findTagValue(tagName, element.getDeclaringElement(), model); +// } + + public static <Type extends ObjectModelElement> Collection<Type> getElementsWithStereotype( + Collection<Type> elements, String... stereotypes) { + Collection<Type> result = new ArrayList<Type>(); + for (Type element : elements) { + if (hasStereotypes(element, stereotypes)) { + result.add(element); + } + } + return result; + } + + public static boolean hasStereotypes(ObjectModelElement element, + String... stereotypes) { + for (String stereotype : stereotypes) { + if (!element.hasStereotype(stereotype)) { + return false; + } + } + return true; + } + + public static String getPrimaryKeyAttributesListDeclaration( + ObjectModelClass clazz, boolean includeName) { + String attributes = ""; + for (ObjectModelAttribute attr : getElementsWithStereotype(clazz.getAttributes(), STEREOTYPE_PRIMARYKAY)) { + attributes += attr.getType(); + if (includeName) { + attributes += " " + attr.getName(); + } + attributes += ", "; + } + if (attributes.length() > 0) { + attributes = attributes.substring(0, attributes.length() - 2); + } + return attributes; + } + +// public static String capitalize(String s) { +// return StringUtils.capitalize(s); +// } + + public static boolean isAssociationClassDoublon(ObjectModelAttribute attr) { + return (attr.getReverseAttribute() != null) && (attr.getDeclaringElement().equals(attr.getReverseAttribute().getDeclaringElement())) && (!GeneratorUtil.isFirstAttribute(attr)); + } + + /** + * Renvoie le nom de l'attribut de classe d'association en fonction des cas: + * Si l'attribut porte le même nom que le type (extrémité inverse de + * l'association), on lui ajoute le nom de la classe d'association + * + * @param attr l'attribut a traiter + * @return le nom de l'attribut de classe d'association + */ + public static String getAssocAttrName(ObjectModelAttribute attr) { + String typeName = attr.getType().substring( + attr.getType().lastIndexOf(".") + 1); + String result = attr.getName(); + if (attr.getName().equalsIgnoreCase(typeName)) { + result += StringUtils.capitalize(attr.getAssociationClass().getName()); + } + return result; + } + + public static String getDOType(ObjectModelElement elem, ObjectModel model) { + String type = elem.getName(); + if (elem instanceof ObjectModelAttribute) { + type = ((ObjectModelAttribute) elem).getType(); + } + if (elem instanceof ObjectModelClass) { + type = ((ObjectModelClass) elem).getQualifiedName(); + } + return getDOType(type, model); + } + + public static String getDOType(String type, ObjectModel model) { + if (!model.hasClass(type)) { + return type; + } + ObjectModelClass clazz = model.getClass(type); + if (clazz.hasStereotype(STEREOTYPE_ENTITY)) { + if (shouldBeAbstract(clazz)) { + type += "Abstract"; + } else { + type += "Impl"; + } + } + return type; + } + private static final Set<String> numberTypes = new HashSet<String>(); + private static final Set<String> textTypes = new HashSet<String>(); + private static final Set<String> booleanTypes = new HashSet<String>(); + private static final Set<String> primitiveTypes = new HashSet<String>(); + private static final String VOID_TYPE = "void"; + + static { + numberTypes.add("byte"); + numberTypes.add("java.lang.Byte"); + numberTypes.add("Byte"); + numberTypes.add("short"); + numberTypes.add("java.lang.Short"); + numberTypes.add("Short"); + numberTypes.add("int"); + numberTypes.add("java.lang.Integer"); + numberTypes.add("Integer"); + numberTypes.add("long"); + numberTypes.add("java.lang.Long"); + numberTypes.add("Long"); + numberTypes.add("float"); + numberTypes.add("java.lang.Float"); + numberTypes.add("Float"); + numberTypes.add("double"); + numberTypes.add("java.lang.Double"); + numberTypes.add("Double"); + + textTypes.add("char"); + textTypes.add("java.lang.Char"); + textTypes.add("Char"); + textTypes.add("java.lang.String"); + textTypes.add("String"); + + booleanTypes.add("boolean"); + booleanTypes.add("java.lang.Boolean"); + booleanTypes.add("Boolean"); + + primitiveTypes.addAll(numberTypes); + primitiveTypes.addAll(textTypes); + primitiveTypes.addAll(booleanTypes); + } + + public static boolean isNumericType(ObjectModelAttribute attr) { + return numberTypes.contains(attr.getType()); + } + + public static boolean isTextType(ObjectModelAttribute attr) { + return textTypes.contains(attr.getType()); + } + + public static boolean isDateType(ObjectModelAttribute attr) { + return "java.util.Date".equals(attr.getType()); + } + + public static boolean isBooleanType(ObjectModelAttribute attr) { + return booleanTypes.contains(attr.getType()); + } + + public static boolean isPrimitiveType(ObjectModelAttribute attr) { + return primitiveTypes.contains(attr.getType()); + } + + /** + * Indique si la classe specifiee n'a aucune ou que des methodes abstraites + * + * @param clazz l'instance de ObjectModelClass + * @return true si la classe n'a que des operations abstraite ou aucune + * operation + */ + public static boolean hasNothingOrAbstractMethods(ObjectModelClass clazz) { + boolean result = true; + Iterator<?> operations = clazz.getOperations().iterator(); + while (result && operations.hasNext()) { + ObjectModelOperation op = (ObjectModelOperation) operations.next(); + result = op.isAbstract(); + } + return result; + } + + /** + * Indique si la classe specifiee devrait etre abstraite + * + * @param clazz l'instance de ObjectModelClass + * @return true dans ce cas, false sinon + */ + public static boolean shouldBeAbstract(ObjectModelClass clazz) { + return clazz != null && (clazz.isAbstract() && hasNothingOrAbstractMethods(clazz)); + } + + /** + * <p> + * Cette méthode permet de détecter si + * - l'attribut représente une relation 1-n + * - cette relation est unidirectionnelle + * - le type de l'attribut représente un entité + * - cette entité a des sous-classes dans le modèle + * <p/> + * Ce cas correspond à une incompatibilité d'Hibernate qui nous oblige a + * adopter un comportement particulier. + * </p> + * + * @param attr l'attribut a tester + * @param model le model + * @return true si et seulement si il s'agit bien de ce type de relation + */ + public static boolean hasUnidirectionalRelationOnAbstractType( + ObjectModelAttribute attr, ObjectModel model) { + ObjectModelAttribute reverse = attr.getReverseAttribute(); + //relation 1-n + if (reverse != null && isNMultiplicity(attr) && !isNMultiplicity(reverse)) { + //Pas de navigabilité + if (!reverse.isNavigable()) { + //Il s'agit d'une entity + ObjectModelClass clazz = model.getClass(attr.getType()); + if (clazz != null && clazz.hasStereotype(STEREOTYPE_ENTITY)) { + //Cette classe a des sous-classes dans le modèle + for (ObjectModelClass subClass : model.getClasses()) { + if (subClass.getSuperclasses().contains(clazz)) { + return true; + } + } + } + } + } + return false; + } + + /** + * Renvoie le nom unique de table pour une relation ManyToMany en fonction + * de l'attribut <code>attr</code> + * <p/> + * Plusieurs cas de figure: + * <li> + * + * @param attr l'attribut servant de base au calcul du nom + * @return le nom de la table + */ + public static String getManyToManyTableName(ObjectModelAttribute attr) { + String result; + + if (attr.hasAssociationClass()) { + result = TopiaGeneratorUtil.getDBName(attr.getAssociationClass()); + } else { + String name = attr.getName(); + String revers = attr.getReverseAttributeName(); + + if (name.compareToIgnoreCase(revers) < 0) { + result = name + "_" + revers; + } else { + result = revers + "_" + name; + } + } + // String result; + // if (!Util.isFirstAttribute(attr)) { + // result = attr.getDeclaringElement().getName() + "_" + attr.getReverseAttribute().getDeclaringElement().getName(); + // } else { + // result = attr.getReverseAttribute().getDeclaringElement().getName() + "_" + attr.getDeclaringElement().getName(); + // } + return result.toLowerCase(); + } + + /** + * Renvoie le type d'interface à utiliser en fonction de l'attribut + * + * @param attr l'attribut a traiter + * @return String + */ + public static String getNMultiplicityInterfaceType(ObjectModelAttribute attr) { + if (attr.hasStereotype(STEREOTYPE_UNIQUE)) { + return Set.class.getName(); + } else if (attr.isIndexed() || attr.isOrdered()) { + return List.class.getName(); + } + return Collection.class.getName(); + } + + /** + * Renvoie le type d'objet (instance) à utiliser en fonction de l'attribut + * + * @param attr l'attribut a traiter + * @return String + */ + public static String getNMultiplicityObjectType(ObjectModelAttribute attr) { + if (attr.hasStereotype(STEREOTYPE_UNIQUE)) { + return HashSet.class.getName(); + } else if (attr.isIndexed() || attr.isOrdered()) { + //On considère qu'on ne sait pas traiter vraiment l'attribut "ordered" + // puisqu'on va conserver l'ordre d'insertion, et non un ordre en + // fonction d'un élément donné. Donc on renvoi une ArrayList + return ArrayList.class.getName(); + } + LinkedList.class.getName(); + return ArrayList.class.getName(); + } + + /** + * Renvoie le type d'interface à utiliser en fonction de l'attribut + * + * @param attr l'attribut a traiter + * @return String + */ + public static String getNMultiplicityHibernateType(ObjectModelAttribute attr) { + if (attr.hasStereotype(STEREOTYPE_UNIQUE)) { + return "set"; + } else if (attr.isIndexed()) { + return "list"; + } + //attr.isOrdered() - On génère le ordered en bag + return "bag"; + } + + /** + * Obtain the list of entities classes with the possibility to sort the result. + * + * @param model the current model to scan + * @param sort flag to allow sort the result + * @return the list of filtred classes by their stereotype + */ + public static List<ObjectModelClass> getEntityClasses(ObjectModel model, + boolean sort) { + return getClassesByStereotype(STEREOTYPE_ENTITY, model, sort); + } + + /** + * Obtain the list of classes for a given stereotype with the possibility to sort the result. + * + * @param stereotype filter stereotype + * @param model the current model to scan + * @param sort flag to allow sort the result + * @return the list of filtred classes by their stereotype + */ + public static List<ObjectModelClass> getClassesByStereotype( + String stereotype, ObjectModel model, boolean sort) { + List<ObjectModelClass> classes = new ArrayList<ObjectModelClass>(); + for (ObjectModelClass clazz : model.getClasses()) { + if (clazz.hasStereotype(stereotype)) { + classes.add(clazz); + } + } + if (sort && !classes.isEmpty()) { + java.util.Collections.sort(classes, + new java.util.Comparator<ObjectModelClass>() { + + @Override + public int compare(ObjectModelClass o1, + ObjectModelClass o2) { + return o1.getQualifiedName().compareTo( + o2.getQualifiedName()); + } + }); + } + return classes; + } + + /** + * Detecte si la clef metier d'une classe est mutable ou pas. + * <p/> + * On respecte la valeur par defaut d'hibernate, à savoir que par default une clef metier est non mutable. + * + * @param clazz la classe a tester + * @return <code>true</code> si le tag value a ete positionne sur la classe via le tag + * {@link #TAG_NATURAL_ID_MUTABLE}, , <code>false</code> sinon. + */ + public static boolean isNaturalIdMutable(ObjectModelClass clazz) { + String value = clazz.getTagValue(TAG_NATURAL_ID_MUTABLE); + if (!notEmpty(value)) { + // valeur null, donc par default positionnee + return false; + } + try { + return Boolean.valueOf(value.trim()); + } catch (Exception e) { + // on a pas reussi a convertir en boolean. + //todo peut-être declancher une exception ? + return false; + } + } + + /** + * Obtain the list of fqn of object involed in the given class. + * + * @param aClass the clazz to inspect + * @param incomingFqns incoming fqns + * @return the list of fqn of attributes + */ + public static List<String> getImports(ObjectModelClass aClass, String... incomingFqns) { + Set<String> tmp = new HashSet<String>(); + tmp.addAll(Arrays.asList(incomingFqns)); + getImports(aClass, tmp); + List<String> result = cleanImports(aClass.getPackageName(), tmp); + return result; + } + + /** + * Obtain the list of fqn of object involed in the given interface. + * + * @param anInterface the interface to inspect + * @param incomingFqns incoming fqns + * @return the list of fqn of attributes + */ + public static List<String> getImports(ObjectModelInterface anInterface, String... incomingFqns) { + Set<String> tmp = new HashSet<String>(); + tmp.addAll(Arrays.asList(incomingFqns)); + getImports(anInterface, tmp); + List<String> result = cleanImports(anInterface.getPackageName(), tmp); + return result; + } + + public static String getSimpleName(String fqn) { + int lasIndex = fqn.lastIndexOf("."); + if (lasIndex == 1) { + // primitive type + return fqn; + } + return fqn.substring(lasIndex + 1); + /*if (lasIndex == aClass.getPackageName().length()) { + // same package + return fqn.substring(lasIndex + 1); + } + + return fqn;*/ + } + + /** + * Obtain the list of fqn of object involed in the given class. + * + * @param aClass the class to inspect + * @param fqns where to store found fqns + */ + protected static void getImports(ObjectModelClass aClass, Set<String> fqns) { + // scan attributes + for (ObjectModelAttribute attr : aClass.getAttributes()) { + fqns.add(attr.getType()); + if (isNMultiplicity(attr)) { + String collectionType = getNMultiplicityInterfaceType(attr); + fqns.add(collectionType); + String collectionObject = getNMultiplicityObjectType(attr); + fqns.add(collectionObject); + } + } + for (ObjectModelAttribute attribute : aClass.getAllOtherAttributes()) { + fqns.add(attribute.getType()); + } + // scan associations + if (aClass instanceof ObjectModelAssociationClass) { + ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) aClass; + for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) { + if (attr == null) { + continue; + } + fqns.add(attr.getType()); + if (isNMultiplicity(attr)) { + String collectionType = getNMultiplicityInterfaceType(attr); + fqns.add(collectionType); + String collectionObject = getNMultiplicityObjectType(attr); + fqns.add(collectionObject); + } + } + } + // scan operations + for (ObjectModelOperation operation : aClass.getOperations()) { + getImports(operation, fqns); + } + // scan super interfaces + for (ObjectModelInterface modelInterface : aClass.getInterfaces()) { + fqns.add(modelInterface.getQualifiedName()); + getImports(modelInterface, fqns); + } + // scan super classes + for (ObjectModelClass modelClass : aClass.getSuperclasses()) { + fqns.add(modelClass.getQualifiedName()); + getImports(modelClass); + } + } + + /** + * Obtain the list of fqn of object involed in the given interface. + * + * @param anInterface the interface to inspect + * @param fqns where to store found fqns + */ + protected static void getImports(ObjectModelInterface anInterface, Set<String> fqns) { + // scan operations + for (ObjectModelOperation operation : anInterface.getOperations()) { + getImports(operation, fqns); + } + // scan super interfaces + for (ObjectModelInterface modelInterface : anInterface.getInterfaces()) { + fqns.add(modelInterface.getQualifiedName()); + getImports(modelInterface, fqns); + } + } + + /** + * Obtain the fqn's list of all involed type in a givne operation. + * + * @param operation operation to inspect + * @param fqns where to store found fqns + */ + protected static void getImports(ObjectModelOperation operation, Set<String> fqns) { + String fqn = operation.getReturnType(); + fqns.add(fqn); + for (ObjectModelParameter parameter : operation.getParameters()) { + fqns.add(parameter.getType()); + } + } + + /** + * Clean a set of fqns, transform it into a {@link List} and sort it. + * + * @param packageName the current package name + * @param fqns the dirty set of fqns + * @return the sorted cleaned list of fqns. + */ + protected static List<String> cleanImports(String packageName, Set<String> fqns) { + fqns.removeAll(primitiveTypes); + fqns.remove(VOID_TYPE); + int packageLength = packageName.length(); + List<String> genericType = new ArrayList<String>(); + for (Iterator<String> it = fqns.iterator(); it.hasNext();) { + String fqn = it.next(); + int lastIndex = fqn.lastIndexOf("."); + if (lastIndex == packageLength && fqn.startsWith(packageName)) { + // same package + it.remove(); + continue; + } + int genericIndex = fqn.indexOf('<'); + if (genericIndex != -1) { + genericType.add(fqn.substring(0, genericIndex)); + it.remove(); + } + } + fqns.addAll(genericType); + + ArrayList<String> result = new ArrayList<String>(fqns); + java.util.Collections.sort(result); + return result; + } + + /** + * Convertit un nom de variable en nom de constante. + * + * @param variableName le nom de variable a convertir + * @return le nom de la constante à partir du nom de la variable + */ + public static String convertVariableNameToConstantName(String variableName) { + //TODO Faire des tests pour savoir si variableName est non null et valide + //TODO Ameliorer l'algo pour tenir compte des caractères non alpha + //TODO pour le moment cela convient, donc... + StringBuilder buffer = new StringBuilder(); + boolean lastCarIsUp = false; + for (int i = 0, j = variableName.length(); i < j; i++) { + char c = variableName.charAt(i); + boolean carIsUp = Character.isUpperCase(c); + if (i > 0 && !lastCarIsUp && carIsUp) { + // ajout d'un _ + buffer.append('_'); + } + if (carIsUp) { + buffer.append(c); + } else { + buffer.append(Character.toUpperCase(c)); + } + lastCarIsUp = carIsUp; + } + return buffer.toString(); + } +} // GeneratorUtil + Property changes on: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/models/dtotest.objectmodel =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/models/dtotest.objectmodel (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/models/dtotest.objectmodel 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,153 @@ +<?xml version="1.0" encoding="UTF-8"?> +<objectModel xmlns="http://www.codelutin.org/eugene/objectModel" name="TopiaTest" version="1"> + <class name="Personne" package="org.nuiton.eugene.test"> + <stereotype name="entity"/> + <superclass name="org.nuiton.eugene.test.Party2" discriminator=""/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="otherNames" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="0" maxMultiplicity="-1"/> + <attribute visibility="public" type="org.nuiton.eugene.test.Address" reverseAttributeName="" associationType="aggregate" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + </class> + <class name="Employe" package="org.nuiton.eugene.test"> + <stereotype name="entity"/> + <superclass name="org.nuiton.eugene.test.Personne" discriminator=""/> + <attribute name="salary" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test.Company" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="false" ordering="unordered"/> + <attribute name="lead" visibility="public" type="org.nuiton.eugene.test.Department" reverseAttributeName="leader" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="1" navigable="false" ordering="unordered"/> + </class> + <class name="Company" package="org.nuiton.eugene.test"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test.Employe" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + <attribute visibility="public" associationClassName="org.nuiton.eugene.test.Bill" type="org.nuiton.eugene.test.Store" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + <attribute visibility="public" type="org.nuiton.eugene.test.Department" reverseAttributeName="" associationType="composite" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + </class> + <class name="Address" package="org.nuiton.eugene.test"> + <stereotype name="entity"/> + <attribute name="city" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="adress" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test.Personne" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="false" ordering="unordered"/> + </class> + <class name="Department" package="org.nuiton.eugene.test"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="leader" visibility="public" type="org.nuiton.eugene.test.Employe" reverseAttributeName="lead" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + <attribute visibility="public" type="org.nuiton.eugene.test.Company" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + <attribute visibility="public" type="org.nuiton.eugene.test.Product" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + </class> + <class name="Product" package="org.nuiton.eugene.test"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test.Department" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="false" ordering="unordered"/> + <attribute visibility="public" type="org.nuiton.eugene.test.Type" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + </class> + <class name="Store" package="org.nuiton.eugene.test"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="DEFAULT_NUM" associationType="composite" visibility="public" static="true" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="numStore" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <operation name="getDefaultNum" visibility="public" static="true"> + <returnParameter type="java.lang.String"/> + </operation> + <class name="Row" package="org.nuiton.eugene.test"> + <attribute name="num" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="position" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + </class> + <attribute visibility="public" associationClassName="org.nuiton.eugene.test.Bill" type="org.nuiton.eugene.test.Company" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="0" maxMultiplicity="-1" navigable="false" ordering="unordered"/> + </class> + <class name="Type" package="org.nuiton.eugene.test"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test.Product" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="false" ordering="unordered"/> + </class> + <associationClass name="Bill" package="org.nuiton.eugene.test"> + <stereotype name="entity"/> + <participant name="org.nuiton.eugene.test.Company" attribute=""/> + <participant name="org.nuiton.eugene.test.Store" attribute=""/> + <attribute name="cost" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="date" associationType="composite" visibility="public" type="java.util.Date" minMultiplicity="1" maxMultiplicity="1"/> + </associationClass> + <class name="Voiture" abstract="true" package="org.nuiton.eugene.test.beangen"> + <stereotype name="bean"/> + <tagValue name="documentation" value="Doc for BeanA"/> + <attribute name="immatriculation" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"> + <tagValue name="documentation" value="attrA of BeanA"/> + </attribute> + <attribute name="modele" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="proprietaire" associationType="composite" visibility="public" type="org.nuiton.eugene.test.beangen.PersonneDTO" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test.beangen.Roue" reverseAttributeName="" associationType="composite" reverseMaxMultiplicity="1" minMultiplicity="4" maxMultiplicity="4" navigable="true" ordering="unordered"/> + <attribute visibility="public" type="org.nuiton.eugene.test.beangen.Siege" reverseAttributeName="" associationType="composite" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="4" navigable="true" ordering="unordered"/> + </class> + <class name="Roue" package="org.nuiton.eugene.test.beangen"> + <stereotype name="bean"/> + <operation name="mount" visibility="public"> + <returnParameter type="void"/> + </operation> + <operation name="getModel" visibility="public"> + <returnParameter type="int"/> + <parameter name="id" type="java.lang.String"/> + </operation> + <attribute visibility="public" type="org.nuiton.eugene.test.beangen.Voiture" reverseAttributeName="" reverseMaxMultiplicity="4" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + </class> + <class name="RelationDTO" package="org.nuiton.eugene.test.beangen"> + <stereotype name="dto"/> + <attribute name="idCompany" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="idDepartement" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="dateDebut" associationType="composite" visibility="public" type="java.util.Date" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="person" visibility="public" type="org.nuiton.eugene.test.beangen.PersonneDTO" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + </class> + <class name="PersonneDTO" package="org.nuiton.eugene.test.beangen"> + <dependency name="" supplierName="org.nuiton.eugene.test.Personne"/> + <stereotype name="dto"/> + <attribute visibility="public" type="org.nuiton.eugene.test.beangen.RelationDTO" reverseAttributeName="person" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="false" ordering="unordered"/> + </class> + <class name="Siege" package="org.nuiton.eugene.test.beangen"> + <stereotype name="bean"/> + <attribute name="noSerie" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test.beangen.Voiture" reverseAttributeName="" reverseMaxMultiplicity="4" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + </class> + <interface name="Vehicule" package="org.nuiton.eugene.test.beangen"> + <operation name="start" visibility="public"> + <returnParameter type="void"/> + </operation> + </interface> + <class name="Contact2" package="org.nuiton.eugene.test.deletetest"> + <stereotype name="entity"/> + <attribute name="contactValue" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="type" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <operation name="findAllByCompany" visibility="public"> + <returnParameter type="java.util.Set<Contact2>"/> + <parameter name="company" type="org.nuiton.eugene.test.Company"/> + <stereotype name="dao"/> + </operation> + <attribute visibility="public" type="org.nuiton.eugene.test.Party2" reverseAttributeName="contacts" reverseMaxMultiplicity="-1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + </class> + <class name="Telephone2" package="org.nuiton.eugene.test.deletetest"> + <stereotype name="entity"/> + <superclass name="org.nuiton.eugene.test.Contact2" discriminator=""/> + <attribute name="prefix" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="country" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + </class> + <class name="Party2" package="org.nuiton.eugene.test.deletetest"> + <stereotype name="entity"/> + <attribute name="contacts" visibility="public" type="org.nuiton.eugene.test.Contact2" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + </class> + <class name="Person" package="org.nuiton.topia.test.entities"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="firstname" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.topia.test.entities.Pet" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + </class> + <class name="Pet" package="org.nuiton.topia.test.entities"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="type" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.topia.test.entities.Person" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + <attribute visibility="public" type="org.nuiton.topia.test.entities.Race" reverseAttributeName="" associationType="composite" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + </class> + <class name="Race" package="org.nuiton.topia.test.entities"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.topia.test.entities.Pet" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="false" ordering="unordered"/> + </class> + <class name="Set<Contact2>" package="java.util"/> +</objectModel> Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/models/dtotest2.objectmodel =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/models/dtotest2.objectmodel (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/models/dtotest2.objectmodel 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,153 @@ +<?xml version="1.0" encoding="UTF-8"?> +<objectModel xmlns="http://www.codelutin.org/eugene/objectModel" name="TopiaTest" version="1"> + <class name="Personne" package="org.nuiton.eugene.test2"> + <stereotype name="entity"/> + <superclass name="org.nuiton.eugene.test2.Party2" discriminator=""/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="otherNames" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="0" maxMultiplicity="-1"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.Address" reverseAttributeName="" associationType="aggregate" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + </class> + <class name="Employe" package="org.nuiton.eugene.test2"> + <stereotype name="entity"/> + <superclass name="org.nuiton.eugene.test2.Personne" discriminator=""/> + <attribute name="salary" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.Company" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="false" ordering="unordered"/> + <attribute name="lead" visibility="public" type="org.nuiton.eugene.test2.Department" reverseAttributeName="leader" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="1" navigable="false" ordering="unordered"/> + </class> + <class name="Company" package="org.nuiton.eugene.test2"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.Employe" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + <attribute visibility="public" associationClassName="org.nuiton.eugene.test2.Bill" type="org.nuiton.eugene.test2.Store" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.Department" reverseAttributeName="" associationType="composite" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + </class> + <class name="Address" package="org.nuiton.eugene.test2"> + <stereotype name="entity"/> + <attribute name="city" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="adress" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.Personne" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="false" ordering="unordered"/> + </class> + <class name="Department" package="org.nuiton.eugene.test2"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="leader" visibility="public" type="org.nuiton.eugene.test2.Employe" reverseAttributeName="lead" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.Company" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.Product" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + </class> + <class name="Product" package="org.nuiton.eugene.test2"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.Department" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="false" ordering="unordered"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.Type" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + </class> + <class name="Store" package="org.nuiton.eugene.test2"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="DEFAULT_NUM" associationType="composite" visibility="public" static="true" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="numStore" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <operation name="getDefaultNum" visibility="public" static="true"> + <returnParameter type="java.lang.String"/> + </operation> + <class name="Row" package="org.nuiton.eugene.test2"> + <attribute name="num" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="position" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + </class> + <attribute visibility="public" associationClassName="org.nuiton.eugene.test2.Bill" type="org.nuiton.eugene.test2.Company" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="0" maxMultiplicity="-1" navigable="false" ordering="unordered"/> + </class> + <class name="Type" package="org.nuiton.eugene.test2"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.Product" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="false" ordering="unordered"/> + </class> + <associationClass name="Bill" package="org.nuiton.eugene.test2"> + <stereotype name="entity"/> + <participant name="org.nuiton.eugene.test2.Company" attribute=""/> + <participant name="org.nuiton.eugene.test2.Store" attribute=""/> + <attribute name="cost" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="date" associationType="composite" visibility="public" type="java.util.Date" minMultiplicity="1" maxMultiplicity="1"/> + </associationClass> + <class name="Voiture" abstract="true" package="org.nuiton.eugene.test2.beangen"> + <stereotype name="bean"/> + <tagValue name="documentation" value="Doc for BeanA"/> + <attribute name="immatriculation" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"> + <tagValue name="documentation" value="attrA of BeanA"/> + </attribute> + <attribute name="modele" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="proprietaire" associationType="composite" visibility="public" type="org.nuiton.eugene.test2.beangen.PersonneDTO" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.beangen.Roue" reverseAttributeName="" associationType="composite" reverseMaxMultiplicity="1" minMultiplicity="4" maxMultiplicity="4" navigable="true" ordering="unordered"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.beangen.Siege" reverseAttributeName="" associationType="composite" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="4" navigable="true" ordering="unordered"/> + </class> + <class name="Roue" package="org.nuiton.eugene.test2.beangen"> + <stereotype name="bean"/> + <operation name="mount" visibility="public"> + <returnParameter type="void"/> + </operation> + <operation name="getModel" visibility="public"> + <returnParameter type="int"/> + <parameter name="id" type="java.lang.String"/> + </operation> + <attribute visibility="public" type="org.nuiton.eugene.test2.beangen.Voiture" reverseAttributeName="" reverseMaxMultiplicity="4" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + </class> + <class name="RelationDTO" package="org.nuiton.eugene.test2.beangen"> + <stereotype name="dto"/> + <attribute name="idCompany" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="idDepartement" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="dateDebut" associationType="composite" visibility="public" type="java.util.Date" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="person" visibility="public" type="org.nuiton.eugene.test2.beangen.PersonneDTO" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + </class> + <class name="PersonneDTO" package="org.nuiton.eugene.test2.beangen"> + <dependency name="" supplierName="org.nuiton.eugene.test2.Personne"/> + <stereotype name="dto"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.beangen.RelationDTO" reverseAttributeName="person" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="false" ordering="unordered"/> + </class> + <class name="Siege" package="org.nuiton.eugene.test2.beangen"> + <stereotype name="bean"/> + <attribute name="noSerie" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.eugene.test2.beangen.Voiture" reverseAttributeName="" reverseMaxMultiplicity="4" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + </class> + <interface name="Vehicule" package="org.nuiton.eugene.test2.beangen"> + <operation name="start" visibility="public"> + <returnParameter type="void"/> + </operation> + </interface> + <class name="Contact2" package="org.nuiton.eugene.test2.deletetest"> + <stereotype name="entity"/> + <attribute name="contactValue" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="type" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <operation name="findAllByCompany" visibility="public"> + <returnParameter type="java.util.Set<Contact2>"/> + <parameter name="company" type="org.nuiton.eugene.test2.Company"/> + <stereotype name="dao"/> + </operation> + <attribute visibility="public" type="org.nuiton.eugene.test2.Party2" reverseAttributeName="contacts" reverseMaxMultiplicity="-1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + </class> + <class name="Telephone2" package="org.nuiton.eugene.test2.deletetest"> + <stereotype name="entity"/> + <superclass name="org.nuiton.eugene.test2.Contact2" discriminator=""/> + <attribute name="prefix" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="country" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + </class> + <class name="Party2" package="org.nuiton.eugene.test2.deletetest"> + <stereotype name="entity"/> + <attribute name="contacts" visibility="public" type="org.nuiton.eugene.test2.Contact2" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + </class> + <class name="Person" package="org.nuiton.topia.test.entities"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="firstname" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.topia.test.entities.Pet" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/> + </class> + <class name="Pet" package="org.nuiton.topia.test.entities"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute name="type" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.topia.test.entities.Person" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + <attribute visibility="public" type="org.nuiton.topia.test.entities.Race" reverseAttributeName="" associationType="composite" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/> + </class> + <class name="Race" package="org.nuiton.topia.test.entities"> + <stereotype name="entity"/> + <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/> + <attribute visibility="public" type="org.nuiton.topia.test.entities.Pet" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="false" ordering="unordered"/> + </class> + <class name="Set<Contact2>" package="java.util"/> +</objectModel> Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/resources/log4j.properties =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/resources/log4j.properties (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/main/resources/log4j.properties 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,12 @@ +# Global logging configuration +log4j.rootLogger=ERROR, stdout + +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n + +# package level +log4j.logger.org.nuiton.eugene=DEBUG +log4j.logger.org.nuiton.eugene.test=DEBUG +log4j.logger.org.nuiton.processor=DEBUG Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,91 @@ +/* + * *##% + * EUGene Test + * Copyright (C) 2007 - 2009 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>. + * ##%* + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.nuiton.eugene.test.generator; + +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import org.nuiton.eugene.models.object.ObjectModel; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelOperation; + +/** + * + * @author fdesbois + */ +public class TestBuilderTest { + + private static final Log log = LogFactory.getLog(TestBuilderTest.class); + + public TestBuilderTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of build method, of class TestBuilder. + */ + @Test + public void testBuild() { + System.out.println("build"); + TestBuilder instance = new TestBuilder(); + + instance.build(); + + ObjectModel result = instance.getModel(); + assertNotNull(result); + assertEquals(result.getClasses().size(), 2); + ObjectModelClass clazz = result.getClass("org.chorem.bonzoms.Person"); + assertNotNull(clazz); + assertEquals(clazz.getAttributes().size(), 3); + assertEquals(clazz.getOperations().size(), 2); + List<ObjectModelOperation> operations = (List<ObjectModelOperation>)clazz.getOperations(); + ObjectModelOperation operation = operations.get(0); + log.debug("Body code [" + operation.getName() + "] : " + operation.getBodyCode()); + assertFalse(operation.getBodyCode().isEmpty()); + } + +} \ No newline at end of file Property changes on: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/resources/log4j.properties =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/resources/log4j.properties (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/src/test/resources/log4j.properties 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,12 @@ +# Global logging configuration +log4j.rootLogger=ERROR, stdout + +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n + +# package level +log4j.logger.org.nuiton.eugene=DEBUG +log4j.logger.org.nuiton.eugene.test=DEBUG +log4j.logger.org.nuiton.processor=DEBUG Added: branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/verify.groovy =================================================================== --- branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/verify.groovy (rev 0) +++ branches/eugene-2.0/maven-eugene-plugin/src/it/generate/generators/verify.groovy 2009-12-14 01:57:24 UTC (rev 749) @@ -0,0 +1,5 @@ + +//TODO + +return true; + Modified: branches/eugene-2.0/pom.xml =================================================================== --- branches/eugene-2.0/pom.xml 2009-12-13 22:07:38 UTC (rev 748) +++ branches/eugene-2.0/pom.xml 2009-12-14 01:57:24 UTC (rev 749) @@ -19,7 +19,6 @@ <modules> <module>eugene</module> <module>maven-eugene-plugin</module> - <module>eugene-test</module> </modules> <dependencyManagement>