Subject: [Topia-commits] r1318 - in topia/trunk/topia-persistence/src/main/java/org/codelutin/topia: generator persistence
From: [email-masked]
To: [email-masked]
Date: Wed, 28 Jan 2009 18:19:18 +0100 (CET)
List-Id: <topia-commits.lists.labs.libre-entreprise.org>

Author: bpoussin
Date: 2009-01-28 17:19:17 +0000 (Wed, 28 Jan 2009)
New Revision: 1318

Added:
   topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/EntityVisitor.java
Modified:
   topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java
Log:
ajout d'un methode accept pour visite tous les attributs d'une entity et de la class EntityVisitor
(je laisse en exercice les tests et le debuggage, on dit merci qui :))

Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java	2009-01-26 22:19:33 UTC (rev 1317)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java	2009-01-28 17:19:17 UTC (rev 1318)
@@ -225,7 +225,75 @@
 
 }*/
 
+
 /*{
+    /**
+     * Envoi via les methodes du visitor l'ensemble des champs de l'entity
+     * avec leur type et leur valeur
+     *)
+    public void accept(EntityVisitor visitor) throws TopiaException {
+        visitor.start(this);
+}*/
+
+        for (ObjectModelAttribute attr : clazz.getAttributes()) {
+            ObjectModelAttribute reverse = attr.getReverseAttribute();
+
+            // pour les asso quoi qu'il arrive il faut les lier des 2 cotes
+            // pour pouvoir supprimer en cascade l'asso lors de la suppression
+            // d'un des cotes
+            if (!(attr.isNavigable()
+                    || hasUnidirectionalRelationOnAbstractType(reverse, model)
+                    || attr.hasAssociationClass())) {
+                continue;
+            }
+
+            if (!Util.isNMultiplicity(attr)) {
+                if (!attr.hasAssociationClass()) {
+                    // FIXME il faut encapsuler getType() pour retourner la version objet des types simples
+/*{    visitor.accept(this, <%=attr.getType()%>.class, <%=attr.getName()%>);
+
+}*/
+                } else {
+                    String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
+/*{    visitor.accept(this, <%=attr.getAssociationClass().getQualifiedName()%>.class, <%=Util.toLowerCaseFirstLetter(assocAttrName)%>);
+
+}*/
+                }
+            } else {
+                String collectionType = GeneratorUtil.getNMultiplicityInterfaceType(attr);
+                if (!attr.hasAssociationClass()) {
+/*{    visitor.accept(this, <%=collectionType%>.class, <%=attr.getType()%>.class, <%=attr.getName()%>);
+
+}*/
+                } else {
+                    String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
+/*{    visitor.accept(this, <%=collectionType%>.class, <%=attr.getAssociationClass().getQualifiedName()%>.class, <%=Util.toLowerCaseFirstLetter(assocAttrName)%>);
+
+}*/
+                }
+            }
+        }
+
+        //Déclaration des attributs d'une classe d'associations
+        if (clazz instanceof ObjectModelAssociationClass) {
+            ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz;
+            for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
+                if (attr != null) {
+/*{    visitor.accept(this, <%=attr.getType()%>.class, <%=Util.toLowerCaseFirstLetter(attr.getName())%>);
+
+}*/
+                }
+            }
+        }
+/*{
+        visitor.end(this);
+    }
+
+}*/
+
+
+
+/*{
     public List<TopiaEntity> getAggregate() throws TopiaException {
         List<TopiaEntity> tmp = new ArrayList<TopiaEntity>();
         // pour tous les attributs rechecher les composites et les class d'asso

Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/EntityVisitor.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/EntityVisitor.java	                        (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/persistence/EntityVisitor.java	2009-01-28 17:19:17 UTC (rev 1318)
@@ -0,0 +1,36 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 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.codelutin.topia.persistence;
+
+/**
+ *
+ * Created: 28 janv. 2009 18:10:34
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public interface EntityVisitor {
+
+    public void start(TopiaEntity e);
+    public void end(TopiaEntity e);
+    public void visit(TopiaEntity e, Class type, Object value);
+    public void visit(TopiaEntity e, Class collectionType, Class type, Object value);
+}

_______________________________________________
Topia-commits mailing list
[email-masked]
https://lists.labs.libre-entreprise.org/mailman/listinfo/topia-commits