Topia-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- 4806 discussions
18 Apr '09
Author: tchemit
Date: 2009-04-18 07:42:19 +0000 (Sat, 18 Apr 2009)
New Revision: 1426
Modified:
topia/trunk/topia-persistence/changelog.txt
Log:
changelog
Modified: topia/trunk/topia-persistence/changelog.txt
===================================================================
--- topia/trunk/topia-persistence/changelog.txt 2009-04-17 21:24:37 UTC (rev 1425)
+++ topia/trunk/topia-persistence/changelog.txt 2009-04-18 07:42:19 UTC (rev 1426)
@@ -1,4 +1,6 @@
2.1.4 xxxx 200903xx
+* 20090418 [chemit] - add a BeanGenerator
+ - add methods isXXXEmpty on association in generated entities
* 20090317 [chatellier] Change tagValue from "orderBy" to "order-by"
2.1.3 chemit 20090220
1
0
r1425 - topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator
by tchemit@users.labs.libre-entreprise.org 17 Apr '09
by tchemit@users.labs.libre-entreprise.org 17 Apr '09
17 Apr '09
Author: tchemit
Date: 2009-04-17 21:24:37 +0000 (Fri, 17 Apr 2009)
New Revision: 1425
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/EntityInterfaceGenerator.java
Log:
- ajout sur les associations multiples de la m?\195?\169thode isXXXEmpty pour savoir si la collection est vide (utilise sizeXXX)
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-04-15 15:08:45 UTC (rev 1424)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java 2009-04-17 21:24:37 UTC (rev 1425)
@@ -729,6 +729,15 @@
return <%=attrName%>.size();
}
+ /* (non-Javadoc)
+ * @see <%=clazzFQN%>#is<%=GeneratorUtil.capitalize(attrName)%>Empty()
+ *)
+ @Override
+ public boolean is<%=GeneratorUtil.capitalize(attrName)%>Empty() {
+ int size = size<%=GeneratorUtil.capitalize(attrName)%>();
+ return size == 0;
+ }
+
}*/
} else {
String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
@@ -768,6 +777,15 @@
return <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.size();
}
+ /* (non-Javadoc)
+ * @see <%=clazzFQN%>#is<%=GeneratorUtil.capitalize(assocAttrName)%>Empty()
+ *)
+ @Override
+ public boolean is<%=GeneratorUtil.capitalize(assocAttrName)%>Empty() {
+ int size = size<%=GeneratorUtil.capitalize(assocAttrName)%>();
+ return size == 0;
+ }
+
}*/
}
}
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java 2009-04-15 15:08:45 UTC (rev 1424)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java 2009-04-17 21:24:37 UTC (rev 1425)
@@ -340,6 +340,11 @@
*)
public int size<%=GeneratorUtil.capitalize(attrName)%>();
+ /**
+ * @return <code>true</code> si la collection <%=attrName%> est vide.
+ *)
+ public boolean is<%=GeneratorUtil.capitalize(attrName)%>Empty();
+
}*/
}
@@ -409,7 +414,11 @@
* @return Le nombre d'éléments de la collection <%=attrName%>.
*)
public int size<%=GeneratorUtil.capitalize(assocAttrName)%>();
-
+
+ /**
+ * @return <code>true</code> si la collection <%=assocAttrName%> est vide.
+ *)
+ public boolean is<%=GeneratorUtil.capitalize(assocAttrName)%>Empty();
}*/
}
1
0
r1424 - in topia/trunk/topia-persistence/src: main/java/org/codelutin/topia/generator test/java/org/codelutin/topia/generator
by tchemit@users.labs.libre-entreprise.org 15 Apr '09
by tchemit@users.labs.libre-entreprise.org 15 Apr '09
15 Apr '09
Author: tchemit
Date: 2009-04-15 15:08:45 +0000 (Wed, 15 Apr 2009)
New Revision: 1424
Added:
topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/generator/TopiaGeneratorUtilTest.java
Modified:
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java
Log:
- BeanGenerator can generate abstract class now
- add a method to convert identifier to constant and use it in EntityInterfaceGenerator
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java 2009-04-15 07:33:53 UTC (rev 1423)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java 2009-04-15 15:08:45 UTC (rev 1424)
@@ -40,6 +40,7 @@
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.codelutin.generator.ObjectModelGenerator;
@@ -48,6 +49,8 @@
import org.codelutin.generator.models.object.ObjectModelClass;
import org.codelutin.generator.models.object.ObjectModelClassifier;
import org.codelutin.generator.models.object.ObjectModelInterface;
+import org.codelutin.generator.models.object.ObjectModelOperation;
+import org.codelutin.generator.models.object.ObjectModelParameter;
import org.codelutin.topia.persistence.TopiaEntity;
/**
@@ -173,7 +176,8 @@
}*/
}
- generateAttributes(output, attributes);
+ generateInterfaceOperations(output, clazz);
+ generateAttributes(output, attributes);
/*{ protected final PropertyChangeSupport pcs;
/**
@@ -428,6 +432,46 @@
}
}
+ 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
@@ -465,6 +509,6 @@
if (clazz.isAbstract()) {
return true;
}
- return false;
+ return !clazz.getOperations().isEmpty();
}
} //BeanGenerator
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java 2009-04-15 07:33:53 UTC (rev 1423)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityInterfaceGenerator.java 2009-04-15 15:08:45 UTC (rev 1424)
@@ -509,7 +509,8 @@
String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
}
- String attrColName = attrName.toUpperCase();
+ String attrColName = TopiaGeneratorUtil.convertVariableNameToConstantName(attrName);
+ //String attrColName = attrName.toUpperCase();
/*{ public static final String <%=attrColName%> = "<%=attrName%>";
}*/
@@ -521,7 +522,8 @@
for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
if (attr != null) {
String attrName = attr.getName();
- String attrColName = attrName.toUpperCase();
+ String attrColName = TopiaGeneratorUtil.convertVariableNameToConstantName(attrName);
+ //String attrColName = attrName.toUpperCase();
/*{ public static final String <%=attrColName%> = "<%=attrName%>";
}*/
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java 2009-04-15 07:33:53 UTC (rev 1423)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java 2009-04-15 15:08:45 UTC (rev 1424)
@@ -933,4 +933,33 @@
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
Added: topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/generator/TopiaGeneratorUtilTest.java
===================================================================
--- topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/generator/TopiaGeneratorUtilTest.java (rev 0)
+++ topia/trunk/topia-persistence/src/test/java/org/codelutin/topia/generator/TopiaGeneratorUtilTest.java 2009-04-15 15:08:45 UTC (rev 1424)
@@ -0,0 +1,44 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.codelutin.topia.generator;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author chemit
+ */
+public class TopiaGeneratorUtilTest {
+
+ @Test
+ public void testConvertVariableNameToConstantName() {
+
+ String variableName = "abc";
+ String expResult = "ABC";
+ String result = TopiaGeneratorUtil.convertVariableNameToConstantName(variableName);
+ assertEquals(expResult, result);
+
+ variableName = "ABC";
+ expResult = "ABC";
+ result = TopiaGeneratorUtil.convertVariableNameToConstantName(variableName);
+ assertEquals(expResult, result);
+
+ variableName = "abC";
+ expResult = "AB_C";
+ result = TopiaGeneratorUtil.convertVariableNameToConstantName(variableName);
+ assertEquals(expResult, result);
+
+ variableName = "AbC";
+ expResult = "AB_C";
+ result = TopiaGeneratorUtil.convertVariableNameToConstantName(variableName);
+ assertEquals(expResult, result);
+
+ variableName = "AbC";
+ expResult = "AB_C";
+ result = TopiaGeneratorUtil.convertVariableNameToConstantName(variableName);
+ assertEquals(expResult, result);
+ }
+}
\ No newline at end of file
1
0
r1423 - topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator
by tchemit@users.labs.libre-entreprise.org 15 Apr '09
by tchemit@users.labs.libre-entreprise.org 15 Apr '09
15 Apr '09
Author: tchemit
Date: 2009-04-15 07:33:53 +0000 (Wed, 15 Apr 2009)
New Revision: 1423
Modified:
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java
Log:
add a simple Bean generator with pcs notifications
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java 2009-04-13 11:34:36 UTC (rev 1422)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java 2009-04-15 07:33:53 UTC (rev 1423)
@@ -34,6 +34,9 @@
import java.io.File;
import java.io.IOException;
import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
@@ -41,11 +44,11 @@
import org.apache.commons.logging.LogFactory;
import org.codelutin.generator.ObjectModelGenerator;
import org.codelutin.generator.GeneratorUtil;
-import org.codelutin.generator.models.object.ObjectModelAssociationClass;
import org.codelutin.generator.models.object.ObjectModelAttribute;
import org.codelutin.generator.models.object.ObjectModelClass;
import org.codelutin.generator.models.object.ObjectModelClassifier;
import org.codelutin.generator.models.object.ObjectModelInterface;
+import org.codelutin.topia.persistence.TopiaEntity;
/**
* DTO generator
@@ -72,20 +75,67 @@
return;
}
String copyright = TopiaGeneratorUtil.getCopyright(model);
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
-/*{<%=copyright%>
-}*/
- }
String clazzName = clazz.getName();
-/*{package <%=clazz.getPackageName()%>;
- }*/
+ String abstractStr = isAbstract(clazz)?"abstract ":" ";
boolean generateToString = TopiaGeneratorUtil.generateToString(clazz, model);
- List<String> imports = TopiaGeneratorUtil.getImports(clazz,
+ List<String> imports = TopiaGeneratorUtil.getImports(clazz,
+ List.class.getName(),
+ Collection.class.getName(),
+ TopiaEntity.class.getName(),
+ java.beans.PropertyChangeSupport.class.getName(),
java.beans.PropertyChangeListener.class.getName()
);
if (generateToString) {
imports.add(org.apache.commons.lang.builder.ToStringBuilder.class.getName());
}
+ String extendClass = "";
+ Iterator<ObjectModelClass> j = clazz.getSuperclasses().iterator();
+ if (j.hasNext()) {
+ ObjectModelClassifier p = j.next();
+ extendClass += p.getName();
+ }
+ String implInterface = "";
+ for (Iterator<ObjectModelInterface> i=clazz.getInterfaces().iterator(); i.hasNext();) {
+ ObjectModelClassifier parentInterface = i.next();
+ implInterface += parentInterface.getName();
+ if (i.hasNext()) {
+ implInterface += ", ";
+ }
+ }
+ String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", clazz, model);
+
+ List<ObjectModelAttribute> attributes;
+ List<ObjectModelAttribute> multipleAttr;
+ attributes = new ArrayList<ObjectModelAttribute>();
+ multipleAttr = new ArrayList<ObjectModelAttribute>();
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
+ if (attr.isNavigable()) {
+ attributes.add(attr);
+ if (GeneratorUtil.isNMultiplicity(attr)) {
+ multipleAttr.add(attr);
+ }
+ }
+ }
+ 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);
+ }
+ if (TopiaGeneratorUtil.notEmpty(copyright)) {
+/*{<%=copyright%>
+}*/
+ }
+
+/*{package <%=clazz.getPackageName()%>;
+ }*/
+
if (log.isDebugEnabled()) {
log.debug("imports for class <" + clazzName + ">");
}
@@ -96,34 +146,16 @@
/*{import <%=anImport%>;
}*/
}
+/*{
+public <%=abstractStr%>class <%=clazzName%>}*/
-/**
- * DTO implantation for <%=GeneratorUtil.capitalize(clazzName)%> entity.
- *)
-public class <%=clazzName%>}*/
-
/*
* Définition de la super classe : il ne doit y avoir qu'une
*/
-
- String extendClass = "";
- Iterator<ObjectModelClass> j = clazz.getSuperclasses().iterator();
- if (j.hasNext()) {
- ObjectModelClassifier p = j.next();
- extendClass += p.getName();
- }
-
if (extendClass.length() > 0) {
/*{ extends <%=extendClass%>}*/
}
- String implInterface = "";
- for (Iterator<ObjectModelInterface> i=clazz.getInterfaces().iterator(); i.hasNext();) {
- ObjectModelClassifier parentInterface = i.next();
- implInterface += parentInterface.getName();
- if (i.hasNext()) {
- implInterface += ", ";
- }
- }
+
if (implInterface.length() > 0) {
/*{ implements <%=implInterface%> {
@@ -134,84 +166,21 @@
}*/
}
- String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", clazz, model);
+
// TODO Calculer un serialVersionUID si il n'y en a pas
if (svUID != null) {
/*{ public static final long serialVersionUID = <%=svUID%>;
}*/
}
-/*
- * Définition des attributs
- */
- for (ObjectModelAttribute attr : clazz.getAttributes()) {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
-
- 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 (!GeneratorUtil.isNMultiplicity(attr)) {
- if (!attr.hasAssociationClass()) {
-/*{ <%=attrVisibility%> <%=attrType%> <%=attrName%>;
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
-/*{ <%=attrVisibility%> <%=assocClassFQN%> <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
-}*/
- }
- } else {
- if (!attr.hasAssociationClass()) {
- String nMultType = getCollection(attr, attrType);
-/*{ <%=attrVisibility%> <%=nMultType%> <%=attrName%>;
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- String nMultType = getCollection(attr, assocClassFQN);
-/*{ <%=attrVisibility%> <%=nMultType%> <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
-}*/
- }
- }
- } /* end for*/
+ generateAttributes(output, attributes);
+/*{ protected final PropertyChangeSupport pcs;
- //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) {
- String attrName = attr.getName();
- String attrVisibility = attr.getVisibility();
- String attrType = attr.getType();
-/*{ <%=attrVisibility%> <%=attrType%> <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%>;
-}*/
- }
- }
- }
-/*{
- protected java.beans.PropertyChangeSupport pcs;
-
/**
* Default constructor of <%=clazzName%>.
*)
public <%=clazzName%>() {
- pcs = new java.beans.PropertyChangeSupport(this);
+ pcs = new PropertyChangeSupport(this);
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
@@ -230,161 +199,254 @@
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 void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
pcs.firePropertyChange(propertyName, oldValue, newValue);
}
+
+ 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;
+ }
+
+ 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;
+ }
+ }*/
+ }
+
+/*{
+} //<%=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 (Object o : clazz.getAttributes()) {
- ObjectModelAttribute attr = (ObjectModelAttribute) o;
- ObjectModelAttribute reverse = attr.getReverseAttribute();
-
+ for (ObjectModelAttribute attr : attributes) {
+
if (!attr.isNavigable()) {
continue;
}
String attrName = attr.getName();
String attrType = attr.getType();
-
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- if (!attr.hasAssociationClass()) {
-/*{ public void set<%=GeneratorUtil.capitalize(attrName)%>(<%=attrType%> value) {
- <%=attrType%> oldValue = this.<%=attrName%>;
- this.<%=attrName%> = value;
- firePropertyChange("<%=attrName%>", oldValue, value);
- }
-
- public <%=attrType%> get<%=GeneratorUtil.capitalize(attrName)%>() {
+ 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%>;
}
}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- if (log.isTraceEnabled()) {
- log.trace("assocAttrName: " + assocAttrName);
- }
-/*{ public void set<%=GeneratorUtil.capitalize(assocAttrName)%>(<%=assocClassFQN%> association) {
- <%=assocClassFQN%> oldAssocation = this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = association;
- p.firePropertyChange("<%=attrName%>", oldAssocation, assocation);
+ }
}
- public <%=assocClassFQN%> get<%=GeneratorUtil.capitalize(assocAttrName)%>() {
- return <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
+ 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);
}
}*/
- }
- } else { //NMultiplicity
- if (!attr.hasAssociationClass()) { //Méthodes remplacées par des accesseurs sur les classes d'assoc
- boolean reverseNavigable = reverse == null ? false : reverse.isNavigable();
- String reverseAttrName = reverse == null ? "" : reverse.getName();
- String nMultType = getCollection(attr, attrType);
-/*{ public void set<%=GeneratorUtil.capitalize(attrName)%>(<%=nMultType%> values) {
- <%=nMultType%> oldValues = this.<%=attrName%>;
- this.<%=attrName%> = values;
- firePropertyChange("<%=attrName%>", oldValues, values);
+ }
}
-}*/
+ protected void generateGetChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException {
+
+ for (ObjectModelAttribute attr : multipleAttr) {
- //AddChild
-/*{ public <%=attrType%> addChild(<%=attrType%> <%=attrName%>) {
- this.<%=attrName%>.add(<%=attrName%>);
- firePropertyChange("<%=attrName%>", null, <%=attrName%>);
-}*/
- if (reverseNavigable) {
-/*{ <%=attrName%>.set<%=GeneratorUtil.capitalize(reverseAttrName)%>(this);
-}*/
- }
-/*{ return <%=attrName%>;
+ 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;
}
-
+
}*/
- //RemoveChild
-/*{ public void removeChild(<%=attrType%> <%=attrName%>) {
- this.<%=attrName%>.remove(<%=attrName%>);
- firePropertyChange("<%=attrName%>", <%=attrName%>, null);
-}*/
- if (reverseNavigable) {
-/*{ <%=attrName%>.set<%=GeneratorUtil.capitalize(reverseAttrName)%>(null);
-}*/
- }
-/*{ }
-
-}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- String nMultType = getCollection(attr, assocClassFQN);
- if (log.isTraceEnabled()) {
- log.trace("assocAttrName: " + assocAttrName);
- }
-/*{ public void set<%=GeneratorUtil.capitalize(assocAttrName)%>(<%=nMultType%> values) {
- <%=nMultType%> oldValues = this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = values;
- firePropertyChange("<%=attrName%>", oldValues, values);
+ if (isEntity) {
+/*{ public <%=attrType%> get<%=attrNameCapitalized%>(String topiaId) {
+ <%=attrType%> o = getEntity(<%=attrName%>, topiaId);
+ return o;
}
}*/
- }
- if (!attr.hasAssociationClass()) {
- String nMultType = getCollection(attr, attrType);
-/*{ public <%=nMultType%> get<%=GeneratorUtil.capitalize(attrName)%>() {
- return this.<%=attrName%>;
+ }
+ }
}
+ 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%>;
+ }
}*/
- } else {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- String nMultType = getCollection(attr, assocClassFQN);
- if (log.isTraceEnabled()) {
- log.trace("assocAttrName: " + assocAttrName);
- }
-/*{ public <%=nMultType%> get<%=GeneratorUtil.capitalize(assocAttrName)%>() {
- return this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
+ }
}
-}*/
- }
+ 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;
+ }
- if (generateToString) {
+}*/
+ }
+ }
+
+ 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())) {
+ if (!(attr.isNavigable() || attr.hasAssociationClass())) {
continue;
}
//FIXME possibilité de boucles (non directes)
- ObjectModelClass attrEntity = null;
- if (model.hasClass(attr.getType())) {
- attrEntity = model.getClass(attr.getType());
- }
String attrName = attr.getName();
/*{ append("<%=attrName%>", this.<%=attrName%>).
-}*/
+}*/
}
-/*{ toString();
+/*{ toString();
return result;
}
}*/
- }
-/*{
-} //<%=clazz.getName()%>
-}*/
}
protected String getCollection(ObjectModelAttribute attr, String attrType) {
@@ -398,4 +460,11 @@
nMultType += ">";
return nMultType;
}
+
+ protected boolean isAbstract(ObjectModelClass clazz) {
+ if (clazz.isAbstract()) {
+ return true;
+ }
+ return false;
+ }
} //BeanGenerator
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java 2009-04-13 11:34:36 UTC (rev 1422)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java 2009-04-15 07:33:53 UTC (rev 1423)
@@ -142,6 +142,9 @@
/** 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";
/** Type de persistence Hibernate */
public static final String PERSISTENCE_TYPE_HIBERNATE = "hibernate";
@@ -313,7 +316,33 @@
}
return true;
}
+ /**
+ * 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 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.
*
1
0
r1422 - topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator
by tchemit@users.labs.libre-entreprise.org 13 Apr '09
by tchemit@users.labs.libre-entreprise.org 13 Apr '09
13 Apr '09
Author: tchemit
Date: 2009-04-13 11:34:36 +0000 (Mon, 13 Apr 2009)
New Revision: 1422
Added:
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java
Modified:
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java
Log:
add a simple Bean generator with pcs notifications
Added: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java (rev 0)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java 2009-04-13 11:34:36 UTC (rev 1422)
@@ -0,0 +1,401 @@
+/* *##% ToPIA - Tools for Portable and Independent Architecture
+ * Copyright (C) 2004 - 2008 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+/* *
+* EntityAbstractGenerator.java
+*
+* Created: 12 déc. 2005
+*
+* @author Arnaud Thimel <thimel(a)codelutin.com>
+* @version $Revision: 1334 $
+*
+* Mise a jour: $Date: 2009-01-29 16:47:42 +0100 (jeu 29 jan 2009) $
+* par : $Author: thimel $
+*/
+
+package org.codelutin.topia.generator;
+
+import static org.codelutin.topia.generator.TopiaGeneratorUtil.TAG_ANNOTATION;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Iterator;
+
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.generator.ObjectModelGenerator;
+import org.codelutin.generator.GeneratorUtil;
+import org.codelutin.generator.models.object.ObjectModelAssociationClass;
+import org.codelutin.generator.models.object.ObjectModelAttribute;
+import org.codelutin.generator.models.object.ObjectModelClass;
+import org.codelutin.generator.models.object.ObjectModelClassifier;
+import org.codelutin.generator.models.object.ObjectModelInterface;
+
+/**
+ * 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)) {
+ return;
+ }
+ String copyright = TopiaGeneratorUtil.getCopyright(model);
+ if (TopiaGeneratorUtil.notEmpty(copyright)) {
+/*{<%=copyright%>
+}*/
+ }
+ String clazzName = clazz.getName();
+/*{package <%=clazz.getPackageName()%>;
+ }*/
+ boolean generateToString = TopiaGeneratorUtil.generateToString(clazz, model);
+ List<String> imports = TopiaGeneratorUtil.getImports(clazz,
+ java.beans.PropertyChangeListener.class.getName()
+ );
+ if (generateToString) {
+ imports.add(org.apache.commons.lang.builder.ToStringBuilder.class.getName());
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("imports for class <" + clazzName + ">");
+ }
+ for (String anImport : imports) {
+ if (log.isDebugEnabled()) {
+ log.debug("import " + anImport);
+ }
+/*{import <%=anImport%>;
+}*/
+ }
+
+/**
+ * DTO implantation for <%=GeneratorUtil.capitalize(clazzName)%> entity.
+ *)
+public class <%=clazzName%>}*/
+
+/*
+ * Définition de la super classe : il ne doit y avoir qu'une
+ */
+
+ String extendClass = "";
+ Iterator<ObjectModelClass> j = clazz.getSuperclasses().iterator();
+ if (j.hasNext()) {
+ ObjectModelClassifier p = j.next();
+ extendClass += p.getName();
+ }
+
+ if (extendClass.length() > 0) {
+/*{ extends <%=extendClass%>}*/
+ }
+ String implInterface = "";
+ for (Iterator<ObjectModelInterface> i=clazz.getInterfaces().iterator(); i.hasNext();) {
+ ObjectModelClassifier parentInterface = i.next();
+ implInterface += parentInterface.getName();
+ if (i.hasNext()) {
+ implInterface += ", ";
+ }
+ }
+ if (implInterface.length() > 0) {
+/*{ implements <%=implInterface%> {
+
+}*/
+ } else {
+ /*{ {
+
+}*/
+ }
+
+ String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", clazz, model);
+ // TODO Calculer un serialVersionUID si il n'y en a pas
+ if (svUID != null) {
+/*{ public static final long serialVersionUID = <%=svUID%>;
+
+}*/
+ }
+/*
+ * Définition des attributs
+ */
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
+ ObjectModelAttribute reverse = attr.getReverseAttribute();
+
+ 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 (!GeneratorUtil.isNMultiplicity(attr)) {
+ if (!attr.hasAssociationClass()) {
+/*{ <%=attrVisibility%> <%=attrType%> <%=attrName%>;
+}*/
+ } else {
+ String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ String assocClassFQN = attr.getAssociationClass().getQualifiedName();
+/*{ <%=attrVisibility%> <%=assocClassFQN%> <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
+}*/
+ }
+ } else {
+ if (!attr.hasAssociationClass()) {
+ String nMultType = getCollection(attr, attrType);
+/*{ <%=attrVisibility%> <%=nMultType%> <%=attrName%>;
+}*/
+ } else {
+ String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ String assocClassFQN = attr.getAssociationClass().getQualifiedName();
+ String nMultType = getCollection(attr, assocClassFQN);
+/*{ <%=attrVisibility%> <%=nMultType%> <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
+}*/
+ }
+ }
+ } /* end for*/
+
+ //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) {
+ String attrName = attr.getName();
+ String attrVisibility = attr.getVisibility();
+ String attrType = attr.getType();
+/*{ <%=attrVisibility%> <%=attrType%> <%=GeneratorUtil.toLowerCaseFirstLetter(attrName)%>;
+}*/
+ }
+ }
+ }
+/*{
+ protected java.beans.PropertyChangeSupport pcs;
+
+ /**
+ * Default constructor of <%=clazzName%>.
+ *)
+ public <%=clazzName%>() {
+ pcs = new java.beans.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);
+ }
+
+ protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ pcs.firePropertyChange(propertyName, oldValue, newValue);
+ }
+}*/
+
+
+ /*
+ * Définition des getteurs et setteurs
+ */
+ for (Object o : clazz.getAttributes()) {
+ ObjectModelAttribute attr = (ObjectModelAttribute) o;
+ ObjectModelAttribute reverse = attr.getReverseAttribute();
+
+ if (!attr.isNavigable()) {
+ continue;
+ }
+
+ String attrName = attr.getName();
+ String attrType = attr.getType();
+
+ if (!GeneratorUtil.isNMultiplicity(attr)) {
+ if (!attr.hasAssociationClass()) {
+/*{ public void set<%=GeneratorUtil.capitalize(attrName)%>(<%=attrType%> value) {
+ <%=attrType%> oldValue = this.<%=attrName%>;
+ this.<%=attrName%> = value;
+ firePropertyChange("<%=attrName%>", oldValue, value);
+ }
+
+ public <%=attrType%> get<%=GeneratorUtil.capitalize(attrName)%>() {
+ return <%=attrName%>;
+ }
+
+}*/
+ } else {
+ String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ String assocClassFQN = attr.getAssociationClass().getQualifiedName();
+ if (log.isTraceEnabled()) {
+ log.trace("assocAttrName: " + assocAttrName);
+ }
+/*{ public void set<%=GeneratorUtil.capitalize(assocAttrName)%>(<%=assocClassFQN%> association) {
+ <%=assocClassFQN%> oldAssocation = this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
+ this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = association;
+ p.firePropertyChange("<%=attrName%>", oldAssocation, assocation);
+ }
+
+ public <%=assocClassFQN%> get<%=GeneratorUtil.capitalize(assocAttrName)%>() {
+ return <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
+ }
+
+}*/
+ }
+ } else { //NMultiplicity
+ if (!attr.hasAssociationClass()) { //Méthodes remplacées par des accesseurs sur les classes d'assoc
+ boolean reverseNavigable = reverse == null ? false : reverse.isNavigable();
+ String reverseAttrName = reverse == null ? "" : reverse.getName();
+ String nMultType = getCollection(attr, attrType);
+/*{ public void set<%=GeneratorUtil.capitalize(attrName)%>(<%=nMultType%> values) {
+ <%=nMultType%> oldValues = this.<%=attrName%>;
+ this.<%=attrName%> = values;
+ firePropertyChange("<%=attrName%>", oldValues, values);
+ }
+
+}*/
+
+ //AddChild
+/*{ public <%=attrType%> addChild(<%=attrType%> <%=attrName%>) {
+ this.<%=attrName%>.add(<%=attrName%>);
+ firePropertyChange("<%=attrName%>", null, <%=attrName%>);
+}*/
+ if (reverseNavigable) {
+/*{ <%=attrName%>.set<%=GeneratorUtil.capitalize(reverseAttrName)%>(this);
+}*/
+ }
+/*{ return <%=attrName%>;
+ }
+
+}*/
+ //RemoveChild
+/*{ public void removeChild(<%=attrType%> <%=attrName%>) {
+ this.<%=attrName%>.remove(<%=attrName%>);
+ firePropertyChange("<%=attrName%>", <%=attrName%>, null);
+}*/
+ if (reverseNavigable) {
+/*{ <%=attrName%>.set<%=GeneratorUtil.capitalize(reverseAttrName)%>(null);
+}*/
+ }
+/*{ }
+
+}*/
+ } else {
+ String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ String assocClassFQN = attr.getAssociationClass().getQualifiedName();
+ String nMultType = getCollection(attr, assocClassFQN);
+ if (log.isTraceEnabled()) {
+ log.trace("assocAttrName: " + assocAttrName);
+ }
+/*{ public void set<%=GeneratorUtil.capitalize(assocAttrName)%>(<%=nMultType%> values) {
+ <%=nMultType%> oldValues = this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
+ this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = values;
+ firePropertyChange("<%=attrName%>", oldValues, values);
+ }
+
+}*/
+ }
+ if (!attr.hasAssociationClass()) {
+ String nMultType = getCollection(attr, attrType);
+/*{ public <%=nMultType%> get<%=GeneratorUtil.capitalize(attrName)%>() {
+ return this.<%=attrName%>;
+ }
+
+}*/
+ } else {
+ String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ String assocClassFQN = attr.getAssociationClass().getQualifiedName();
+ String nMultType = getCollection(attr, assocClassFQN);
+ if (log.isTraceEnabled()) {
+ log.trace("assocAttrName: " + assocAttrName);
+ }
+/*{ public <%=nMultType%> get<%=GeneratorUtil.capitalize(assocAttrName)%>() {
+ return this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
+ }
+
+}*/
+ }
+ }
+ }
+
+ if (generateToString) {
+/*{
+ @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)
+ ObjectModelClass attrEntity = null;
+ if (model.hasClass(attr.getType())) {
+ attrEntity = model.getClass(attr.getType());
+ }
+ String attrName = attr.getName();
+/*{ append("<%=attrName%>", this.<%=attrName%>).
+}*/
+ }
+/*{ toString();
+ return result;
+ }
+ }*/
+ }
+/*{
+} //<%=clazz.getName()%>
+}*/
+ }
+
+ protected String getCollection(ObjectModelAttribute attr, String attrType) {
+ String nMultType;
+ if (attr.isOrdered()) {
+ nMultType = "List<";
+ } else {
+ nMultType = "Collection<";
+ }
+ nMultType += attrType;
+ nMultType += ">";
+ return nMultType;
+ }
+} //BeanGenerator
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java 2009-04-12 21:21:30 UTC (rev 1421)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java 2009-04-13 11:34:36 UTC (rev 1422)
@@ -63,6 +63,8 @@
/** 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
@@ -302,11 +304,11 @@
ObjectModel model) {
String value;
value = model.getTagValue(TAG_NOT_GENERATE_TO_STRING);
- if (value != null || value.trim().isEmpty()) {
+ if (value != null && !value.trim().isEmpty()) {
return false;
}
value = clazz.getTagValue(TAG_NOT_GENERATE_TO_STRING);
- if (value != null || value.trim().isEmpty()) {
+ if (value != null && !value.trim().isEmpty()) {
return false;
}
return true;
1
0
r1421 - topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator
by tchemit@users.labs.libre-entreprise.org 12 Apr '09
by tchemit@users.labs.libre-entreprise.org 12 Apr '09
12 Apr '09
Author: tchemit
Date: 2009-04-12 21:21:30 +0000 (Sun, 12 Apr 2009)
New Revision: 1421
Modified:
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java
Log:
can skip toString generation
Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java 2009-04-12 21:20:39 UTC (rev 1420)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/TopiaGeneratorUtil.java 2009-04-12 21:21:30 UTC (rev 1421)
@@ -138,6 +138,9 @@
/** 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";
+
/** Type de persistence Hibernate */
public static final String PERSISTENCE_TYPE_HIBERNATE = "hibernate";
@@ -289,6 +292,26 @@
return result;
}
+ /**
+ * 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 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;
+ }
+
/**
* Detecte si un attribut fait partie d'une clef metier.
*
@@ -683,6 +706,7 @@
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(
1
0
r1420 - topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator
by tchemit@users.labs.libre-entreprise.org 12 Apr '09
by tchemit@users.labs.libre-entreprise.org 12 Apr '09
12 Apr '09
Author: tchemit
Date: 2009-04-12 21:20:39 +0000 (Sun, 12 Apr 2009)
New Revision: 1420
Modified:
topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java
Log:
can skip toString generation
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-04-09 15:59:39 UTC (rev 1419)
+++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/EntityAbstractGenerator.java 2009-04-12 21:20:39 UTC (rev 1420)
@@ -791,7 +791,8 @@
}
}
}
-
+ boolean doGenerateToString = TopiaGeneratorUtil.generateToString(clazz, model);
+ if (doGenerateToString) {
/*{ /* (non-Javadoc)
* @see java.lang.Object#toString()
*)
@@ -817,6 +818,7 @@
return result;
}
}*/
+ }
String i18nPrefix = TopiaGeneratorUtil.getI18nPrefix(clazz, model);
if (i18nPrefix != null) {
// generate i18n prefix
1
0
r1419 - topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator
by chatellier@users.labs.libre-entreprise.org 09 Apr '09
by chatellier@users.labs.libre-entreprise.org 09 Apr '09
09 Apr '09
Author: chatellier
Date: 2009-04-09 15:59:39 +0000 (Thu, 09 Apr 2009)
New Revision: 1419
Modified:
topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java
Log:
Code style (tab & co...)
Modified: topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java
===================================================================
--- topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java 2009-04-09 12:59:21 UTC (rev 1418)
+++ topia/trunk/topia-ui/src/main/java/org/codelutin/topia/generator/TapestryWebGenerator.java 2009-04-09 15:59:39 UTC (rev 1419)
@@ -1,5 +1,5 @@
/* *##% ToPIA - Tools for Portable and Independent Architecture
- * Copyright (C) 2004 - 2008 CodeLutin
+ * 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
@@ -28,7 +28,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.tapestry5.Link;
import org.codelutin.generator.MonitorWriter;
import org.codelutin.generator.StateModelGenerator;
import org.codelutin.generator.GeneratorUtil;
@@ -54,7 +53,7 @@
/** logger */
private static final Log log = LogFactory.getLog(TapestryWebGenerator.class);
-
+
/** Already asssigned use case states names */
protected List<String> assignedUseCaseStateNames;
@@ -66,7 +65,7 @@
public TapestryWebGenerator() {
assignedUseCaseStateNames = new ArrayList<String>();
}
-
+
/**
* Redefintion pour une generation specifique tapestry
*
@@ -75,18 +74,18 @@
*/
@Override
public void generate(StateModel stateModel, File destDir) throws IOException {
-
+
this.model = stateModel;
// pour tous les diagramme du model
for (StateModelStateChart chart : stateModel.getStateCharts()) {
generate(chart,chart.getStates(),destDir);
-
+
// generate use case engine
generateUseCaseEngineFromModel(stateModel, chart,destDir);
}
}
-
+
/**
* Appele par lutin generator pour tous les etats du model
* @param chart
@@ -96,7 +95,7 @@
return (getPackageFromState(chart) + '.' + getNameFromState(state)).replace('.',
File.separatorChar) + ".java";
}
-
+
/**
* Get generated class name from state
*
@@ -108,7 +107,7 @@
protected String getNameFromState(StateModelState state) {
return "Abstract" + GeneratorUtil.toUpperCaseFirstLetter(state.getName());
}
-
+
/**
* Return specifique tapestry package name.
*
@@ -120,7 +119,7 @@
protected String getPackageFromState(StateModelStateChart chart) {
return chart.getPackageName().replaceFirst("web", "web.pages");
}
-
+
/**
* Return specifique tapestry package name (base)
*
@@ -133,7 +132,7 @@
protected String getPackageFromComponents(StateModelStateChart chart) {
return chart.getPackageName().replaceFirst("web.*", "web.base");
}
-
+
/**
* Generate a collection of states
*
@@ -142,7 +141,7 @@
* @throws IOException
*/
protected void generate(StateModelStateChart chart, Collection<StateModelState> states, File destDir) throws IOException {
-
+
// et tous les états de ces diagrammes
for (Object oState : states.toArray()) {
generateFromState(chart,(StateModelState)oState,destDir);
@@ -159,7 +158,7 @@
* @throws IOException
*/
protected void generateFromState(StateModelStateChart chart, StateModelState state, File destDir) throws IOException {
-
+
// complexe
if(state.isComplex()) {
StateModelComplexState complexeState = (StateModelComplexState)state;
@@ -167,13 +166,13 @@
}
// simple
else {
-
+
StateModelSimpleState simpleState = (StateModelSimpleState)state;
-
+
// les etat initiaux et finaux ne donne pas
// pas de generation de fichier
if(!simpleState.isFinal() && !simpleState.isInitial()) {
-
+
String filename = getFilenameFromState(chart, simpleState);
File outputFile = getDestinationFile(destDir, filename);
if (getOverwrite() || !isNewerThanSource(outputFile)) {
@@ -193,7 +192,7 @@
} // init && final
}
}
-
+
/**
* Called for each simple state
*
@@ -203,7 +202,6 @@
* @throws IOException
*/
protected void generateFromSimpleState(Writer output, StateModelStateChart chart, StateModelState state) throws IOException {
- //String copyright = GeneratorGeneratorUtil.getCopyright(model);
String copyright = model.getTagValue("copyright");
if (copyright != null && !copyright.isEmpty()) {
/*{<%=copyright%>
@@ -220,231 +218,233 @@
*)
public abstract class <%=getNameFromState(state)%> extends UseCasePage {
}*/
-
+
// generate events
- generateInjectionAndEventsFromState(output,chart,state);
-
- // generate use case name
- generateUseCaseNameFromState(output,chart,state);
+ generateInjectionAndEventsFromState(output,chart,state);
+
+ // generate use case name
+ generateUseCaseNameFromState(output,chart,state);
/*{}}*/
- }
+ }
- /**
- * Generate state injections
- * @param output
- * @param chart
- * @param state
- */
- @SuppressWarnings("unused")
- protected void generateInjectionAndEventsFromState(Writer output, StateModelStateChart chart, StateModelState state) throws IOException {
-
- // liste les états de destination (pour éviter les doublons)
- List<StateModelState> destStates = new ArrayList<StateModelState>();
-
- for(StateModelTransition transition : state.getTransitions()) {
-
- StateModelState toState = transition.getDestinationState();
-
- if(toState.isComplex()) {
- StateModelState toInitState = ((StateModelComplexState)toState).getInitialState();
-
- // l'attribute doit etre private
- // sinon tapestry ne le traite pas
-
- // si l'état de destination n'a pas encore été traité
- if(!destStates.contains(toState)){
- destStates.add(toState);
+ /**
+ * Generate state injections
+ * @param output
+ * @param chart
+ * @param state
+ */
+ @SuppressWarnings("unused")
+ protected void generateInjectionAndEventsFromState(Writer output, StateModelStateChart chart, StateModelState state) throws IOException {
+
+ // liste les états de destination (pour éviter les doublons)
+ List<StateModelState> destStates = new ArrayList<StateModelState>();
+
+ for(StateModelTransition transition : state.getTransitions()) {
+
+ StateModelState toState = transition.getDestinationState();
+
+ if(toState.isComplex()) {
+ StateModelState toInitState = ((StateModelComplexState)toState).getInitialState();
+
+ // l'attribute doit etre private
+ // sinon tapestry ne le traite pas
+
+ // si l'état de destination n'a pas encore été traité
+ if(!destStates.contains(toState)){
+ destStates.add(toState);
/*{
/* linked state "<%=toState.getName()%>" *)
@InjectPage
private <%=GeneratorUtil.toUpperCaseFirstLetter(toInitState.getName())%> <%=GeneratorUtil.toLowerCaseFirstLetter(toInitState.getName())%>;
}*/
- // l'attribut etant prive, il faut un getter
+ // l'attribut etant prive, il faut un getter
/*{
- /* getter for state "<%=toState.getName()%>" *)
- protected <%=GeneratorUtil.toUpperCaseFirstLetter(toInitState.getName())%> get<%=GeneratorUtil.toUpperCaseFirstLetter(toInitState.getName())%>() {
- return <%=GeneratorUtil.toLowerCaseFirstLetter(toInitState.getName())%>;
- }
+ /* getter for state "<%=toState.getName()%>" *)
+ protected <%=GeneratorUtil.toUpperCaseFirstLetter(toInitState.getName())%> get<%=GeneratorUtil.toUpperCaseFirstLetter(toInitState.getName())%>() {
+ return <%=GeneratorUtil.toLowerCaseFirstLetter(toInitState.getName())%>;
+ }
}*/
- }
+ }
/*{
- /* transition on <%=transition.getEvent()%> event *)
- public Object onActionFrom<%=GeneratorUtil.toUpperCaseFirstLetter(transition.getEvent())%>() {
- enterUseCase();
- return <%=GeneratorUtil.toLowerCaseFirstLetter(toInitState.getName())%>;
- }
+ /* transition on <%=transition.getEvent()%> event *)
+ public Object onActionFrom<%=GeneratorUtil.toUpperCaseFirstLetter(transition.getEvent())%>() {
+ enterUseCase();
+ return <%=GeneratorUtil.toLowerCaseFirstLetter(toInitState.getName())%>;
+ }
}*/
- }
- else {
-
- StateModelSimpleState simpleToState = (StateModelSimpleState)toState;
-
- // si l'etat a injecter n'est pas final
- if(!simpleToState.isFinal()) {
-
- // si l'état de destination n'a pas encore été traité
- if(!destStates.contains(toState)){
- destStates.add(toState);
+ }
+ else {
+
+ StateModelSimpleState simpleToState = (StateModelSimpleState)toState;
+
+ // si l'etat a injecter n'est pas final
+ if(!simpleToState.isFinal()) {
+
+ // si l'état de destination n'a pas encore été traité
+ if(!destStates.contains(toState)){
+ destStates.add(toState);
/*{
/* linked state "<%=simpleToState.getName()%>" *)
- @InjectPage
- private <%=GeneratorUtil.toUpperCaseFirstLetter(simpleToState.getName())%> <%=GeneratorUtil.toLowerCaseFirstLetter(simpleToState.getName())%>;
+ @InjectPage
+ private <%=GeneratorUtil.toUpperCaseFirstLetter(simpleToState.getName())%> <%=GeneratorUtil.toLowerCaseFirstLetter(simpleToState.getName())%>;
}*/
- // l'attribut etant prive, il faut un getter
+ // l'attribut etant prive, il faut un getter
/*{
- /* getter for state "<%=simpleToState.getName()%>" *)
- protected <%=GeneratorUtil.toUpperCaseFirstLetter(simpleToState.getName())%> get<%=GeneratorUtil.toUpperCaseFirstLetter(simpleToState.getName())%>() {
- return <%=GeneratorUtil.toLowerCaseFirstLetter(simpleToState.getName())%>;
- }
+ /* getter for state "<%=simpleToState.getName()%>" *)
+ protected <%=GeneratorUtil.toUpperCaseFirstLetter(simpleToState.getName())%> get<%=GeneratorUtil.toUpperCaseFirstLetter(simpleToState.getName())%>() {
+ return <%=GeneratorUtil.toLowerCaseFirstLetter(simpleToState.getName())%>;
+ }
}*/
- }
- } // isFinal
+ }
+ } // isFinal
/*{
- /* transition on "<%=transition.getEvent()%>" event *)
- public Object onActionFrom<%=GeneratorUtil.toUpperCaseFirstLetter(transition.getEvent())%>() {
+ /* transition on "<%=transition.getEvent()%>" event *)
+ public Object onActionFrom<%=GeneratorUtil.toUpperCaseFirstLetter(transition.getEvent())%>() {
}*/
- if(simpleToState.isFinal()) {
-/*{ return leaveUseCase();
+ if(simpleToState.isFinal()) {
+/*{ return leaveUseCase();
}*/
- } else {
-/*{ return <%=GeneratorUtil.toLowerCaseFirstLetter(simpleToState.getName())%>;
+ } else {
+/*{ return <%=GeneratorUtil.toLowerCaseFirstLetter(simpleToState.getName())%>;
}*/
- }
+ }
/*{ }
}*/
- }
- }
- }
-
- /**
- * Generate use case name
- *
- * @param output
- * @param chart
- * @param state
- */
- protected void generateUseCaseNameFromState(Writer output, StateModelStateChart chart, StateModelState state) throws IOException {
+ }
+ }
+ }
- String stateId = generateStateUseCaseName(state.getName());
+ /**
+ * Generate use case name
+ *
+ * @param output
+ * @param chart
+ * @param state
+ */
+ protected void generateUseCaseNameFromState(Writer output, StateModelStateChart chart, StateModelState state) throws IOException {
+
+ String stateId = generateStateUseCaseName(state.getName());
/*{
- /* return a unique state id for model *)
- protected final String getUseCaseName() {
- return "<%=stateId%>";
- }
+ /* return a unique state id for model *)
+ protected final String getUseCaseName() {
+ return "<%=stateId%>";
+ }
}*/
- }
-
- /**
- * Genere un nom unique d'etat pour le model courant.
- *
- * Pour des raisons de debugage, on utilise des lettres particuliere du
- * nom de l'etat, suivit d'un numero, s'il y a collision.
- *
- * @return a unique name
- */
- protected String generateStateUseCaseName(String name) {
-
- String ucsn = getHashStateName(name);
-
- // test already assigned
- String uniqueucsn = ucsn;
- int num = 2;
- while(assignedUseCaseStateNames.contains(uniqueucsn)) {
- uniqueucsn = new StringBuffer(ucsn).append(num++).toString();
- }
-
- assignedUseCaseStateNames.add(uniqueucsn);
-
- return uniqueucsn;
- }
-
- /**
- * Hash a state name.
- *
- * On prend la premiere lettre de chaque mot.
- *
- * ContactList -> cl
- * contactList -> cl
- * ContactListPage -> clp
- *
- * @param name
- * @return hashed state name
- */
- protected String getHashStateName(String name) {
-
- // bug si moins de 1 caractere
- if(name == null || name.length()<1) return name;
-
- StringBuffer sb = new StringBuffer();
-
- // on prend la premiere lettre
- sb.append(Character.toLowerCase(name.charAt(0)));
-
- // ensuite, on prend les majuscules
- for(int i = 1 ; i < name.length() ; ++i) {
-
- // si maj
- if(Character.isUpperCase(name.charAt(i))) {
- sb.append(Character.toLowerCase(name.charAt(i)));
- }
- }
-
- return sb.toString();
- }
-
- /**
- * Generate the engine use case class.
- *
- * Need to be generated inside client webapp directory to be analysed by
- * tapestry (annotations)
- *
- * @param model model
- * @param chart chart
- */
- protected void generateUseCaseEngineFromModel(StateModel model,StateModelStateChart chart,File destDir) throws IOException {
- String componentPackageName = getPackageFromComponents(chart);
-
- // UseCasePage
- String filename = (componentPackageName + ".UseCasePage").replace('.', File.separatorChar) + ".java";
- File outputFile = getDestinationFile(destDir, filename);
- if (getOverwrite() || !isNewerThanSource(outputFile)) {
- try {
- StringWriter out = new StringWriter();
- MonitorWriter monitorOut = new MonitorWriter(out);
- // generate UseCasePage class
- generateUseCasePageClass(monitorOut,model,componentPackageName);
- write(outputFile, monitorOut);
- } catch (Exception e) {
- log.warn("Erreur lors de la génération du fichier UseCasePage",e);
- throw new RuntimeException(
- "Erreur lors de la génération du fichier UseCasePage", e);
- }
- }
-
- // UseCaseMap
- filename = (componentPackageName + ".UseCaseMap").replace('.', File.separatorChar) + ".java";
- outputFile = getDestinationFile(destDir, filename);
- if (getOverwrite() || !isNewerThanSource(outputFile)) {
- try {
- StringWriter out = new StringWriter();
- MonitorWriter monitorOut = new MonitorWriter(out);
- // generate UseCasePage class
- generateUseCaseMapClass(monitorOut,componentPackageName);
- write(outputFile, monitorOut);
- } catch (Exception e) {
- log.warn("Erreur lors de la génération du fichier UseCaseMap",e);
- throw new RuntimeException(
- "Erreur lors de la génération du fichier UseCaseMap", e);
- }
- }
- }
+ }
+
+ /**
+ * Genere un nom unique d'etat pour le model courant.
+ *
+ * Pour des raisons de debugage, on utilise des lettres particuliere du
+ * nom de l'etat, suivit d'un numero, s'il y a collision.
+ *
+ * @return a unique name
+ */
+ protected String generateStateUseCaseName(String name) {
- /**
- * Generate base.UseCasePage class
- * @param output
- * @param componentPackageName
- */
- private void generateUseCasePageClass(MonitorWriter output, StateModel model, String componentPackageName) throws IOException {
+ String ucsn = getHashStateName(name);
+
+ // test already assigned
+ String uniqueucsn = ucsn;
+ int num = 2;
+ while(assignedUseCaseStateNames.contains(uniqueucsn)) {
+ uniqueucsn = new StringBuffer(ucsn).append(num++).toString();
+ }
+
+ assignedUseCaseStateNames.add(uniqueucsn);
+
+ return uniqueucsn;
+ }
+
+ /**
+ * Hash a state name.
+ *
+ * On prend la premiere lettre de chaque mot.
+ *
+ * ContactList -> cl
+ * contactList -> cl
+ * ContactListPage -> clp
+ *
+ * @param name
+ * @return hashed state name
+ */
+ protected String getHashStateName(String name) {
+
+ // bug si moins de 1 caractere
+ if(name == null || name.length()<1) {
+ return name;
+ }
+
+ StringBuffer sb = new StringBuffer();
+
+ // on prend la premiere lettre
+ sb.append(Character.toLowerCase(name.charAt(0)));
+
+ // ensuite, on prend les majuscules
+ for(int i = 1 ; i < name.length() ; ++i) {
+
+ // si maj
+ if(Character.isUpperCase(name.charAt(i))) {
+ sb.append(Character.toLowerCase(name.charAt(i)));
+ }
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Generate the engine use case class.
+ *
+ * Need to be generated inside client webapp directory to be analysed by
+ * tapestry (annotations)
+ *
+ * @param model model
+ * @param chart chart
+ */
+ protected void generateUseCaseEngineFromModel(StateModel model,StateModelStateChart chart,File destDir) throws IOException {
+ String componentPackageName = getPackageFromComponents(chart);
+
+ // UseCasePage
+ String filename = (componentPackageName + ".UseCasePage").replace('.', File.separatorChar) + ".java";
+ File outputFile = getDestinationFile(destDir, filename);
+ if (getOverwrite() || !isNewerThanSource(outputFile)) {
+ try {
+ StringWriter out = new StringWriter();
+ MonitorWriter monitorOut = new MonitorWriter(out);
+ // generate UseCasePage class
+ generateUseCasePageClass(monitorOut,model,componentPackageName);
+ write(outputFile, monitorOut);
+ } catch (Exception e) {
+ log.warn("Erreur lors de la génération du fichier UseCasePage",e);
+ throw new RuntimeException(
+ "Erreur lors de la génération du fichier UseCasePage", e);
+ }
+ }
+
+ // UseCaseMap
+ filename = (componentPackageName + ".UseCaseMap").replace('.', File.separatorChar) + ".java";
+ outputFile = getDestinationFile(destDir, filename);
+ if (getOverwrite() || !isNewerThanSource(outputFile)) {
+ try {
+ StringWriter out = new StringWriter();
+ MonitorWriter monitorOut = new MonitorWriter(out);
+ // generate UseCasePage class
+ generateUseCaseMapClass(monitorOut,componentPackageName);
+ write(outputFile, monitorOut);
+ } catch (Exception e) {
+ log.warn("Erreur lors de la génération du fichier UseCaseMap",e);
+ throw new RuntimeException(
+ "Erreur lors de la génération du fichier UseCaseMap", e);
+ }
+ }
+ }
+
+ /**
+ * Generate base.UseCasePage class
+ * @param output
+ * @param componentPackageName
+ */
+ private void generateUseCasePageClass(MonitorWriter output, StateModel model, String componentPackageName) throws IOException {
/*{package <%=componentPackageName%>;
import org.apache.tapestry5.Link;
@@ -456,89 +456,89 @@
import org.apache.tapestry5.services.Request;
public abstract class UseCasePage}*/
-
- // ajoute un heritage si il a ete specifie dans un fichier de propriete
- Map<String,String> tagValues = model.getTagValues();
- if(tagValues != null) {
- String tagUseCaseEngineExtendedClass = tagValues.get("usecaseengineextendedclass");
- if(tagUseCaseEngineExtendedClass != null) {
- /*{ extends <%=tagUseCaseEngineExtendedClass%>}*/
- }
- }
+ // ajoute un heritage si il a ete specifie dans un fichier de propriete
+ Map<String,String> tagValues = model.getTagValues();
+ if(tagValues != null) {
+ String tagUseCaseEngineExtendedClass = tagValues.get("usecaseengineextendedclass");
+ if(tagUseCaseEngineExtendedClass != null) {
+ /*{ extends <%=tagUseCaseEngineExtendedClass%>}*/
+ }
+ }
+
/*{ implements LinkFactoryListener {
- private static final String UC_PARAMETER_NAME = "UC";
- private static final String UC_PARAMETER_SEPARATOR = ":";
-
- @ApplicationState
- private UseCaseMap useCaseManager;
- private boolean useCaseManagerExists;
-
- @Inject
- @Service("LinkFactory")
- private LinkFactory _linkFactory;
-
- @Inject
- @Service("Request")
- private Request _request;
+ private static final String UC_PARAMETER_NAME = "UC";
+ private static final String UC_PARAMETER_SEPARATOR = ":";
+
+ @ApplicationState
+ private UseCaseMap useCaseManager;
+ private boolean useCaseManagerExists;
+
+ @Inject
+ @Service("LinkFactory")
+ private LinkFactory _linkFactory;
+
+ @Inject
+ @Service("Request")
+ private Request _request;
- private String UCName;
-
- public void onActivate() {
- _linkFactory.addListener(this);
-
- UCName = _request.getParameter(UC_PARAMETER_NAME);
- }
-
- protected abstract String getUseCaseName();
-
- /**
- * Create stack if not exists
- *)
- protected void init() {
- if(!useCaseManagerExists) {
- useCaseManager = new UseCaseMap();
- }
- }
- /**
- * Enter in a new sub use case
- *)
- protected void enterUseCase() {
- init();
- // current
- String currentUCN = UCName;
- // new
- UCName = (currentUCN == null) ? getUseCaseName() : currentUCN + UC_PARAMETER_SEPARATOR + getUseCaseName();
- useCaseManager.enterSubUseCase(UCName, currentUCN, this);
- }
-
- /**
- * Leave a sub use case
- *)
- protected UseCasePage leaveUseCase() {
- init();
-
- UseCasePage nextPage = null;
-
- // current UCN
- String UC = UCName;
+ private String UCName;
+
+ public void onActivate() {
+ _linkFactory.addListener(this);
+
+ UCName = _request.getParameter(UC_PARAMETER_NAME);
+ }
+
+ protected abstract String getUseCaseName();
+
+ /**
+ * Create stack if not exists
+ *)
+ protected void init() {
+ if(!useCaseManagerExists) {
+ useCaseManager = new UseCaseMap();
+ }
+ }
+ /**
+ * Enter in a new sub use case
+ *)
+ protected void enterUseCase() {
+ init();
+ // current
+ String currentUCN = UCName;
+ // new
+ UCName = (currentUCN == null) ? getUseCaseName() : currentUCN + UC_PARAMETER_SEPARATOR + getUseCaseName();
+ useCaseManager.enterSubUseCase(UCName, currentUCN, this);
+ }
+
+ /**
+ * Leave a sub use case
+ *)
+ protected UseCasePage leaveUseCase() {
+ init();
+
+ UseCasePage nextPage = null;
+
+ // current UCN
+ String UC = UCName;
- // get state
- Object[] response = useCaseManager.leaveUseCase(UC);
-
- // if null, return null, don't change page
- if(response != null) {
- // get UCN before enter this one
- UCName = (String) response[0];
-
- nextPage = (UseCasePage) response[1];
- }
+ // get state
+ Object[] response = useCaseManager.leaveUseCase(UC);
+
+ // if null, return null, don't change page
+ if(response != null) {
+ // get UCN before enter this one
+ UCName = (String) response[0];
+
+ nextPage = (UseCasePage) response[1];
+ }
- return nextPage;
- }
+ return nextPage;
+ }
- /*
+ /*
* @see org.apache.tapestry5.internal.services.LinkFactoryListener#createdComponentEventLink(org.apache.tapestry5.Link)
*)
@Override
@@ -555,61 +555,61 @@
// action
addUCParameter(_link);
}
-
- protected void addUCParameter(Link _link) {
- if(_link.getParameterValue(UC_PARAMETER_NAME) == null) {
+
+ protected void addUCParameter(Link _link) {
+ if(_link.getParameterValue(UC_PARAMETER_NAME) == null) {
- if(UCName != null) {
- _link.addParameter(UC_PARAMETER_NAME, UCName);
- }
- }
- }
+ if(UCName != null) {
+ _link.addParameter(UC_PARAMETER_NAME, UCName);
+ }
+ }
+ }
}
}*/
- }
-
- /**
- * Generate base.UseCaseMap class
- * @param output
- * @param componentPackageName
- */
- private void generateUseCaseMapClass(MonitorWriter output, String componentPackageName) throws IOException {
+ }
+
+ /**
+ * Generate base.UseCaseMap class
+ * @param output
+ * @param componentPackageName
+ */
+ private void generateUseCaseMapClass(MonitorWriter output, String componentPackageName) throws IOException {
/*{package <%=componentPackageName%>;
import java.util.HashMap;
import java.util.Map;
public class UseCaseMap {
-
- /**
- * Map (state name -> state instance)
- *)
- private Map<String,Object[]> mapUseCase;
-
- /**
- * Constructor
- *)
- public UseCaseMap () {
- mapUseCase = new HashMap<String,Object[]>();
- }
-
- /**
- * New sub use case
- *)
- public void enterSubUseCase(String newUseCaseName, String previousUseCaseName, Object state) {
- mapUseCase.put(newUseCaseName,new Object[]{previousUseCaseName,state});
- }
-
- /**
- * Finish a subusecase
- *
- * Return the state that init the subuse case
- * @return a state
- *)
- public Object[] leaveUseCase(String useCaseName) {
- return mapUseCase.get(useCaseName);
- }
+
+ /**
+ * Map (state name -> state instance)
+ *)
+ private Map<String,Object[]> mapUseCase;
+
+ /**
+ * Constructor
+ *)
+ public UseCaseMap () {
+ mapUseCase = new HashMap<String,Object[]>();
+ }
+
+ /**
+ * New sub use case
+ *)
+ public void enterSubUseCase(String newUseCaseName, String previousUseCaseName, Object state) {
+ mapUseCase.put(newUseCaseName,new Object[]{previousUseCaseName,state});
+ }
+
+ /**
+ * Finish a subusecase
+ *
+ * Return the state that init the subuse case
+ * @return a state
+ *)
+ public Object[] leaveUseCase(String useCaseName) {
+ return mapUseCase.get(useCaseName);
+ }
}
}*/
- }
+ }
}
1
0
Author: chatellier
Date: 2009-04-09 12:59:21 +0000 (Thu, 09 Apr 2009)
New Revision: 1418
Modified:
topia-service/trunk/pom.xml
Log:
miss (wrong version :) )
Modified: topia-service/trunk/pom.xml
===================================================================
--- topia-service/trunk/pom.xml 2009-04-09 12:34:53 UTC (rev 1417)
+++ topia-service/trunk/pom.xml 2009-04-09 12:59:21 UTC (rev 1418)
@@ -50,7 +50,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
- <version>1.1.120</version>
+ <version>1.1.110</version>
<scope>test</scope>
</dependency>
1
0
Author: chatellier
Date: 2009-04-09 12:34:53 +0000 (Thu, 09 Apr 2009)
New Revision: 1417
Modified:
topia-service/trunk/pom.xml
Log:
Update versions, fix xsd location
Modified: topia-service/trunk/pom.xml
===================================================================
--- topia-service/trunk/pom.xml 2009-04-09 12:33:58 UTC (rev 1416)
+++ topia-service/trunk/pom.xml 2009-04-09 12:34:53 UTC (rev 1417)
@@ -1,5 +1,5 @@
<?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">
+<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -35,7 +35,7 @@
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
- <version>2.4.0</version>
+ <version>2.4.1</version>
<scope>compile</scope>
</dependency>
@@ -50,7 +50,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
- <version>1.1.107</version>
+ <version>1.1.120</version>
<scope>test</scope>
</dependency>
@@ -80,9 +80,9 @@
<labs.project>topia</labs.project>
<!-- libs versions -->
- <topia.version>2.1.3</topia.version>
+ <topia.version>2.1.4</topia.version>
<generator.version>0.64</generator.version>
- <lutinutil.version>1.0.3</lutinutil.version>
+ <lutinutil.version>1.0.4</lutinutil.version>
</properties>
1
0