From tchemit@users.nuiton.org Wed Nov 24 15:22:43 2010
From: tchemit@users.nuiton.org
To: wikitty-commits@list.nuiton.org
Subject: [Wikitty-commits] r509 - in trunk: . wikitty-api wikitty-dto
	wikitty-dto/src/main/java/org/nuiton/wikitty/generator
	wikitty-generators/src/main/java/org/nuiton/wikitty/generator
Date: Wed, 24 Nov 2010 15:22:43 +0100
Message-ID: <20101124142243.8CF0E15C73@nuiton.codelutin.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============5264618842725374854=="

--===============5264618842725374854==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Author: tchemit
Date: 2010-11-24 15:22:43 +0100 (Wed, 24 Nov 2010)
New Revision: 509

Url: http://nuiton.org/repositories/revision/wikitty/509

Log:
move DTO generator + fix poms

Added:
   trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/Wikitt=
yDTOGenerator.java
Removed:
   trunk/wikitty-dto/src/main/java/org/nuiton/wikitty/generator/WikittyDTOGen=
erator.java
Modified:
   trunk/pom.xml
   trunk/wikitty-api/pom.xml
   trunk/wikitty-dto/pom.xml

Modified: trunk/pom.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/pom.xml	2010-11-24 13:39:47 UTC (rev 508)
+++ trunk/pom.xml	2010-11-24 14:22:43 UTC (rev 509)
@@ -191,7 +191,7 @@
       <dependency>
         <groupId>org.nuiton.i18n</groupId>
         <artifactId>nuiton-i18n</artifactId>
-        <version>1.2.2</version>
+        <version>${nuitonI18nVersion}</version>
         <scope>compile</scope>
       </dependency>
=20
@@ -522,6 +522,9 @@
     <!-- common versions used in sub-poms -->
     <eugeneVersion>2.2.1-SNAPSHOT</eugeneVersion>
     <nuitonUtilsVersion>1.5.2-SNAPSHOT</nuitonUtilsVersion>
+    <nuitonI18nVersion>2.0</nuitonI18nVersion>
+    <processPluginVersion>1.0.3</processPluginVersion>
+
     <springVersion>3.0.1.RELEASE</springVersion>
     <jettyMorbayVersion>6.1.22</jettyMorbayVersion>
=20
@@ -558,8 +561,15 @@
         <plugin>
           <groupId>org.nuiton.processor</groupId>
           <artifactId>maven-processor-plugin</artifactId>
-          <version>1.0.3</version>
+          <version>${processPluginVersion}</version>
         </plugin>
+
+        <!-- eugene plugin -->
+        <plugin>
+          <groupId>org.nuiton.eugene</groupId>
+          <artifactId>maven-eugene-plugin</artifactId>
+          <version>${eugeneVersion}</version>
+        </plugin>
       </plugins>
     </pluginManagement>
   </build>

Modified: trunk/wikitty-api/pom.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/wikitty-api/pom.xml	2010-11-24 13:39:47 UTC (rev 508)
+++ trunk/wikitty-api/pom.xml	2010-11-24 14:22:43 UTC (rev 509)
@@ -155,7 +155,6 @@
         <plugin>
           <groupId>org.nuiton.eugene</groupId>
           <artifactId>maven-eugene-plugin</artifactId>
-          <version>${eugeneVersion}</version>
           <dependencies>
             <dependency>
               <groupId>org.nuiton.wikitty</groupId>

Modified: trunk/wikitty-dto/pom.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/wikitty-dto/pom.xml	2010-11-24 13:39:47 UTC (rev 508)
+++ trunk/wikitty-dto/pom.xml	2010-11-24 14:22:43 UTC (rev 509)
@@ -3,156 +3,165 @@
          xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation=3D"http://maven.apache.org/POM/4.0.0 http://mave=
n.apache.org/xsd/maven-4.0.0.xsd">
=20
-    <modelVersion>4.0.0</modelVersion>
+  <modelVersion>4.0.0</modelVersion>
=20
-    <parent>
-        <groupId>org.nuiton</groupId>
-        <artifactId>wikitty</artifactId>
-        <version>3.0-SNAPSHOT</version>
-    </parent>
+  <parent>
+    <groupId>org.nuiton</groupId>
+    <artifactId>wikitty</artifactId>
+    <version>3.0-SNAPSHOT</version>
+  </parent>
=20
-    <!-- ************************************************************* -->
-    <!-- *** POM Relationships *************************************** -->
-    <!-- ************************************************************* -->
-    <groupId>org.nuiton.wikitty</groupId>
-    <artifactId>wikitty-dto</artifactId>
+  <!-- ************************************************************* -->
+  <!-- *** POM Relationships *************************************** -->
+  <!-- ************************************************************* -->
+  <groupId>org.nuiton.wikitty</groupId>
+  <artifactId>wikitty-dto</artifactId>
=20
-    <dependencies>
+  <dependencies>
=20
-        <!-- sibling dependencies -->
+    <!-- sibling dependencies -->
=20
-        <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>wikitty-generators</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>wikitty-api</artifactId>
-            <version>${project.version}</version>
-        </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>wikitty-generators</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>wikitty-api</artifactId>
+      <version>${project.version}</version>
+    </dependency>
=20
-        <dependency>
-            <groupId>org.nuiton.eugene</groupId>
-            <artifactId>eugene</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>commons-logging</groupId>
-            <artifactId>commons-logging</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>commons-lang</groupId>
-            <artifactId>commons-lang</artifactId>
-        </dependency>
+    <dependency>
+      <groupId>org.nuiton.eugene</groupId>
+      <artifactId>eugene</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
=20
-        <dependency>
-            <groupId>org.nuiton</groupId>
-            <artifactId>nuiton-utils</artifactId>
-        </dependency>
+    <dependency>
+      <groupId>org.nuiton</groupId>
+      <artifactId>nuiton-utils</artifactId>
+    </dependency>
=20
-        <dependency>
-            <groupId>commons-beanutils</groupId>
-            <artifactId>commons-beanutils</artifactId>
-        </dependency>
+    <dependency>
+      <groupId>commons-beanutils</groupId>
+      <artifactId>commons-beanutils</artifactId>
+    </dependency>
=20
-       =20
-        <!-- TEST -->
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-        </dependency>
=20
-    </dependencies>
+    <!-- TEST -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
=20
-    <!-- ************************************************************* -->
-    <!-- *** Project Information ************************************* -->
-    <!-- ************************************************************* -->
+  </dependencies>
=20
-    <name>Wikitty :: dto</name>
+  <!-- ************************************************************* -->
+  <!-- *** Project Information ************************************* -->
+  <!-- ************************************************************* -->
=20
-    <description>Provide DTOs for Wikitty</description>
-    <inceptionYear>2010</inceptionYear>
+  <name>Wikitty :: dto</name>
=20
-    <!-- ************************************************************* -->
-    <!-- *** Build Settings ****************************************** -->
-    <!-- ************************************************************* -->
+  <description>Provide DTOs for Wikitty</description>
+  <inceptionYear>2010</inceptionYear>
=20
-    <packaging>jar</packaging>
-    <properties>
-       =20
-        <!-- extra files to include in release -->
-        <redmine.releaseFiles>
-            target/${project.build.finalName}.${project.packaging}
-        </redmine.releaseFiles>
-    </properties>
+  <!-- ************************************************************* -->
+  <!-- *** Build Settings ****************************************** -->
+  <!-- ************************************************************* -->
=20
-    <build>
+  <properties>
=20
-        <plugins>
-            <!-- processor plugin -->
-            <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>
+    <!-- extra files to include in release -->
+    <redmine.releaseFiles>
+      target/${project.build.finalName}.${project.packaging}
+    </redmine.releaseFiles>
+  </properties>
=20
-            <plugin>
-                <groupId>org.nuiton.eugene</groupId>
-                <artifactId>maven-eugene-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>api-dto-generation</id>
-                        <phase>generate-test-sources</phase>
-                        <configuration>
-                            <testPhase>true</testPhase>
-                            <inputs>
-                                <input>classpath:model:/:wikitty.objectmodel=
</input>
-                            </inputs>
-                            <fullPackagePath>org.nuiton.wikitty.entities
-                            </fullPackagePath>
-                            <defaultPackage>org.nuiton.wikitty.entities
-                            </defaultPackage>
-                            <extractedPackages>org.nuiton.wikitty.entities
-                            </extractedPackages>
-                            <templates>
-                                org.nuiton.wikitty.generator.WikittyDTOGener=
ator
-                            </templates>
-                        </configuration>
-                        <goals>
-                            <goal>smart-generate</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
+  <build>
=20
-            <!-- expose new plexus components -->
-            <plugin>
-                <groupId>org.codehaus.plexus</groupId>
-                <artifactId>plexus-component-metadata</artifactId>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>generate-metadata</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
+    <plugins>
+      <!-- processor plugin -->
+      <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>
=20
-    </build>
+      <plugin>
+        <groupId>org.nuiton.eugene</groupId>
+        <artifactId>maven-eugene-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>api-dto-generation</id>
+            <phase>generate-test-sources</phase>
+            <configuration>
+              <testPhase>true</testPhase>
+              <inputs>
+                <input>classpath:model:/:wikitty.objectmodel</input>
+              </inputs>
+              <fullPackagePath>
+                org.nuiton.wikitty.entities
+              </fullPackagePath>
+              <defaultPackage>
+                org.nuiton.wikitty.entities
+              </defaultPackage>
+              <extractedPackages>
+                org.nuiton.wikitty.entities
+              </extractedPackages>
+              <templates>
+                org.nuiton.wikitty.generator.WikittyDTOGenerator
+              </templates>
+            </configuration>
+            <goals>
+              <goal>smart-generate</goal>
+            </goals>
+          </execution>
+        </executions>
+        <!--dependencies>
+            <dependency>
+              <groupId>org.nuiton.wikitty</groupId>
+              <artifactId>wikitty-dto</artifactId>
+              <version>${project.version}</version>
+            </dependency>
+          </dependencies-->
+      </plugin>
=20
+      <!-- expose new plexus components -->
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-component-metadata</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>generate-metadata</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+
+  </build>
+
 </project>

Deleted: trunk/wikitty-dto/src/main/java/org/nuiton/wikitty/generator/Wikitty=
DTOGenerator.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/wikitty-dto/src/main/java/org/nuiton/wikitty/generator/WikittyDTOGe=
nerator.java	2010-11-24 13:39:47 UTC (rev 508)
+++ trunk/wikitty-dto/src/main/java/org/nuiton/wikitty/generator/WikittyDTOGe=
nerator.java	2010-11-24 14:22:43 UTC (rev 509)
@@ -1,562 +0,0 @@
-/*
- * #%L
- * Wikitty :: dto
- *=20
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2010 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=20
- * published by the Free Software Foundation, either version 3 of the=20
- * License, or (at your option) any later version.
- *=20
- * 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.
- *=20
- * You should have received a copy of the GNU General Lesser Public=20
- * License along with this program.  If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.wikitty.generator;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.Transformer;
-import org.nuiton.eugene.java.ObjectModelTransformerToJava;
-import org.nuiton.eugene.models.object.ObjectModel;
-import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelModifier;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-import org.nuiton.eugene.models.object.ObjectModelParameter;
-
-
-/*{generator option: writeString =3D }*/
-/*{generator option: parentheses =3D false}*/
-/*{generator option: writeString =3D +}*/
-
-/**
- * @plexus.component role=3D"org.nuiton.eugene.Template" role-hint=3D"org.nu=
iton.wikitty.generator.WikittyDTOGenerator"
- */
-public class WikittyDTOGenerator extends ObjectModelTransformerToJava {
-
-    private static final Log log =3D LogFactory.getLog(WikittyDTOGenerator.c=
lass);
-
-    /**
-     * map busines entity from source model to generated abstract class
-     */
-    protected Map<ObjectModelClass, ObjectModelClass> processedClasses =3D
-            new HashMap<ObjectModelClass, ObjectModelClass>();
-
-    /**
-     * pattern to parse toString tagValue
-     * for the string "abc{foo|bar}defrzeg{uvw|xyz}oeira"
-     * will match {foo|bar} and {uvw|xyz} with groups for foo, bar, uvw and =
xyz
-     */
-    protected Pattern toStringTagValuePattern =3D Pattern.compile("\\{(([^|}=
])*)(?:\\|([^}]*))?\\}");
-
-    /**
-     * map "Client.name" to "getName()" or any getter to read this attribute
-     * those getter names are stored while generating in order to be found
-     * later when generating toString()
-     */
-    protected Map<String, String> attributeToGetterName =3D new HashMap<Stri=
ng, String>();
-
-    @Override
-    protected Transformer<ObjectModel, ObjectModel> initPreviousTransformer(=
) {
-        return new WikittyPurifierTransformer();
-    }
-
-    protected List<ObjectModelClass> entitiesWithInheritedOperations =3D
-            new ArrayList<ObjectModelClass>();
-
-    @Override
-    public void transformFromModel(ObjectModel model) {
-
-        // contains boths businessEntities and metaExtensions
-        // elements may have one of the two sterotypes or both
-        // but elements with none of them aren't in this list
-        List<ObjectModelClass> modelBoth =3D new ArrayList<ObjectModelClass>=
();
-
-        // fill modelBusinessEntities with entities found in model
-        for (ObjectModelClass clazz : model.getClasses()) {
-            if (WikittyTransformerUtil.isBusinessEntity(clazz) ||
-                    WikittyTransformerUtil.isMetaExtension(clazz)) {
-                modelBoth.add(clazz);
-            }
-        }
-
-        for (ObjectModelClass clazz : modelBoth) {
-            ObjectModelClass abstractClass =3D createClass(
-                    businessEntityToDTOName(clazz),
-                    clazz.getPackageName());
-            processedClasses.put(clazz, abstractClass);
-            addInterface(abstractClass, clazz.getQualifiedName());
-        }
-
-        for (ObjectModelClass clazz : modelBoth) {
-            if (WikittyTransformerUtil.isMetaExtension(clazz)) {
-                addMetaExtensionOperations(clazz, processedClasses.get(clazz=
));
-            } else if (WikittyTransformerUtil.isBusinessEntity(clazz)) {
-                addOperations(clazz, processedClasses.get(clazz));
-            }
-        }
-
-        // at this time, all operations in generated abstracts are just the =
operations
-        // like get/set etc. we will copy all operations of a given class to=
 all children
-        // that's why constructors and others operations are not yet added
-        for (ObjectModelClass clazz : modelBoth) {
-            if (WikittyTransformerUtil.isBusinessEntity(clazz)) {
-                addInheritedOperations(clazz, processedClasses.get(clazz));
-            }
-        }
-
-        for (ObjectModelClass clazz : modelBoth) {
-            ObjectModelClass abstractClassForThisEntity =3D processedClasses=
.get(clazz);
-            addConstructors(abstractClassForThisEntity);
-            addToString(clazz, abstractClassForThisEntity);
-            addBusinessEntityMethods(abstractClassForThisEntity);
-            addModelOperations(clazz, abstractClassForThisEntity);
-        }
-
-        processedClasses.clear();
-    }
-
-    protected void addSerialVersionUID(ObjectModelClass clazz) {
-        // adding a generated serialVersionUID
-        Random random =3D new Random();
-        Long serialVersionUIDs =3D random.nextLong();
-        addConstant(clazz,
-                "serialVersionUID",
-                "long",
-                serialVersionUIDs.toString() + "L",
-                ObjectModelModifier.PRIVATE);
-    }
-
-    protected void addConstructors(ObjectModelClass clazz) {
-
-        ObjectModelOperation constructor =3D addConstructor(clazz, ObjectMod=
elModifier.PUBLIC);
-        setOperationBody(constructor, ""
-/*{
-}*/);
-
-        constructor =3D addConstructor(clazz, ObjectModelModifier.PUBLIC);
-        addParameter(constructor, WikittyTransformerUtil.WIKITTY_CLASS_FQN, =
"wikitty");
-        setOperationBody(constructor, ""
-/*{
-        wikittyId=3Dwikitty.getId();
-}*/);
-
-        constructor =3D addConstructor(clazz, ObjectModelModifier.PUBLIC);
-        addParameter(constructor, "String", "wikittyId");
-        setOperationBody(constructor, ""
-/*{
-        this.wikittyId=3DwikittyId;
-}*/);
-
-    }
-
-    protected void addOperations(ObjectModelClass businessEntity, ObjectMode=
lClass abstractClass) {
-        // generating operations with bodies to realize contract
-        for (ObjectModelAttribute attribute : businessEntity.getAttributes()=
) {
-            if (attribute.isNavigable()) {
-                // needed below, in templates
-                String attributeType =3D WikittyTransformerUtil.generateResu=
ltType(attribute, false);
-                String attributeName =3D attribute.getName();
-
-                //add necessary import
-                addImport(abstractClass, attribute.getType());
-
-                //If alternative name, use it
-                if (attribute.hasTagValue(WikittyTransformerUtil.TAG_ALTERNA=
TIVE_NAME)) {
-                    attributeName =3D attribute.getTagValue(WikittyTransform=
erUtil.TAG_ALTERNATIVE_NAME);
-                }
-
-                String getterName;
-
-                if (WikittyTransformerUtil.isAttributeCollection(attribute))=
 {
-                    // attribute is a collection, we will generate operations
-                    // get, add, remove and clear
-                    String collectionType =3D WikittyTransformerUtil.getColl=
ectionTypeName(attribute);
-                    if (collectionType.equals("Set")){
-                        addImport(abstractClass, java.util.Set.class);
-                    }
-                    if (collectionType.equals("List")){
-                        addImport(abstractClass, java.util.List.class);
-
-                    }
-
-                    String attributeTypeInSet =3D WikittyTransformerUtil.gen=
erateResultType(attribute, true);
-
-                    //adding the attribute
-                    ObjectModelAttribute modelAttribute =3D addAttribute(abs=
tractClass, attributeName, attributeTypeInSet);
-                    String annotation =3D "WikittyField(fqn=3D\""+ businessE=
ntity.getName() + "." + attributeName +"\")";
-                    addAnnotation(abstractClass, modelAttribute, annotation);
-                    addImport(abstractClass, org.nuiton.wikitty.entities.Wik=
ittyField.class);
-
-
-                    // adding the getter
-                    getterName =3D "get" + StringUtils.capitalize(attributeN=
ame);
-                    ObjectModelOperation getter =3D addOperation(abstractCla=
ss, getterName, attributeTypeInSet);
-                    addAnnotation(abstractClass, getter, "Override");
-                    String getterBody =3D ""
-/*{
-        return <%=3DattributeName%>;
-}*/;
-                    setOperationBody(getter, getterBody);
-
-                    // adding the setter
-                    getterName =3D "set" + StringUtils.capitalize(attributeN=
ame);
-                    ObjectModelOperation setter =3D addOperation(abstractCla=
ss, getterName, "void");
-                    addAnnotation(abstractClass, setter, "Override");
-                    addParameter(setter, attributeTypeInSet, attributeName);
-                    String setterBody =3D ""
-/*{
-        this.<%=3DattributeName%>=3D<%=3DattributeName%>;
-}*/;
-                    setOperationBody(setter, setterBody);
-
-                    //adding the add method
-                    String addName =3D "add" + StringUtils.capitalize(attrib=
uteName);
-                    ObjectModelOperation adder =3D addOperation(abstractClas=
s, addName, "void");
-                    addAnnotation(abstractClass, adder, "Override");
-                    addParameter(adder, attributeType, "element");
-                    String adderBody =3D ""
-/*{
-        <%=3DattributeName%>.add(element);
-}*/;
-                    setOperationBody(adder, adderBody);
-
-                    //adding the remove method
-                    String removeName =3D "remove" + StringUtils.capitalize(=
attributeName);
-                    ObjectModelOperation remover =3D addOperation(abstractCl=
ass, removeName, "void");
-                    addAnnotation(abstractClass, remover, "Override");
-                    addParameter(remover, attributeType, "element");
-                    String removerBody =3D ""
-/*{
-        <%=3DattributeName%>.remove(element);
-}*/;
-                    setOperationBody(remover, removerBody);
-
-                    //adding the clear method
-                    String clearName =3D "clear" + StringUtils.capitalize(at=
tributeName);
-                    ObjectModelOperation clear =3D addOperation(abstractClas=
s, clearName, "void");
-                    addAnnotation(abstractClass, clear, "Override");
-                    String clearBody =3D ""
-/*{
-        <%=3DattributeName%>.clear();
-}*/;
-                    setOperationBody(clear, clearBody);
-
-                } else {
-                    //No multiplicity
-
-                    //add necessary import
-                    addImport(abstractClass, attribute.getType());
-
-                    //adding the attribute
-                    ObjectModelAttribute modelAttribute =3D addAttribute(abs=
tractClass, attributeName, attributeType);
-                    String annotation =3D "WikittyField(fqn=3D\"" + business=
Entity.getName() + "."+attributeName + "\")";
-                    addAnnotation(abstractClass, modelAttribute, annotation);
-                    addImport(abstractClass, org.nuiton.wikitty.entities.Wik=
ittyField.class);
-
-                    // adding getter
-                    getterName =3D "get" + StringUtils.capitalize(attributeN=
ame);
-                    ObjectModelOperation getter =3D addOperation(abstractCla=
ss, getterName, attributeType);
-                    addAnnotation(abstractClass, getter, "Override");
-                    setOperationBody(getter, ""
-/*{
-        return <%=3DattributeName%>;
-}*/);
-
-                    //adding setter
-                    String setterName =3D "set" + StringUtils.capitalize(att=
ributeName);
-                    ObjectModelOperation setter =3D addOperation(abstractCla=
ss, setterName, "void");
-                    addAnnotation(abstractClass, setter, "Override");
-                    addParameter(setter, attributeType, attributeName);
-                    setOperationBody(setter, ""
-/*{
-        this.<%=3DattributeName%>=3D<%=3DattributeName%>;
-}*/);
-                }
-
-                // save the getter name for this attribute
-                attributeToGetterName.put(businessEntity.getName() + "." + a=
ttributeName, getterName);
-            }
-        }
-    }
-
-    /**
-     * Add inherited operations to the abstract generated from an entity.
-     * Method browse superClasses to copy methods and their bodies. The meth=
od
-     * deal with imports, cause bodies call the Helper of the classe where
-     * the attribute was declared.
-     * <p/>
-     * If A inherit from B and B inherit from and A, B, C not in the same pa=
ckage
-     * we B need to import CHelper and A need to import BHelper. But, since A
-     * has C attributes too, it needs CHelper too. So when we will process B,
-     * we will save needed imports, A will get them thus import CHelper.
-     */
-    protected void addInheritedOperations(ObjectModelClass businessEntity, O=
bjectModelClass abstractClass) {
-
-        if (!entitiesWithInheritedOperations.contains(businessEntity)) {
-
-            // add attributes and methods inherited from super classes
-            for (ObjectModelClass superClass : businessEntity.getSuperclasse=
s()) {
-
-                // process super classes first, so we will get inherited ope=
rations from superclass
-                addInheritedOperations(superClass, processedClasses.get(supe=
rClass));
-
-                if (WikittyTransformerUtil.isBusinessEntity(superClass)) {
-
-                    //Add operations for the super class
-                    addOperations(superClass, abstractClass);
-                }
-            }
-
-            entitiesWithInheritedOperations.add(businessEntity);
-        }
-    }
-
-    /**
-     * add a toString method
-     * if a toString tagValue is attached to businessEntity, it will be used
-     * to generate a toString as this :
-     * <p/>
-     * given "hello {Person.name|unknow}"
-     * <p/>
-     * will try to replace first {...} by name field value for extension Per=
son.
-     * if this information is not available, will do unknow.
-     */
-    protected void addToString(ObjectModelClass businessEntity, ObjectModelC=
lass abstractClass) {
-
-        String toStringOperationBody;
-
-        if (businessEntity.hasTagValue(WikittyTransformerUtil.TAG_TO_STRING)=
) {
-            String toStringPattern =3D businessEntity.getTagValue(WikittyTra=
nsformerUtil.TAG_TO_STRING);
-
-            // toStringPattern is something like
-            // "hello {Person.name|unknow} employe of {Company.name|unknow}"
-            //
-
-            Matcher matcher =3D toStringTagValuePattern.matcher(toStringPatt=
ern);
-
-            while (matcher.find()) {
-                String wholeMatch =3D matcher.group(0); // "{foo|bar}"
-                String variableName =3D matcher.group(1); // "foo"
-                String defaultValue =3D matcher.group(3); // "bar", may be n=
ull
-
-                if (defaultValue =3D=3D null) {
-                    defaultValue =3D "";
-                }
-
-                if (attributeToGetterName.containsKey(variableName)) {
-                    String getterName =3D attributeToGetterName.get(variable=
Name);
-                    toStringPattern =3D toStringPattern.replace(wholeMatch, =
""
-/*{"
-             + <%=3DgetterName%>().toString() +
-             "}*/);
-                } else {
-                    log.warn("no field " + variableName + " in " + businessE=
ntity.getQualifiedName());
-                    toStringPattern =3D toStringPattern.replace(wholeMatch, =
defaultValue);
-                }
-            }
-
-            toStringOperationBody =3D ""
-/*{
-        return "<%=3DtoStringPattern%>";
-}*/;
-        } else {
-            // no toString tagValue provided, generating a default toString
-            toStringOperationBody =3D ""
-/*{
-        return "dto:"+getWikittyId()+":"+getWikittyVersion();
-}*/;
-        }
-
-        ObjectModelOperation toString =3D addOperation(abstractClass, "toStr=
ing", "String");
-        addAnnotation(abstractClass, toString, "Override");
-        setOperationBody(toString, toStringOperationBody);
-    }
-
-    protected void addMetaExtensionOperations(ObjectModelClass metaExtension,
-                                              ObjectModelClass abstractClass=
ForThisMetaExtension) {
-
-        //add standard attribute operations for meta-extension
-        addOperations(metaExtension, abstractClassForThisMetaExtension);
-
-    }
-
-    /**
-     * Method to get the generated class name
-     */
-    protected String businessEntityToDTOName(ObjectModelClass clazz) {
-        return clazz.getName() + "DTO";
-    }
-
-    protected void addBusinessEntityMethods(ObjectModelClass dtoClass) {
-
-        //adding wikittyId attribute
-        addAttribute(dtoClass, "wikittyId", "String");
-
-        //adding getWikittyId method
-        ObjectModelOperation getter =3D addOperation(dtoClass, "getWikittyId=
", "String");
-        addAnnotation(dtoClass, getter, "Override");
-        setOperationBody(getter, ""
-/*{
-        return wikittyId;
-}*/);
-
-        //adding setWikittyId method
-        ObjectModelOperation setter =3D addOperation(dtoClass, "setWikittyId=
", "void");
-        addParameter(setter, "String", "wikittyId");
-        setOperationBody(setter, ""
-/*{
-        this.wikittyId=3DwikittyId;
-}*/);
-
-        //adding wikittyVersion attribute
-        addAttribute(dtoClass, "wikittyVersion", "String");
-
-
-
-        //adding getWikittyVersion method
-        ObjectModelOperation getWikittyVersion =3D addOperation(dtoClass,
-                "getWikittyVersion", "String");
-        addAnnotation(dtoClass, getWikittyVersion, "Override");
-        setOperationBody(getWikittyVersion, ""
-/*{
-        return wikittyVersion;
-}*/);
-
-        //adding setWikittyVersion method
-        ObjectModelOperation setWikittyVersion =3D addOperation(dtoClass,
-                "setWikittyVersion", "void");
-        addParameter(setWikittyVersion, "String", "wikittyVersion");
-        setOperationBody(setWikittyVersion, ""
-/*{
-        this.wikittyVersion=3DwikittyVersion;
-}*/);
-
-        //adding necessary imports
-        addImport(dtoClass, java.beans.PropertyChangeListener.class);
-        addImport(dtoClass, java.util.Collection.class);
-
-        // adding addPropertyChangeListener
-        ObjectModelOperation addPropertyChangeListener =3D addOperation(dtoC=
lass,
-                "addPropertyChangeListener", "void");
-        addAnnotation(dtoClass, addPropertyChangeListener, "Override");
-        addParameter(addPropertyChangeListener, "PropertyChangeListener", "l=
istener");
-        setOperationBody(addPropertyChangeListener, ""
-/*{
-        throw new UnsupportedOperationException("Not supported yet.");
-}*/);
-
-        // adding removePropertyChangeListener
-        ObjectModelOperation removePropertyChangeListener =3D addOperation(d=
toClass,
-                "removePropertyChangeListener", "void");
-        addAnnotation(dtoClass, removePropertyChangeListener, "Override");
-        addParameter(removePropertyChangeListener, "PropertyChangeListener",=
 "listener");
-        setOperationBody(removePropertyChangeListener, ""
-/*{
-        throw new UnsupportedOperationException("Not supported yet.");
-}*/);
-
-        // adding addPropertyChangeListener 2 parameters
-        ObjectModelOperation addPropertyChangeListener2 =3D addOperation(dto=
Class,
-                "addPropertyChangeListener", "void");
-        addAnnotation(dtoClass, addPropertyChangeListener2, "Override");
-        addParameter(addPropertyChangeListener2, "String", "property");
-        addParameter(addPropertyChangeListener2, "PropertyChangeListener", "=
listener");
-        setOperationBody(addPropertyChangeListener2, ""
-/*{
-        throw new UnsupportedOperationException("Not supported yet.");
-}*/);
-
-        // adding removePropertyChangeListener 2 parameters
-        ObjectModelOperation removePropertyChangeListener2 =3D addOperation(=
dtoClass,
-                "removePropertyChangeListener", "void");
-        addAnnotation(dtoClass, removePropertyChangeListener2, "Override");
-        addParameter(removePropertyChangeListener2, "String", "property");
-        addParameter(removePropertyChangeListener2, "PropertyChangeListener"=
, "listener");
-        setOperationBody(removePropertyChangeListener2, ""
-/*{
-        throw new UnsupportedOperationException("Not supported yet.");
-}*/);
-
-        //adding getExtensionFields method
-        ObjectModelOperation getExtensionFields =3D addOperation(dtoClass,
-                "getExtensionFields", "Collection<String>");
-        addAnnotation(dtoClass, getExtensionFields, "Override");
-        addParameter(getExtensionFields, "String", "ext");
-        setOperationBody(getExtensionFields, ""
-/*{
-        throw new UnsupportedOperationException("Not supported yet.");
-}*/);
-
-        //adding getExtensionNames method
-        ObjectModelOperation getExtensionNames =3D addOperation(dtoClass,
-                "getExtensionNames", "Collection<String>");
-        addAnnotation(dtoClass, getExtensionNames, "Override");
-        setOperationBody(getExtensionNames, ""
-/*{
-        throw new UnsupportedOperationException("Not supported yet.");
-}*/);
-
-        //adding getField method
-        ObjectModelOperation getField =3D addOperation(dtoClass, "getField",=
 "Object");
-        addAnnotation(dtoClass, getField, "Override");
-        addParameter(getField, "String", "ext");
-        addParameter(getField, "String", "fieldName");
-        setOperationBody(getField, ""
-/*{
-        throw new UnsupportedOperationException("Not supported yet.");
-}*/);
-
-        //adding setField method
-        ObjectModelOperation setField =3D addOperation(dtoClass, "setField",=
 "void");
-        addAnnotation(dtoClass, setField, "Override");
-        addParameter(setField, "String", "ext");
-        addParameter(setField, "String", "fieldName");
-        addParameter(setField, "Object", "value");
-        setOperationBody(setField, ""
-/*{
-        throw new UnsupportedOperationException("Not supported yet.");
-}*/);
-
-    }
-
-    protected void addModelOperations(ObjectModelClass businessEntity, Objec=
tModelClass dtoClass){
-        Collection<ObjectModelOperation> operations =3D businessEntity.getOp=
erations();
-
-        for (ObjectModelOperation operation:operations){
-            ObjectModelOperation dtoOperation =3D addOperation(dtoClass,
-                    operation.getName(), operation.getReturnType());
-
-            Collection<ObjectModelParameter> parameters =3D operation.getPar=
ameters();
-            for (ObjectModelParameter parameter:parameters){
-                addParameter(dtoOperation, parameter.getType(), parameter.ge=
tName());
-            }
-            addAnnotation(dtoClass, dtoOperation, "Override");
-            setOperationBody(dtoOperation, ""
-/*{
-        throw new UnsupportedOperationException("Not supported yet.");
-}*/);
-        }
-    }
-
-}

Copied: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/W=
ikittyDTOGenerator.java (from rev 506, trunk/wikitty-dto/src/main/java/org/nu=
iton/wikitty/generator/WikittyDTOGenerator.java)
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/Wikit=
tyDTOGenerator.java	                        (rev 0)
+++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/Wikit=
tyDTOGenerator.java	2010-11-24 14:22:43 UTC (rev 509)
@@ -0,0 +1,564 @@
+/*
+ * #%L
+ * Wikitty :: dto
+ *=20
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2010 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=20
+ * published by the Free Software Foundation, either version 3 of the=20
+ * License, or (at your option) any later version.
+ *=20
+ * 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.
+ *=20
+ * You should have received a copy of the GNU General Lesser Public=20
+ * License along with this program.  If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.wikitty.generator;
+
+import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.Transformer;
+import org.nuiton.eugene.java.ObjectModelTransformerToJava;
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelModifier;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.eugene.models.object.ObjectModelParameter;
+
+
+/*{generator option: writeString =3D }*/
+/*{generator option: parentheses =3D false}*/
+/*{generator option: writeString =3D +}*/
+
+/**
+ * @plexus.component role=3D"org.nuiton.eugene.Template" role-hint=3D"org.nu=
iton.wikitty.generator.WikittyDTOGenerator"
+ */
+public class WikittyDTOGenerator extends ObjectModelTransformerToJava {
+
+    private static final Log log =3D LogFactory.getLog(WikittyDTOGenerator.c=
lass);
+
+    /**
+     * map busines entity from source model to generated abstract class
+     */
+    protected Map<ObjectModelClass, ObjectModelClass> processedClasses =3D
+            new HashMap<ObjectModelClass, ObjectModelClass>();
+
+    /**
+     * pattern to parse toString tagValue
+     * for the string "abc{foo|bar}defrzeg{uvw|xyz}oeira"
+     * will match {foo|bar} and {uvw|xyz} with groups for foo, bar, uvw and =
xyz
+     */
+    protected Pattern toStringTagValuePattern =3D Pattern.compile("\\{(([^|}=
])*)(?:\\|([^}]*))?\\}");
+
+    /**
+     * map "Client.name" to "getName()" or any getter to read this attribute
+     * those getter names are stored while generating in order to be found
+     * later when generating toString()
+     */
+    protected Map<String, String> attributeToGetterName =3D new HashMap<Stri=
ng, String>();
+
+    @Override
+    protected Transformer<ObjectModel, ObjectModel> initPreviousTransformer(=
) {
+        return new WikittyPurifierTransformer();
+    }
+
+    protected List<ObjectModelClass> entitiesWithInheritedOperations =3D
+            new ArrayList<ObjectModelClass>();
+
+    @Override
+    public void transformFromModel(ObjectModel model) {
+
+        // contains boths businessEntities and metaExtensions
+        // elements may have one of the two sterotypes or both
+        // but elements with none of them aren't in this list
+        List<ObjectModelClass> modelBoth =3D new ArrayList<ObjectModelClass>=
();
+
+        // fill modelBusinessEntities with entities found in model
+        for (ObjectModelClass clazz : model.getClasses()) {
+            if (WikittyTransformerUtil.isBusinessEntity(clazz) ||
+                    WikittyTransformerUtil.isMetaExtension(clazz)) {
+                modelBoth.add(clazz);
+            }
+        }
+
+        for (ObjectModelClass clazz : modelBoth) {
+            ObjectModelClass abstractClass =3D createClass(
+                    businessEntityToDTOName(clazz),
+                    clazz.getPackageName());
+            processedClasses.put(clazz, abstractClass);
+            addInterface(abstractClass, clazz.getQualifiedName());
+        }
+
+        for (ObjectModelClass clazz : modelBoth) {
+            if (WikittyTransformerUtil.isMetaExtension(clazz)) {
+                addMetaExtensionOperations(clazz, processedClasses.get(clazz=
));
+            } else if (WikittyTransformerUtil.isBusinessEntity(clazz)) {
+                addOperations(clazz, processedClasses.get(clazz));
+            }
+        }
+
+        // at this time, all operations in generated abstracts are just the =
operations
+        // like get/set etc. we will copy all operations of a given class to=
 all children
+        // that's why constructors and others operations are not yet added
+        for (ObjectModelClass clazz : modelBoth) {
+            if (WikittyTransformerUtil.isBusinessEntity(clazz)) {
+                addInheritedOperations(clazz, processedClasses.get(clazz));
+            }
+        }
+
+        for (ObjectModelClass clazz : modelBoth) {
+            ObjectModelClass abstractClassForThisEntity =3D processedClasses=
.get(clazz);
+            addConstructors(abstractClassForThisEntity);
+            addToString(clazz, abstractClassForThisEntity);
+            addBusinessEntityMethods(abstractClassForThisEntity);
+            addModelOperations(clazz, abstractClassForThisEntity);
+        }
+
+        processedClasses.clear();
+    }
+
+    protected void addSerialVersionUID(ObjectModelClass clazz) {
+        // adding a generated serialVersionUID
+        Random random =3D new Random();
+        Long serialVersionUIDs =3D random.nextLong();
+        addConstant(clazz,
+                "serialVersionUID",
+                "long",
+                serialVersionUIDs.toString() + "L",
+                ObjectModelModifier.PRIVATE);
+    }
+
+    protected void addConstructors(ObjectModelClass clazz) {
+
+        ObjectModelOperation constructor =3D addConstructor(clazz, ObjectMod=
elModifier.PUBLIC);
+        setOperationBody(constructor, ""
+/*{
+}*/);
+
+        constructor =3D addConstructor(clazz, ObjectModelModifier.PUBLIC);
+        addParameter(constructor, WikittyTransformerUtil.WIKITTY_CLASS_FQN, =
"wikitty");
+        setOperationBody(constructor, ""
+/*{
+        wikittyId=3Dwikitty.getId();
+}*/);
+
+        constructor =3D addConstructor(clazz, ObjectModelModifier.PUBLIC);
+        addParameter(constructor, "String", "wikittyId");
+        setOperationBody(constructor, ""
+/*{
+        this.wikittyId=3DwikittyId;
+}*/);
+
+    }
+
+    protected void addOperations(ObjectModelClass businessEntity, ObjectMode=
lClass abstractClass) {
+        // generating operations with bodies to realize contract
+        for (ObjectModelAttribute attribute : businessEntity.getAttributes()=
) {
+            if (attribute.isNavigable()) {
+                // needed below, in templates
+                String attributeType =3D WikittyTransformerUtil.generateResu=
ltType(attribute, false);
+                String attributeName =3D attribute.getName();
+
+                //add necessary import
+                addImport(abstractClass, attribute.getType());
+
+                //If alternative name, use it
+                if (attribute.hasTagValue(WikittyTransformerUtil.TAG_ALTERNA=
TIVE_NAME)) {
+                    attributeName =3D attribute.getTagValue(WikittyTransform=
erUtil.TAG_ALTERNATIVE_NAME);
+                }
+
+                String getterName;
+
+                if (WikittyTransformerUtil.isAttributeCollection(attribute))=
 {
+                    // attribute is a collection, we will generate operations
+                    // get, add, remove and clear
+                    String collectionType =3D WikittyTransformerUtil.getColl=
ectionTypeName(attribute);
+                    if (collectionType.equals("Set")){
+                        addImport(abstractClass, Set.class);
+                    }
+                    if (collectionType.equals("List")){
+                        addImport(abstractClass, List.class);
+
+                    }
+
+                    String attributeTypeInSet =3D WikittyTransformerUtil.gen=
erateResultType(attribute, true);
+
+                    //adding the attribute
+                    ObjectModelAttribute modelAttribute =3D addAttribute(abs=
tractClass, attributeName, attributeTypeInSet);
+                    String annotation =3D "WikittyField(fqn=3D\""+ businessE=
ntity.getName() + "." + attributeName +"\")";
+                    addAnnotation(abstractClass, modelAttribute, annotation);
+                    addImport(abstractClass, "org.nuiton.wikitty.entities.Wi=
kittyField");
+
+
+                    // adding the getter
+                    getterName =3D "get" + StringUtils.capitalize(attributeN=
ame);
+                    ObjectModelOperation getter =3D addOperation(abstractCla=
ss, getterName, attributeTypeInSet);
+                    addAnnotation(abstractClass, getter, "Override");
+                    String getterBody =3D ""
+/*{
+        return <%=3DattributeName%>;
+}*/;
+                    setOperationBody(getter, getterBody);
+
+                    // adding the setter
+                    getterName =3D "set" + StringUtils.capitalize(attributeN=
ame);
+                    ObjectModelOperation setter =3D addOperation(abstractCla=
ss, getterName, "void");
+                    addAnnotation(abstractClass, setter, "Override");
+                    addParameter(setter, attributeTypeInSet, attributeName);
+                    String setterBody =3D ""
+/*{
+        this.<%=3DattributeName%>=3D<%=3DattributeName%>;
+}*/;
+                    setOperationBody(setter, setterBody);
+
+                    //adding the add method
+                    String addName =3D "add" + StringUtils.capitalize(attrib=
uteName);
+                    ObjectModelOperation adder =3D addOperation(abstractClas=
s, addName, "void");
+                    addAnnotation(abstractClass, adder, "Override");
+                    addParameter(adder, attributeType, "element");
+                    String adderBody =3D ""
+/*{
+        <%=3DattributeName%>.add(element);
+}*/;
+                    setOperationBody(adder, adderBody);
+
+                    //adding the remove method
+                    String removeName =3D "remove" + StringUtils.capitalize(=
attributeName);
+                    ObjectModelOperation remover =3D addOperation(abstractCl=
ass, removeName, "void");
+                    addAnnotation(abstractClass, remover, "Override");
+                    addParameter(remover, attributeType, "element");
+                    String removerBody =3D ""
+/*{
+        <%=3DattributeName%>.remove(element);
+}*/;
+                    setOperationBody(remover, removerBody);
+
+                    //adding the clear method
+                    String clearName =3D "clear" + StringUtils.capitalize(at=
tributeName);
+                    ObjectModelOperation clear =3D addOperation(abstractClas=
s, clearName, "void");
+                    addAnnotation(abstractClass, clear, "Override");
+                    String clearBody =3D ""
+/*{
+        <%=3DattributeName%>.clear();
+}*/;
+                    setOperationBody(clear, clearBody);
+
+                } else {
+                    //No multiplicity
+
+                    //add necessary import
+                    addImport(abstractClass, attribute.getType());
+
+                    //adding the attribute
+                    ObjectModelAttribute modelAttribute =3D addAttribute(abs=
tractClass, attributeName, attributeType);
+                    String annotation =3D "WikittyField(fqn=3D\"" + business=
Entity.getName() + "."+attributeName + "\")";
+                    addAnnotation(abstractClass, modelAttribute, annotation);
+                    addImport(abstractClass, "org.nuiton.wikitty.entities.Wi=
kittyField");
+
+                    // adding getter
+                    getterName =3D "get" + StringUtils.capitalize(attributeN=
ame);
+                    ObjectModelOperation getter =3D addOperation(abstractCla=
ss, getterName, attributeType);
+                    addAnnotation(abstractClass, getter, "Override");
+                    setOperationBody(getter, ""
+/*{
+        return <%=3DattributeName%>;
+}*/);
+
+                    //adding setter
+                    String setterName =3D "set" + StringUtils.capitalize(att=
ributeName);
+                    ObjectModelOperation setter =3D addOperation(abstractCla=
ss, setterName, "void");
+                    addAnnotation(abstractClass, setter, "Override");
+                    addParameter(setter, attributeType, attributeName);
+                    setOperationBody(setter, ""
+/*{
+        this.<%=3DattributeName%>=3D<%=3DattributeName%>;
+}*/);
+                }
+
+                // save the getter name for this attribute
+                attributeToGetterName.put(businessEntity.getName() + "." + a=
ttributeName, getterName);
+            }
+        }
+    }
+
+    /**
+     * Add inherited operations to the abstract generated from an entity.
+     * Method browse superClasses to copy methods and their bodies. The meth=
od
+     * deal with imports, cause bodies call the Helper of the classe where
+     * the attribute was declared.
+     * <p/>
+     * If A inherit from B and B inherit from and A, B, C not in the same pa=
ckage
+     * we B need to import CHelper and A need to import BHelper. But, since A
+     * has C attributes too, it needs CHelper too. So when we will process B,
+     * we will save needed imports, A will get them thus import CHelper.
+     */
+    protected void addInheritedOperations(ObjectModelClass businessEntity, O=
bjectModelClass abstractClass) {
+
+        if (!entitiesWithInheritedOperations.contains(businessEntity)) {
+
+            // add attributes and methods inherited from super classes
+            for (ObjectModelClass superClass : businessEntity.getSuperclasse=
s()) {
+
+                // process super classes first, so we will get inherited ope=
rations from superclass
+                addInheritedOperations(superClass, processedClasses.get(supe=
rClass));
+
+                if (WikittyTransformerUtil.isBusinessEntity(superClass)) {
+
+                    //Add operations for the super class
+                    addOperations(superClass, abstractClass);
+                }
+            }
+
+            entitiesWithInheritedOperations.add(businessEntity);
+        }
+    }
+
+    /**
+     * add a toString method
+     * if a toString tagValue is attached to businessEntity, it will be used
+     * to generate a toString as this :
+     * <p/>
+     * given "hello {Person.name|unknow}"
+     * <p/>
+     * will try to replace first {...} by name field value for extension Per=
son.
+     * if this information is not available, will do unknow.
+     */
+    protected void addToString(ObjectModelClass businessEntity, ObjectModelC=
lass abstractClass) {
+
+        String toStringOperationBody;
+
+        if (businessEntity.hasTagValue(WikittyTransformerUtil.TAG_TO_STRING)=
) {
+            String toStringPattern =3D businessEntity.getTagValue(WikittyTra=
nsformerUtil.TAG_TO_STRING);
+
+            // toStringPattern is something like
+            // "hello {Person.name|unknow} employe of {Company.name|unknow}"
+            //
+
+            Matcher matcher =3D toStringTagValuePattern.matcher(toStringPatt=
ern);
+
+            while (matcher.find()) {
+                String wholeMatch =3D matcher.group(0); // "{foo|bar}"
+                String variableName =3D matcher.group(1); // "foo"
+                String defaultValue =3D matcher.group(3); // "bar", may be n=
ull
+
+                if (defaultValue =3D=3D null) {
+                    defaultValue =3D "";
+                }
+
+                if (attributeToGetterName.containsKey(variableName)) {
+                    String getterName =3D attributeToGetterName.get(variable=
Name);
+                    toStringPattern =3D toStringPattern.replace(wholeMatch, =
""
+/*{"
+             + <%=3DgetterName%>().toString() +
+             "}*/);
+                } else {
+                    log.warn("no field " + variableName + " in " + businessE=
ntity.getQualifiedName());
+                    toStringPattern =3D toStringPattern.replace(wholeMatch, =
defaultValue);
+                }
+            }
+
+            toStringOperationBody =3D ""
+/*{
+        return "<%=3DtoStringPattern%>";
+}*/;
+        } else {
+            // no toString tagValue provided, generating a default toString
+            toStringOperationBody =3D ""
+/*{
+        return "dto:"+getWikittyId()+":"+getWikittyVersion();
+}*/;
+        }
+
+        ObjectModelOperation toString =3D addOperation(abstractClass, "toStr=
ing", "String");
+        addAnnotation(abstractClass, toString, "Override");
+        setOperationBody(toString, toStringOperationBody);
+    }
+
+    protected void addMetaExtensionOperations(ObjectModelClass metaExtension,
+                                              ObjectModelClass abstractClass=
ForThisMetaExtension) {
+
+        //add standard attribute operations for meta-extension
+        addOperations(metaExtension, abstractClassForThisMetaExtension);
+
+    }
+
+    /**
+     * Method to get the generated class name
+     */
+    protected String businessEntityToDTOName(ObjectModelClass clazz) {
+        return clazz.getName() + "DTO";
+    }
+
+    protected void addBusinessEntityMethods(ObjectModelClass dtoClass) {
+
+        //adding wikittyId attribute
+        addAttribute(dtoClass, "wikittyId", "String");
+
+        //adding getWikittyId method
+        ObjectModelOperation getter =3D addOperation(dtoClass, "getWikittyId=
", "String");
+        addAnnotation(dtoClass, getter, "Override");
+        setOperationBody(getter, ""
+/*{
+        return wikittyId;
+}*/);
+
+        //adding setWikittyId method
+        ObjectModelOperation setter =3D addOperation(dtoClass, "setWikittyId=
", "void");
+        addParameter(setter, "String", "wikittyId");
+        setOperationBody(setter, ""
+/*{
+        this.wikittyId=3DwikittyId;
+}*/);
+
+        //adding wikittyVersion attribute
+        addAttribute(dtoClass, "wikittyVersion", "String");
+
+
+
+        //adding getWikittyVersion method
+        ObjectModelOperation getWikittyVersion =3D addOperation(dtoClass,
+                "getWikittyVersion", "String");
+        addAnnotation(dtoClass, getWikittyVersion, "Override");
+        setOperationBody(getWikittyVersion, ""
+/*{
+        return wikittyVersion;
+}*/);
+
+        //adding setWikittyVersion method
+        ObjectModelOperation setWikittyVersion =3D addOperation(dtoClass,
+                "setWikittyVersion", "void");
+        addParameter(setWikittyVersion, "String", "wikittyVersion");
+        setOperationBody(setWikittyVersion, ""
+/*{
+        this.wikittyVersion=3DwikittyVersion;
+}*/);
+
+        //adding necessary imports
+        addImport(dtoClass, PropertyChangeListener.class);
+        addImport(dtoClass, Collection.class);
+
+        // adding addPropertyChangeListener
+        ObjectModelOperation addPropertyChangeListener =3D addOperation(dtoC=
lass,
+                "addPropertyChangeListener", "void");
+        addAnnotation(dtoClass, addPropertyChangeListener, "Override");
+        addParameter(addPropertyChangeListener, "PropertyChangeListener", "l=
istener");
+        setOperationBody(addPropertyChangeListener, ""
+/*{
+        throw new UnsupportedOperationException("Not supported yet.");
+}*/);
+
+        // adding removePropertyChangeListener
+        ObjectModelOperation removePropertyChangeListener =3D addOperation(d=
toClass,
+                "removePropertyChangeListener", "void");
+        addAnnotation(dtoClass, removePropertyChangeListener, "Override");
+        addParameter(removePropertyChangeListener, "PropertyChangeListener",=
 "listener");
+        setOperationBody(removePropertyChangeListener, ""
+/*{
+        throw new UnsupportedOperationException("Not supported yet.");
+}*/);
+
+        // adding addPropertyChangeListener 2 parameters
+        ObjectModelOperation addPropertyChangeListener2 =3D addOperation(dto=
Class,
+                "addPropertyChangeListener", "void");
+        addAnnotation(dtoClass, addPropertyChangeListener2, "Override");
+        addParameter(addPropertyChangeListener2, "String", "property");
+        addParameter(addPropertyChangeListener2, "PropertyChangeListener", "=
listener");
+        setOperationBody(addPropertyChangeListener2, ""
+/*{
+        throw new UnsupportedOperationException("Not supported yet.");
+}*/);
+
+        // adding removePropertyChangeListener 2 parameters
+        ObjectModelOperation removePropertyChangeListener2 =3D addOperation(=
dtoClass,
+                "removePropertyChangeListener", "void");
+        addAnnotation(dtoClass, removePropertyChangeListener2, "Override");
+        addParameter(removePropertyChangeListener2, "String", "property");
+        addParameter(removePropertyChangeListener2, "PropertyChangeListener"=
, "listener");
+        setOperationBody(removePropertyChangeListener2, ""
+/*{
+        throw new UnsupportedOperationException("Not supported yet.");
+}*/);
+
+        //adding getExtensionFields method
+        ObjectModelOperation getExtensionFields =3D addOperation(dtoClass,
+                "getExtensionFields", "Collection<String>");
+        addAnnotation(dtoClass, getExtensionFields, "Override");
+        addParameter(getExtensionFields, "String", "ext");
+        setOperationBody(getExtensionFields, ""
+/*{
+        throw new UnsupportedOperationException("Not supported yet.");
+}*/);
+
+        //adding getExtensionNames method
+        ObjectModelOperation getExtensionNames =3D addOperation(dtoClass,
+                "getExtensionNames", "Collection<String>");
+        addAnnotation(dtoClass, getExtensionNames, "Override");
+        setOperationBody(getExtensionNames, ""
+/*{
+        throw new UnsupportedOperationException("Not supported yet.");
+}*/);
+
+        //adding getField method
+        ObjectModelOperation getField =3D addOperation(dtoClass, "getField",=
 "Object");
+        addAnnotation(dtoClass, getField, "Override");
+        addParameter(getField, "String", "ext");
+        addParameter(getField, "String", "fieldName");
+        setOperationBody(getField, ""
+/*{
+        throw new UnsupportedOperationException("Not supported yet.");
+}*/);
+
+        //adding setField method
+        ObjectModelOperation setField =3D addOperation(dtoClass, "setField",=
 "void");
+        addAnnotation(dtoClass, setField, "Override");
+        addParameter(setField, "String", "ext");
+        addParameter(setField, "String", "fieldName");
+        addParameter(setField, "Object", "value");
+        setOperationBody(setField, ""
+/*{
+        throw new UnsupportedOperationException("Not supported yet.");
+}*/);
+
+    }
+
+    protected void addModelOperations(ObjectModelClass businessEntity, Objec=
tModelClass dtoClass){
+        Collection<ObjectModelOperation> operations =3D businessEntity.getOp=
erations();
+
+        for (ObjectModelOperation operation:operations){
+            ObjectModelOperation dtoOperation =3D addOperation(dtoClass,
+                    operation.getName(), operation.getReturnType());
+
+            Collection<ObjectModelParameter> parameters =3D operation.getPar=
ameters();
+            for (ObjectModelParameter parameter:parameters){
+                addParameter(dtoOperation, parameter.getType(), parameter.ge=
tName());
+            }
+            addAnnotation(dtoClass, dtoOperation, "Override");
+            setOperationBody(dtoOperation, ""
+/*{
+        throw new UnsupportedOperationException("Not supported yet.");
+}*/);
+        }
+    }
+
+}


--===============5264618842725374854==--


