Eugene-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
October 2009
- 5 participants
- 40 discussions
28 Oct '09
Author: echatellier
Date: 2009-10-28 12:06:00 +0100 (Wed, 28 Oct 2009)
New Revision: 664
Modified:
trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorTask.java
Log:
Performance to array with correct size
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorTask.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorTask.java 2009-10-28 10:33:37 UTC (rev 663)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorTask.java 2009-10-28 11:06:00 UTC (rev 664)
@@ -369,7 +369,7 @@
for (Generator generator : generators) {
if (generator != null) {
- File[] modelFilesArray = modelFiles.toArray(new File[0]);
+ File[] modelFilesArray = modelFiles.toArray(new File[modelFiles.size()]);
log("Applying " + generator.getClass().getSimpleName()
+ " on " + Arrays.toString(modelFilesArray),
Project.MSG_INFO);
1
0
r663 - in branches/1.1.0-Javabuilder: eugene/src/main/java/org/nuiton/eugene maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin
by fdesbois@users.nuiton.org 28 Oct '09
by fdesbois@users.nuiton.org 28 Oct '09
28 Oct '09
Author: fdesbois
Date: 2009-10-28 11:33:37 +0100 (Wed, 28 Oct 2009)
New Revision: 663
Modified:
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ModelReader.java
branches/1.1.0-Javabuilder/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java
Log:
Add better generic gestion in plugin (to avoid warnings)
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java 2009-10-27 17:18:21 UTC (rev 662)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java 2009-10-28 10:33:37 UTC (rev 663)
@@ -35,6 +35,8 @@
*
* Created: 5 août 2004
*
+ * @param <M> Model associated to the generator
+ *
* @author Cedric Pineau <pineau(a)codelutin.com>
* @version $Revision$
*
@@ -63,16 +65,16 @@
protected long lastModifiedSource = 0;
- protected Generator parent = null;
+ protected Generator<M> parent = null;
public Generator() {
}
- public Generator(Generator parent) {
+ public Generator(Generator<M> parent) {
setParent(parent);
}
- public void setParent(Generator parent) {
+ public void setParent(Generator<M> parent) {
this.parent = parent;
setEncoding(parent.getEncoding());
}
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ModelReader.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ModelReader.java 2009-10-27 17:18:21 UTC (rev 662)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ModelReader.java 2009-10-28 10:33:37 UTC (rev 663)
@@ -11,6 +11,7 @@
*
* Created: 26 oct. 2009
*
+ * @param <M> Model to create from reading input files
* @author fdesbois
* @version $Revision$
*
Modified: branches/1.1.0-Javabuilder/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java
===================================================================
--- branches/1.1.0-Javabuilder/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java 2009-10-27 17:18:21 UTC (rev 662)
+++ branches/1.1.0-Javabuilder/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java 2009-10-28 10:33:37 UTC (rev 663)
@@ -167,14 +167,20 @@
getLog().info("will treate model file : " + m);
}
}
+ ModelReader<?> modelReader = getReader();
+ generate(modelFiles, modelReader);
- ModelReader modelReader = getReader();
+ fixCompileSourceRoots();
+ }
+
+ protected <M extends Model> void generate(File[] modelFiles, ModelReader<M> modelReader) throws MojoFailureException, MojoExecutionException {
+
if (modelReader == null) {
// can skip
getLog().warn("no reader to use");
return;
}
- Model model = modelReader.read(modelFiles);
+ M model = modelReader.read(modelFiles);
List<String> packages = getPackagesToGenerate();
@@ -184,9 +190,9 @@
getLog().info(" generating only for packages " + packages);
}
- List<Generator> generators = getGenerators(packages, modelReader);
+ List<Generator<M>> generators = getGenerators(packages, modelReader);
- for (Generator generator : generators) {
+ for (Generator<M> generator : generators) {
getLog().info("Apply " + generator.getClass().getSimpleName() + " generator");
//TC-20090829 fix when loading more than one model together...
@@ -199,8 +205,6 @@
// generator.generate(modelFile, destDirGen);
// }
}
-
- fixCompileSourceRoots();
}
@Override
@@ -282,11 +286,11 @@
// return modelFiles.toArray(new File[modelFiles.size()]);
// }
- protected ModelReader getReader() throws MojoFailureException, MojoExecutionException {
- ModelReader modelReader = null;
+ protected ModelReader<?> getReader() throws MojoFailureException, MojoExecutionException {
+ ModelReader<?> modelReader = null;
try {
ClassLoader fixedClassLoader = fixClassLoader();
- modelReader = (ModelReader) Class.forName(reader,
+ modelReader = (ModelReader<?>) Class.forName(reader,
true, fixedClassLoader).newInstance();
} catch (InstantiationException eee) {
throw new MojoFailureException("Can't instantiate reader : " + reader, eee);
@@ -298,19 +302,21 @@
return modelReader;
}
- protected List<Generator> getGenerators(List<String> generatedPackagesAsList, ModelReader modelReader)
+ @SuppressWarnings("unchecked")
+ protected <M extends Model> List<Generator<M>>
+ getGenerators(List<String> generatedPackagesAsList, ModelReader<M> modelReader)
throws MojoFailureException, MojoExecutionException {
// init generators
Properties generatorProperties = new Properties();
generatorProperties.setProperty("defaultPackage", defaultPackage);
- List<Generator> generators = new ArrayList<Generator>();
+ List<Generator<M>> generators = new ArrayList<Generator<M>>();
String[] templatesNames = templates.split(",");
ClassLoader fixedClassLoader = fixClassLoader();
for (String templateName : templatesNames) {
// remove trailing spaces
templateName = templateName.trim();
try {
- Generator generator = (Generator) Class.forName(templateName,
+ Generator<M> generator = (Generator<M>) Class.forName(templateName,
true, fixedClassLoader).newInstance();
// configuration
generator.setExcludeTemplates(Arrays.asList(excludeTemplates));
1
0
27 Oct '09
Author: fdesbois
Date: 2009-10-27 18:18:21 +0100 (Tue, 27 Oct 2009)
New Revision: 662
Added:
branches/1.1.0-Javabuilder/eugene-test/nbactions.xml
branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestReader.java
branches/1.1.0-Javabuilder/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java
Modified:
branches/1.1.0-Javabuilder/eugene-test/pom.xml
branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/JavaGenerator.java
branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java
branches/1.1.0-Javabuilder/eugene-test/src/main/resources/log4j.properties
branches/1.1.0-Javabuilder/eugene-test/src/test/resources/log4j.properties
branches/1.1.0-Javabuilder/eugene/pom.xml
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/JavaBuilder.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModel.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java
Log:
- Add extensions for ObjectModel
- Add utils method for Import managment
- Refactor JavaBuilder to use extension and utils method for imports
- Add TestReader to create a model from scratch with TestBuilder
- Correction some errors in JavaGenerator and better managment for imports
Modified: branches/1.1.0-Javabuilder/eugene/pom.xml
===================================================================
--- branches/1.1.0-Javabuilder/eugene/pom.xml 2009-10-27 10:32:23 UTC (rev 661)
+++ branches/1.1.0-Javabuilder/eugene/pom.xml 2009-10-27 17:18:21 UTC (rev 662)
@@ -86,6 +86,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+ <scope>test</scope>
</dependency>
</dependencies>
@@ -168,7 +169,7 @@
</roles>
</developer>
</developers>
-
+
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
<!-- ************************************************************* -->
@@ -178,7 +179,7 @@
<!-- extra files to include in release -->
<redmine.releaseFiles>${redmine.libReleaseFiles}</redmine.releaseFiles>
</properties>
-
+
<build>
<defaultGoal>install</defaultGoal>
@@ -197,7 +198,7 @@
<!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
-
+
<profiles>
<!-- perform only on a release stage when using the maven-release-plugin -->
<profile>
@@ -210,7 +211,7 @@
</activation>
<build>
<plugins>
-
+
<!-- launch in a release the assembly automaticly -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
@@ -231,7 +232,7 @@
</descriptorRefs>
</configuration>
</plugin>
-
+
</plugins>
</build>
</profile>
@@ -239,3 +240,5 @@
</project>
+
+
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java 2009-10-27 10:32:23 UTC (rev 661)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java 2009-10-27 17:18:21 UTC (rev 662)
@@ -21,9 +21,13 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.nuiton.eugene.models.Model;
import org.nuiton.eugene.models.object.ObjectModel;
@@ -580,4 +584,52 @@
return result;
}
+
+ /**
+ * Suppress packageName from a fullQualifiedName, even if it contains List, Map or other generics.
+ * See JUnit test for matching expressions.
+ * @see org.nuiton.eugene.GeneratorUtilTest
+ * @param str FullQualifiedName for an attribute type (for exemple)
+ * @return the simple name associated to the str given
+ */
+ public static String getSimpleName(String str) {
+ return str.replaceAll("\\w+\\.","");
+ }
+
+ public static Set<String> getTypesList(String str) {
+
+ String regex = "^(([\\w\\s\\?]*\\s))?([\\w\\.]+)((<)(.*)(>))?(\\(\\))?$";
+ Pattern p = Pattern.compile(regex);
+ Matcher m = p.matcher(str);
+
+ Set<String> results = new HashSet<String>();
+
+ if (m.find()) {
+ results.add(m.group(3));
+ if (m.group(6) != null) { // cas du type generic
+ for (String onepart : m.group(6).split("(\\s*,\\s*)")) {
+ results.addAll(getTypesList(onepart));
+ }
+ }
+ /*if (m.group(2) != null) { // cas du extend ou du new
+ result += m.group(2);
+ }
+ result += m.group(4);
+ if (m.group(7) != null) { // cas du type generic
+ result += m.group(6); // <
+ String sep = "";
+ for (String onepart : m.group(7).split("(\\s*,\\s*)")) {
+ result += sep + getSimpleName(onepart);
+ sep = ", ";
+ }
+ result += m.group(8); // >
+ }
+ if (m.group(9) != null) { // cas des () pour un new
+ result += m.group(9);
+ }*/
+ }
+
+ return results;
+ }
+
} // GeneratorUtil
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/JavaBuilder.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/JavaBuilder.java 2009-10-27 10:32:23 UTC (rev 661)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/JavaBuilder.java 2009-10-27 17:18:21 UTC (rev 662)
@@ -47,6 +47,11 @@
private static ObjectModelBuilderHelper helper = new ObjectModelBuilderHelper();
+ public JavaBuilder(String modelName) {
+ this.objectModel = new ObjectModelImpl();
+ this.objectModel.setName(modelName);
+ }
+
public JavaBuilder() {
this.objectModel = new ObjectModelImpl();
}
@@ -59,13 +64,22 @@
return helper;
}
+ protected ImportsManager getImportsManager(ObjectModelClassifier classifier) {
+ ImportsManager manager = objectModel.getExtension(classifier.getQualifiedName(), ImportsManager.class);
+ if (manager == null) {
+ manager = new ImportsManager();
+ objectModel.addExtension(classifier.getQualifiedName(), manager);
+ }
+ return manager;
+ }
+
public void addImportForClassifier(ObjectModelClassifier classifier, String imports) {
- ImportsManager manager = objectModel.getImportsManager(classifier.getQualifiedName());
+ ImportsManager manager = getImportsManager(classifier);
manager.addImport(imports);
}
public void addImportForClassifier(ObjectModelClassifier classifier, Class<?> imports) {
- ImportsManager manager = objectModel.getImportsManager(classifier.getQualifiedName());
+ ImportsManager manager = getImportsManager(classifier);
manager.addImport(imports);
}
@@ -82,10 +96,14 @@
}
private ImportsManager setImports(ObjectModelClassifier classifier) {
- ImportsManager manager = objectModel.getImportsManager(classifier.getQualifiedName());
+ ImportsManager manager = getImportsManager(classifier);
// attributes
for (ObjectModelAttribute attribute : classifier.getAttributes()) {
- manager.addImport(attribute.getType());
+ if (log.isInfoEnabled()) {
+ log.info("attribute add import for : " + attribute.getType());
+ }
+ setImportsForType(manager, attribute.getType());
+ setImportsForType(manager, attribute.getDefaultValue());
}
// implemented interfaces
for (ObjectModelInterface interfacez : classifier.getInterfaces()) {
@@ -93,14 +111,20 @@
}
// operations
for (ObjectModelOperation operation : classifier.getOperations()) {
- manager.addImport(operation.getReturnType());
+ setImportsForType(manager, operation.getReturnType());
for (ObjectModelParameter parameter : operation.getParameters()) {
- manager.addImport(parameter.getType());
+ setImportsForType(manager, parameter.getType());
}
}
return manager;
}
+ private void setImportsForType(ImportsManager manager, String type) {
+ for (String oneType : GeneratorUtil.getTypesList(type)) {
+ manager.addImport(oneType);
+ }
+ }
+
public void build() {
}
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java 2009-10-27 10:32:23 UTC (rev 661)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java 2009-10-27 17:18:21 UTC (rev 662)
@@ -119,12 +119,6 @@
// generateFromModel
this.model = model;
- if (log.isDebugEnabled()) {
- log.debug("name : " + model.getName());
- log.debug("interfaces : " + model.getInterfaces().size());
- log.debug("classes : " + model.getClasses().size());
- }
-
//try {
String filename = getFilenameForModel(model);
generateFromElement(model, destDir, filename,
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModel.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModel.java 2009-10-27 10:32:23 UTC (rev 661)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModel.java 2009-10-27 17:18:21 UTC (rev 662)
@@ -122,11 +122,13 @@
public List<String> getComments();
/**
- * Return specific ImportsManager for a classifier
- *
- * @param qualifiedName of the classifier
- * @return the ImportsManager associated to the classifier, create a new one if not exist
+ * Get the extension associated to the reference (unique)
+ * @param <O> object type returned
+ * @param reference unique corresponding to the extension to get
+ * @param extensionClass class of the extension
+ * @return the object value for the extension
+ * @throws ClassCastException
*/
- public List<String> getImports(ObjectModelClassifier element);
+ public <O> O getExtension(String reference, Class<O> extensionClass) throws ClassCastException;
} //ObjectModel
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java 2009-10-27 10:32:23 UTC (rev 661)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java 2009-10-27 17:18:21 UTC (rev 662)
@@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
package org.nuiton.eugene.models.object.xml;
import java.util.ArrayList;
@@ -59,9 +58,11 @@
protected Map<String, ObjectModelEnumeration> enumerations = new HashMap<String, ObjectModelEnumeration>();
protected List<String> comments = new ArrayList<String>();
private Map<String, String> tagValues = new HashMap<String, String>();
-
- private Map<String, ImportsManager> importsManagers = new HashMap<String, ImportsManager>();
-
+ /**
+ * Used to add others specific object to the model
+ * The key defined must be unique to get the significative extension associated to
+ */
+ private Map<String, Object> extensions = new HashMap<String, Object>();
private static Log log = LogFactory.getLog(ObjectModelImpl.class);
public void setName(String name) {
@@ -75,18 +76,14 @@
clazz.setObjectModelImpl(this);
if (!clazz.isExtern()) {
- ObjectModelElementImpl initialElement = (ObjectModelElementImpl) classes
- .get(clazz.getQualifiedName());
+ ObjectModelElementImpl initialElement = (ObjectModelElementImpl) classes.get(clazz.getQualifiedName());
if (initialElement == null) {
classes.put(clazz.getQualifiedName(), clazz);
classifiers.put(clazz.getQualifiedName(), clazz);
} else {
if (!(initialElement instanceof ObjectModelClassImpl)) {
throw new IllegalArgumentException(
- "\""
- + clazz
- + "\" is incompatible with already defined element \""
- + initialElement + "\"");
+ "\"" + clazz + "\" is incompatible with already defined element \"" + initialElement + "\"");
}
ObjectModelClassImpl initialClazz = (ObjectModelClassImpl) initialElement;
@@ -107,18 +104,14 @@
clazz.setObjectModelImpl(this);
if (!clazz.isExtern()) {
- ObjectModelElementImpl initialElement = (ObjectModelElementImpl) classes
- .get(clazz.getQualifiedName());
+ ObjectModelElementImpl initialElement = (ObjectModelElementImpl) classes.get(clazz.getQualifiedName());
if (initialElement == null) {
classes.put(clazz.getQualifiedName(), clazz);
classifiers.put(clazz.getQualifiedName(), clazz);
} else {
if (!(initialElement instanceof ObjectModelAssociationClassImpl)) {
throw new IllegalArgumentException(
- "\""
- + clazz
- + "\" is incompatible with already defined element \""
- + initialElement + "\"");
+ "\"" + clazz + "\" is incompatible with already defined element \"" + initialElement + "\"");
}
ObjectModelAssociationClassImpl initialClazz = (ObjectModelAssociationClassImpl) initialElement;
@@ -165,8 +158,7 @@
*/
public ObjectModelClassifier getClassifier(String qualifiedClassifierName) {
return (qualifiedClassifierName == null ? null
- : (ObjectModelClassifier) classifiers
- .get(qualifiedClassifierName));
+ : (ObjectModelClassifier) classifiers.get(qualifiedClassifierName));
}
/**
@@ -231,18 +223,14 @@
interfacez.setObjectModelImpl(this);
if (!interfacez.isExtern()) {
- ObjectModelElementImpl initialElement = (ObjectModelElementImpl) interfaces
- .get(interfacez.getQualifiedName());
+ ObjectModelElementImpl initialElement = (ObjectModelElementImpl) interfaces.get(interfacez.getQualifiedName());
if (initialElement == null) {
interfaces.put(interfacez.getQualifiedName(), interfacez);
classifiers.put(interfacez.getQualifiedName(), interfacez);
} else {
if (!(initialElement instanceof ObjectModelInterfaceImpl)) {
throw new IllegalArgumentException(
- "\""
- + interfacez
- + "\" is incompatible with already defined element \""
- + initialElement + "\"");
+ "\"" + interfacez + "\" is incompatible with already defined element \"" + initialElement + "\"");
}
ObjectModelInterfaceImpl initialInterfacez = (ObjectModelInterfaceImpl) initialElement;
@@ -358,8 +346,7 @@
// regénérer l'objet
}
for (it = additionalClazzifier.getOperations().iterator(); it.hasNext();) {
- ObjectModelOperationImpl operation = (ObjectModelOperationImpl) it
- .next();
+ ObjectModelOperationImpl operation = (ObjectModelOperationImpl) it.next();
if (!contains(initialClazzifier.getOperations(), operation)) {
initialClazzifier.operations.add(operation);
}
@@ -370,20 +357,17 @@
initialClazzifier.comments.add(comment);
}
}
- for (it = additionalClazzifier.getStereotypes().iterator(); it
- .hasNext();) {
+ for (it = additionalClazzifier.getStereotypes().iterator(); it.hasNext();) {
String stereotype = (String) it.next();
if (!initialClazzifier.getStereotypes().contains(stereotype)) {
initialClazzifier.stereotypes.add(stereotype);
}
}
- for (it = additionalClazzifier.getTagValues().keySet().iterator(); it
- .hasNext();) {
+ for (it = additionalClazzifier.getTagValues().keySet().iterator(); it.hasNext();) {
String tagName = (String) it.next();
if (!initialClazzifier.getTagValues().containsKey(tagName)) {
- initialClazzifier.tagValues.put(tagName, additionalClazzifier
- .getTagValue(tagName));
+ initialClazzifier.tagValues.put(tagName, additionalClazzifier.getTagValue(tagName));
}
}
}
@@ -403,8 +387,7 @@
mergeClassifiers(initialClazz, additionalClazz);
for (it = additionalClazz.getAttributes().iterator(); it.hasNext();) {
- ObjectModelAttributeImpl attribute = (ObjectModelAttributeImpl) it
- .next();
+ ObjectModelAttributeImpl attribute = (ObjectModelAttributeImpl) it.next();
if (!contains(initialClazz.getAttributes(), attribute)) {
initialClazz.attributes.put(attribute.getName(), attribute);
initialClazz.orderedAttributes.add(attribute);
@@ -425,10 +408,8 @@
ObjectModelAssociationClassImpl additionalAssocClazz) {
mergeClasses(initialAssocClazz, additionalAssocClazz);
Iterator it;
- for (it = additionalAssocClazz.participantsRefs.iterator(); it
- .hasNext();) {
- ObjectModeImplAssociationClassParticipant participant = (ObjectModeImplAssociationClassParticipant) it
- .next();
+ for (it = additionalAssocClazz.participantsRefs.iterator(); it.hasNext();) {
+ ObjectModeImplAssociationClassParticipant participant = (ObjectModeImplAssociationClassParticipant) it.next();
if (!contains(initialAssocClazz.participantsRefs, participant)) {
initialAssocClazz.participantsRefs.add(participant);
}
@@ -496,22 +477,32 @@
return (tagValue == null ? null : (String) tagValues.get(tagValue));
}
- @Override
- public List<String> getImports(ObjectModelClassifier classifier) {
- ImportsManager manager = importsManagers.get(classifier.getQualifiedName());
- if (manager == null) {
- throw new IllegalArgumentException("ImportsManager is not defined for classifier '" +
- classifier.getQualifiedName() + "'");
- }
- return manager.getImports(classifier.getPackageName());
+ /**
+ * Add a new extension to the model.
+ * This method overwrite the value object if the reference already exist.
+ * @param <O> object type
+ * @param reference unique key to reference the extension in the model
+ * @param extension object value corresponding to the extension
+ */
+ public <O> void addExtension(String reference, O extension) {
+ extensions.put(reference, extension);
}
- public ImportsManager getImportsManager(String qualifiedName) {
- ImportsManager manager = importsManagers.get(qualifiedName);
- if (manager == null) {
- manager = new ImportsManager();
- importsManagers.put(qualifiedName, manager);
+ /**
+ * Get the extension associated to the reference (unique)
+ * @param <O> object type returned
+ * @param reference unique corresponding to the extension to get
+ * @param extensionClass class of the extension
+ * @return the object value for the extension
+ * @throws ClassCastException
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public <O> O getExtension(String reference, Class<O> extensionClass) throws ClassCastException {
+ Object result = extensions.get(reference);
+ if (result != null && !extensionClass.isAssignableFrom(result.getClass())) {
+ throw new ClassCastException("Invalid cast for " + extensionClass.getName());
}
- return manager;
+ return (O) result;
}
}
Added: branches/1.1.0-Javabuilder/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java (rev 0)
+++ branches/1.1.0-Javabuilder/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java 2009-10-27 17:18:21 UTC (rev 662)
@@ -0,0 +1,143 @@
+
+package org.nuiton.eugene;
+
+import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author fdesbois
+ */
+public class GeneratorUtilTest {
+
+ private static Log log = LogFactory.getLog(GeneratorUtilTest.class);
+
+ public GeneratorUtilTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+
+ /**
+ * Test of getSimpleName method, of class GeneratorUtil.
+ */
+ @Test
+ public void testGetSimpleName() {
+ System.out.println("getSimpleName");
+
+ String str = "List";
+ String expResult = "List";
+ String result = GeneratorUtil.getSimpleName(str);
+ log.info(str + " -> " + result);
+ assertEquals(expResult, result);
+
+ str = "java.util.Regex";
+ expResult = "Regex";
+ result = GeneratorUtil.getSimpleName(str);
+ log.info(str + " -> " + result);
+ assertEquals(expResult, result);
+
+ str = "java.util.List<? extends org.chorem.bonzoms.Bonzoms>";
+ expResult = "List<? extends Bonzoms>";
+ result = GeneratorUtil.getSimpleName(str);
+ log.info(str + " -> " + result);
+ assertEquals(expResult, result);
+
+ str = "java.util.List<org.chorem.jtimer.Jtimer>";
+ expResult = "List<Jtimer>";
+ result = GeneratorUtil.getSimpleName(str);
+ log.info(str + " -> " + result);
+ assertEquals(expResult, result);
+
+ str = "java.util.Set<java.util.Collection<java.util.Collection<java.util.Collection" +
+ "<java.lang.String>>>>";
+ expResult = "Set<Collection<Collection<Collection<String>>>>";
+ result = GeneratorUtil.getSimpleName(str);
+ log.info(str + " -> " + result);
+ assertEquals(expResult, result);
+
+ str = "java.util.Map<org.chorem.jtimer.Jtimer, java.util.Collection<java.lang.String>>";
+ expResult = "Map<Jtimer, Collection<String>>";
+ result = GeneratorUtil.getSimpleName(str);
+ log.info(str + " -> " + result);
+ assertEquals(expResult, result);
+
+ str = "new java.util.HashMap<org.chorem.jtimer.Jtimer, T extends java.lang.String>()";
+ expResult = "new HashMap<Jtimer, T extends String>()";
+ result = GeneratorUtil.getSimpleName(str);
+ log.info(str + " -> " + result);
+ assertEquals(expResult, result);
+
+ str = "Class<O>";
+ expResult = "Class<O>";
+ result = GeneratorUtil.getSimpleName(str);
+ log.info(str + " -> " + result);
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testGetTypesList() {
+ String str = "List";
+ Set<String> results = GeneratorUtil.getTypesList(str);
+ log.info(str + " -> " + results);
+ assertEquals(results.size(), 1);
+
+ str = "java.util.Regex";
+ results = GeneratorUtil.getTypesList(str);
+ log.info(str + " -> " + results);
+ assertEquals(results.size(), 1);
+
+ str = "java.util.List<? extends org.chorem.bonzoms.Bonzoms>";
+ results = GeneratorUtil.getTypesList(str);
+ log.info(str + " -> " + results);
+ assertEquals(results.size(), 2);
+
+ str = "java.util.List<org.chorem.jtimer.Jtimer>";
+ results = GeneratorUtil.getTypesList(str);
+ log.info(str + " -> " + results);
+ assertEquals(results.size(), 2);
+
+ str = "java.util.Set<java.util.Collection<java.util.Collection<java.util.Collection" +
+ "<java.lang.String>>>>";
+ results = GeneratorUtil.getTypesList(str);
+ log.info(str + " -> " + results);
+ assertEquals(results.size(), 3);
+
+ str = "java.util.Map<org.chorem.jtimer.Jtimer, java.util.Collection<java.lang.String>>";
+ results = GeneratorUtil.getTypesList(str);
+ log.info(str + " -> " + results);
+ assertEquals(results.size(), 4);
+
+ str = "new java.util.HashMap<org.chorem.jtimer.Jtimer, T extends java.lang.String>()";
+ results = GeneratorUtil.getTypesList(str);
+ log.info(str + " -> " + results);
+ assertEquals(results.size(), 3);
+
+ str = "java.util.Map<org.chorem.jtimer.Jtimer, java.util.Collection<java.lang.String>>";
+ results = GeneratorUtil.getTypesList(str);
+ log.info(str + " -> " + results);
+ assertEquals(results.size(), 4);
+ }
+
+}
\ No newline at end of file
Added: branches/1.1.0-Javabuilder/eugene-test/nbactions.xml
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/nbactions.xml (rev 0)
+++ branches/1.1.0-Javabuilder/eugene-test/nbactions.xml 2009-10-27 17:18:21 UTC (rev 662)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<actions>
+ <action>
+ <actionName>CUSTOM-debug maven</actionName>
+ <displayName>debug maven</displayName>
+ <goals>
+ <goal>clean</goal>
+ <goal>install</goal>
+ <goal>-e</goal>
+ </goals>
+ </action>
+ </actions>
Modified: branches/1.1.0-Javabuilder/eugene-test/pom.xml
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/pom.xml 2009-10-27 10:32:23 UTC (rev 661)
+++ branches/1.1.0-Javabuilder/eugene-test/pom.xml 2009-10-27 17:18:21 UTC (rev 662)
@@ -110,6 +110,23 @@
<goal>generate</goal>
</goals>
</execution>
+ <execution>
+ <id>Test Java Generator</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+ <reader>org.nuiton.eugene.test.generator.TestReader</reader>
+ <includes>**/*.objectmodel</includes>
+ <templates>org.nuiton.eugene.test.generator.JavaGenerator</templates>
+ <defaultPackage>org.nuiton.eugene.test</defaultPackage>
+ <extraClassPathDirectory>target/classes</extraClassPathDirectory>
+ <generateResources>
+ <input>src/main/models</input>
+ </generateResources>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
</executions>
</plugin>
Modified: branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/JavaGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/JavaGenerator.java 2009-10-27 10:32:23 UTC (rev 661)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/JavaGenerator.java 2009-10-27 17:18:21 UTC (rev 662)
@@ -1,11 +1,16 @@
package org.nuiton.eugene.test.generator;
+import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.GeneratorUtil;
+import org.nuiton.eugene.ImportsManager;
import org.nuiton.eugene.ObjectModelGenerator;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
import org.nuiton.eugene.models.object.ObjectModelClass;
@@ -29,20 +34,20 @@
*/
public class JavaGenerator extends ObjectModelGenerator {
+ private static final Log log = LogFactory.getLog(JavaGenerator.class);
+
@Override
public String getFilenameForClass(ObjectModelClass clazz) {
- return clazz.getName() + ".java";
+ return clazz.getQualifiedName().replace('.', File.separatorChar) + ".java";//return clazz.getName() + ".java";
}
@Override
- public void generateFromClassifier(Writer output, ObjectModelClassifier classifier) {
+ public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
+ if (log.isInfoEnabled()) {
+ log.info("generate : " + clazz.getName());
+ }
- }
-
- @Override
- public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
-
this.generateHeader(output, clazz); // Imports, package et documentation
String abstractStr = clazz.isAbstract() ? " abstract " : " ";
@@ -99,7 +104,8 @@
}*/
// potentiel crash si imports non defini
// dans ce cas, probleme de config utilisateur ! obligation de passer par un builder ?
- for (String imports : getModel().getImports(classifier)) {
+ ImportsManager manager = getModel().getExtension(classifier.getQualifiedName(), ImportsManager.class);
+ for (String imports : manager.getImports(classifier.getPackageName())) {
/*{import <%=imports%>;
}*/
}
@@ -110,7 +116,7 @@
for (ObjectModelAttribute attr : attributes) {
- if (!attr.getDocumentation().isEmpty()) {
+ if (attr.getDocumentation() != null && !attr.getDocumentation().isEmpty()) {
/*{ /**
* <%=attr.getDocumentation()%>
*)
@@ -125,10 +131,10 @@
String attrName = attr.getName();
String attrVisibility = attr.getVisibility();
- String attrType = getSimpleName(attr.getType());
+ String attrType = GeneratorUtil.getSimpleName(attr.getType());
String attrStatic = attr.isStatic() ? " static " : " ";
String attrFinal = attr.isFinal() ? " final " : " ";
- String attrValue = !attr.getDefaultValue().isEmpty() ? " = " + attr.getDefaultValue() : "";
+ String attrValue = !attr.getDefaultValue().isEmpty() ? " = " + GeneratorUtil.getSimpleName(attr.getDefaultValue()) : "";
/*{ <%=attrVisibility%><%=attrStatic%><%=attrFinal%><%=attrType%> <%=attrName%><%=attrValue%>;
}*/
@@ -140,7 +146,7 @@
String opName = op.getName();
/*{ /**
}*/
- if (!op.getDocumentation().isEmpty()) {
+ if (op.getDocumentation() != null && !op.getDocumentation().isEmpty()) {
String opDocumentation = op.getDocumentation();
/*{ * <%=opName%> : <%=opDocumentation%>
}*/
@@ -157,18 +163,18 @@
String opAbstract = op.isAbstract() ? " abstract " : "";
ObjectModelParameter returnParam = op.getReturnParameter();
- String opReturn = getSimpleName(returnParam.getType());
+ String opReturn = GeneratorUtil.getSimpleName(returnParam.getType());
if (!opReturn.equals("void")) {
String paramDocumentation = returnParam.getDocumentation();
/*{ * @return <%=paramDocumentation%>
}*/
}
-/*{ *)
- <%=opVisibility%><%=opStatic%><%=opAbstract%><%=opReturn%> <%=opName%>(}*/
+/*{ *)
+ <%=opVisibility%><%=opStatic%><%=opAbstract%> <%=opReturn%> <%=opName%>(}*/
String comma = "";
for (ObjectModelParameter param : params) {
String paramName = param.getName();
- String paramType = param.getType();
+ String paramType = GeneratorUtil.getSimpleName(param.getType());
/*{<%=comma%><%=paramType%> <%=paramName%>}*/
comma = ", ";
}
@@ -179,18 +185,17 @@
/*{<%=comma%><%=exception%>}*/
comma = ", ";
}
+
+ if (!op.getBodyCode().isEmpty()) {
+/*{ {<%=op.getBodyCode()%>}
+
+}*/
+ } else {
/*{;
}*/
+ }
}
}
-
- private static String getSimpleName(String qualifiedName) {
- String result = qualifiedName;
- int dot = qualifiedName.lastIndexOf(".");
- if (dot >- 1) {
- result = qualifiedName.substring(dot + 1);
- }
- return result;
- }
+
}
Modified: branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java 2009-10-27 10:32:23 UTC (rev 661)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java 2009-10-27 17:18:21 UTC (rev 662)
@@ -1,8 +1,6 @@
package org.nuiton.eugene.test.generator;
-import java.util.Date;
-import java.util.List;
import org.nuiton.eugene.JavaBuilder;
import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelOperation;
@@ -15,6 +13,10 @@
*/
public class TestBuilder extends JavaBuilder {
+ public TestBuilder() {
+ super("TestModel");
+ }
+
@Override
public void build() {
createRole();
@@ -23,35 +25,42 @@
private void createRole() {
ObjectModelClass roleClass = getHelper().createClass("Role", "org.chorem.bonzoms");
- this.addClassToModel(roleClass);
getHelper().addAttribute(roleClass, "name", "String");
- this.addImportForClassifier(roleClass, Date.class);
+ //this.addImportForClassifier(roleClass, Date.class);
getHelper().addAttribute(roleClass, "fromDate", "java.util.Date");
getHelper().addAttribute(roleClass, "thruDate", "java.util.Date");
+
+ this.addClassToModel(roleClass);
}
private void createPerson() {
ObjectModelClass personneClass = getHelper().createClass("Person", "org.chorem.bonzoms");
- this.addClassToModel(personneClass);
- getHelper().addAttribute(personneClass, "lastName", "String");
- getHelper().addAttribute(personneClass, "firstName", "String");
+ getHelper().addAttribute(personneClass, "lastName", "java.lang.String");
+ getHelper().addAttribute(personneClass, "firstName", "java.lang.String", "\"\"");
- this.addImportForClassifier(personneClass, List.class);
- getHelper().addAttribute(personneClass, "roles", "java.util.List<Role>");
+ //this.addImportForClassifier(personneClass, List.class);
+ getHelper().addAttribute(personneClass, "roles",
+ "java.util.List<org.chorem.bonzoms.Role>", "new java.util.ArrayList<org.chorem.bonzoms.Role>()");
ObjectModelOperation setLastName = getHelper().addOperation(personneClass, "setLastName", null, "String", "lastName");
- getHelper().setOperationBody(setLastName, "" /*{
- this.lastName = lastName;
- }*/);
+ getHelper().setOperationBody(setLastName, ""
+ /*{
+ this.lastName = lastName;
+ }*/
+ );
ObjectModelOperation getLastName = getHelper().addOperation(personneClass, "getLastName", "String");
- getHelper().setOperationBody(getLastName, "" /*{
- return this.lastName;
- }*/);
+ getHelper().setOperationBody(getLastName, ""
+ /*{
+ return this.lastName;
+ }*/
+ );
+
+ this.addClassToModel(personneClass);
}
}
Added: branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestReader.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestReader.java (rev 0)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestReader.java 2009-10-27 17:18:21 UTC (rev 662)
@@ -0,0 +1,33 @@
+
+package org.nuiton.eugene.test.generator;
+
+import java.io.File;
+import org.nuiton.eugene.JavaBuilder;
+import org.nuiton.eugene.ModelReader;
+import org.nuiton.eugene.models.object.ObjectModel;
+
+/**
+ * TestReader
+ *
+ * Created: 27 oct. 2009
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class TestReader extends ModelReader<ObjectModel> {
+
+ protected JavaBuilder builder;
+
+ @Override
+ public ObjectModel read(File[] file) {
+ builder = new TestBuilder();
+
+ builder.build();
+
+ return builder.getModel();
+ }
+
+}
Modified: branches/1.1.0-Javabuilder/eugene-test/src/main/resources/log4j.properties
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/resources/log4j.properties 2009-10-27 10:32:23 UTC (rev 661)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/resources/log4j.properties 2009-10-27 17:18:21 UTC (rev 662)
@@ -7,6 +7,6 @@
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
# package level
-log4j.logger.org.nuiton.eugene=INFO
+log4j.logger.org.nuiton.eugene=DEBUG
log4j.logger.org.nuiton.eugene.test=DEBUG
log4j.logger.org.nuiton.processor=DEBUG
Modified: branches/1.1.0-Javabuilder/eugene-test/src/test/resources/log4j.properties
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/test/resources/log4j.properties 2009-10-27 10:32:23 UTC (rev 661)
+++ branches/1.1.0-Javabuilder/eugene-test/src/test/resources/log4j.properties 2009-10-27 17:18:21 UTC (rev 662)
@@ -7,6 +7,6 @@
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
# package level
-log4j.logger.org.nuiton.eugene=INFO
+log4j.logger.org.nuiton.eugene=DEBUG
log4j.logger.org.nuiton.eugene.test=DEBUG
log4j.logger.org.nuiton.processor=DEBUG
1
0
r661 - in branches/1.1.0-Javabuilder: eugene/src/main/java/org/nuiton/eugene eugene-test eugene-test/src/main eugene-test/src/main/java/org/nuiton/eugene/test/generator eugene-test/src/main/models eugene-test/src/test eugene-test/src/test/resources maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin
by fdesbois@users.nuiton.org 27 Oct '09
by fdesbois@users.nuiton.org 27 Oct '09
27 Oct '09
Author: fdesbois
Date: 2009-10-27 11:32:23 +0100 (Tue, 27 Oct 2009)
New Revision: 661
Added:
branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java
branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java
branches/1.1.0-Javabuilder/eugene-test/src/main/models/
branches/1.1.0-Javabuilder/eugene-test/src/main/models/dtotest.objectmodel
branches/1.1.0-Javabuilder/eugene-test/src/test/resources/
branches/1.1.0-Javabuilder/eugene-test/src/test/resources/log4j.properties
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ModelReader.java
Removed:
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/FileReader.java
Modified:
branches/1.1.0-Javabuilder/eugene-test/pom.xml
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java
branches/1.1.0-Javabuilder/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java
Log:
- Integrate Reader in maven-plugin
- Add template from ToPIA to test for regression (must be deleted after finished JavaGenerator)
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/FileReader.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/FileReader.java 2009-10-26 18:35:44 UTC (rev 660)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/FileReader.java 2009-10-27 10:32:23 UTC (rev 661)
@@ -1,65 +0,0 @@
-
-package org.nuiton.eugene;
-
-import java.io.File;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.models.Model;
-
-/**
- * FileReader
- *
- * Created: 26 oct. 2009
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public abstract class FileReader<M extends Model> {
-
- private static final Log log = LogFactory.getLog(FileReader.class);
-
- /** date de derniere modification de la source la plus recente */
- protected long lastModifiedSource = 0;
-
- protected void setLastModifiedSource(File[] files) {
- for (File file : files) {
- if (isNewerThanSource(file)) {
- lastModifiedSource = file.lastModified();
- log.debug("source date: " + lastModifiedSource
- + " files[i] date: " + file.lastModified() + "(" + file
- + ")");
- }
- }
- }
-
- protected long getLastModifiedSource() {
- return lastModifiedSource;
- }
-
- /**
- * @param file fichier a tester
- * @return vrai si le fichier passé en parametre est plus recent que
- * les sources sur generateur.
- */
- protected boolean isNewerThanSource(File file) {
- if (log.isDebugEnabled()) {
- log.debug("source date: " + getLastModifiedSource()
- + " file date: " + file.lastModified() + "(" + file + ")");
- }
- return file.lastModified() > getLastModifiedSource();
- }
-
- public M read(File file, File destDir) {
- return read(new File[] { file }, destDir);
- }
-
- public M read(File file) {
- return read(new File[] { file }, new File("."));
- }
-
- public abstract M read(File[] file, File destDir);
-
-}
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java 2009-10-26 18:35:44 UTC (rev 660)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java 2009-10-27 10:32:23 UTC (rev 661)
@@ -28,6 +28,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.models.Model;
/**
* Generator.
@@ -40,7 +41,7 @@
* Mise a jour: $Date$
* par : $Author$
*/
-public abstract class Generator {
+public abstract class Generator<M extends Model> {
protected static Log log = LogFactory.getLog(Generator.class);
@@ -58,7 +59,10 @@
protected String encoding;
+ /** date de derniere modification de la source la plus recente */
+ protected long lastModifiedSource = 0;
+
protected Generator parent = null;
public Generator() {
@@ -119,32 +123,23 @@
}
return properties.getProperty(name);
}
-/*
- protected void setLastModifiedSource(File[] files) {
- for (File file : files) {
- if (isNewerThanSource(file)) {
- lastModifiedSource = file.lastModified();
- log.debug("source date: " + lastModifiedSource
- + " files[i] date: " + file.lastModified() + "(" + file
- + ")");
- }
- }
- }
- protected long getLastModifiedSource() {
- if (parent != null) {
- return parent.getLastModifiedSource();
- }
- return lastModifiedSource;
+ public void setLastModifiedSource(long lastModifiedSource) {
+ this.lastModifiedSource = lastModifiedSource;
}
+ /**
+ * @param file fichier a tester
+ * @return vrai si le fichier passé en parametre est plus recent que
+ * les sources sur generateur.
+ */
protected boolean isNewerThanSource(File file) {
if (log.isDebugEnabled()) {
- log.debug("source date: " + getLastModifiedSource()
+ log.debug("source date: " + lastModifiedSource
+ " file date: " + file.lastModified() + "(" + file + ")");
}
- return file.lastModified() > getLastModifiedSource();
- }*/
+ return file.lastModified() > lastModifiedSource;
+ }
protected File getDestinationFile(File destDir, String filename) {
return new File(destDir, filename);
@@ -191,8 +186,11 @@
this.excludeTemplates = excludeTemplates;
}
+ @Deprecated
public abstract void generate(File[] file, File destDir);
+ public abstract void generate(M model, File destDir);
+
/**
* Test if given package is allowed for generation.
*
Copied: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ModelReader.java (from rev 659, branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/FileReader.java)
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ModelReader.java (rev 0)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ModelReader.java 2009-10-27 10:32:23 UTC (rev 661)
@@ -0,0 +1,48 @@
+
+package org.nuiton.eugene;
+
+import java.io.File;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.models.Model;
+
+/**
+ * FileReader
+ *
+ * Created: 26 oct. 2009
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public abstract class ModelReader<M extends Model> {
+
+ private static final Log log = LogFactory.getLog(ModelReader.class);
+
+ /** date de derniere modification de la source la plus recente */
+ protected long lastModifiedSource = 0;
+
+ protected void setLastModifiedSource(File[] files) {
+ for (File file : files) {
+ if (file.lastModified() > getLastModifiedSource()) {
+ lastModifiedSource = file.lastModified();
+ log.debug("source date: " + lastModifiedSource
+ + " files[i] date: " + file.lastModified() + "(" + file
+ + ")");
+ }
+ }
+ }
+
+ public long getLastModifiedSource() {
+ return lastModifiedSource;
+ }
+
+ public M read(File file) {
+ return read(new File[] { file });
+ }
+
+ public abstract M read(File[] file);
+
+}
Property changes on: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ModelReader.java
___________________________________________________________________
Added: svn:mergeinfo
+
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java 2009-10-26 18:35:44 UTC (rev 660)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java 2009-10-27 10:32:23 UTC (rev 661)
@@ -18,36 +18,20 @@
package org.nuiton.eugene;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.commons.digester.Digester;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.models.Model;
import org.nuiton.eugene.models.object.ObjectModel;
import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelClassifier;
import org.nuiton.eugene.models.object.ObjectModelElement;
import org.nuiton.eugene.models.object.ObjectModelEnumeration;
import org.nuiton.eugene.models.object.ObjectModelInterface;
-import org.nuiton.eugene.models.object.xml.DigesterObjectModelRuleSet;
-import org.nuiton.eugene.models.object.xml.ObjectModelClassifierImpl;
-import org.nuiton.eugene.models.object.xml.ObjectModelElementImpl;
-import org.nuiton.eugene.models.object.xml.ObjectModelImpl;
-import org.nuiton.eugene.models.object.xml.ObjectModelImplRef;
-import org.nuiton.eugene.models.object.xml.ObjectModelImplTagValue;
-import org.nuiton.util.FileUtil;
-import org.nuiton.util.RecursiveProperties;
-import org.nuiton.util.StringUtil;
-import org.xml.sax.SAXException;
/**
* Pour utiliser ce type de générateur il faut implanter au moins une des trois
@@ -84,15 +68,13 @@
*
* Mise a jour: $Date$ par : $Author$
*/
-public class ObjectModelGenerator extends Generator {
+public class ObjectModelGenerator extends Generator<ObjectModel> {
/** Logger for this class. */
private static Log log = LogFactory.getLog(ObjectModelGenerator.class);
protected ObjectModel model = null;
- protected ObjectModelReader reader;
-
public ObjectModelGenerator() {
super();
}
@@ -105,25 +87,14 @@
return model;
}
- /**
- * @param files les noms des fichiers existant contenant du XML représentant
- * des ObjectModel. Il est automatiquement recherche un fichier de
- * propriété associé a ce fichier pour pouvoir ajouter des
- * stereotype ou des tag value sur les class, attribute ou operation
- * @param destDir le répertoire dans lequel il faudra mettre les fichiers
- * générés
- */
+
@Override
+ @Deprecated
public void generate(File[] files, File destDir) {
- reader = new ObjectModelReader();
- ObjectModel objectModel = reader.read(files, destDir);
- try {
- generate(objectModel, destDir);
- } catch (IOException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Unable to generate for file", eee);
- }
- }
+ ObjectModelReader reader = new ObjectModelReader();
+ ObjectModel objectModel = reader.read(files);
+ setLastModifiedSource(reader.getLastModifiedSource());
+ generate(objectModel, destDir);
}
/**
@@ -142,31 +113,44 @@
* @param model
* @param destDir
* @throws IOException
- */
- public void generate(ObjectModel model, File destDir) throws IOException {
+ */@Override
+ public void generate(ObjectModel model, File destDir) {
// generateFromModel
this.model = model;
- String filename = getFilenameForModel(model);
- generateFromElement(model, destDir, filename,
- ObjectModelType.OBJECT_MODEL);
+ if (log.isDebugEnabled()) {
+ log.debug("name : " + model.getName());
+ log.debug("interfaces : " + model.getInterfaces().size());
+ log.debug("classes : " + model.getClasses().size());
+ }
- // generateFromClassifier
- generateFromElements(model.getClassifiers(), destDir,
- ObjectModelType.OBJECT_MODEL_CLASSIFIER);
+ //try {
+ String filename = getFilenameForModel(model);
+ generateFromElement(model, destDir, filename,
+ ObjectModelType.OBJECT_MODEL);
- // generateFromInterface
- generateFromElements(model.getInterfaces(), destDir,
- ObjectModelType.OBJECT_MODEL_INTERFACE);
+ // generateFromClassifier
+ generateFromElements(model.getClassifiers(), destDir,
+ ObjectModelType.OBJECT_MODEL_CLASSIFIER);
- // generateFromClass
- generateFromElements(model.getClasses(), destDir,
- ObjectModelType.OBJECT_MODEL_CLASS);
+ // generateFromInterface
+ generateFromElements(model.getInterfaces(), destDir,
+ ObjectModelType.OBJECT_MODEL_INTERFACE);
- // generateFromEnumeration
- generateFromElements(model.getEnumerations(), destDir,
- ObjectModelType.OBJECT_MODEL_ENUMERATION);
+ // generateFromClass
+ generateFromElements(model.getClasses(), destDir,
+ ObjectModelType.OBJECT_MODEL_CLASS);
+
+ // generateFromEnumeration
+ generateFromElements(model.getEnumerations(), destDir,
+ ObjectModelType.OBJECT_MODEL_ENUMERATION);
+
+ /*} catch (IOException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Unable to generate for file", eee);
+ }
+ }*/
}
/**
@@ -226,7 +210,7 @@
if (canGenerateElement(element)) {
File outputFile = getDestinationFile(destDir, filename);
- if (!getOverwrite() && reader.isNewerThanSource(outputFile)) {
+ if (!getOverwrite() && isNewerThanSource(outputFile)) {
if (log.isDebugEnabled()) {
log.debug("file " + outputFile + " is up-to-date");
}
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java 2009-10-26 18:35:44 UTC (rev 660)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java 2009-10-27 10:32:23 UTC (rev 661)
@@ -39,7 +39,7 @@
* Mise a jour: $Date$
* par : $Author$
*/
-public class ObjectModelReader extends FileReader<ObjectModel> {
+public class ObjectModelReader extends ModelReader<ObjectModel> {
private static final Log log = LogFactory.getLog(ObjectModelReader.class);
@@ -62,11 +62,9 @@
* des ObjectModel. Il est automatiquement recherche un fichier de
* propriété associé a ce fichier pour pouvoir ajouter des
* stereotype ou des tag value sur les class, attribute ou operation
- * @param destDir le répertoire dans lequel il faudra mettre les fichiers
- * générés
*/
@Override
- public ObjectModel read(File[] files, File destDir) {
+ public ObjectModel read(File[] files) {
setLastModifiedSource(files);
ObjectModel objectModel = new ObjectModelImpl();
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java 2009-10-26 18:35:44 UTC (rev 660)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java 2009-10-27 10:32:23 UTC (rev 661)
@@ -18,24 +18,15 @@
package org.nuiton.eugene;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
-import java.util.Enumeration;
-import org.apache.commons.digester.Digester;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
import org.nuiton.eugene.models.state.StateModel;
import org.nuiton.eugene.models.state.StateModelState;
import org.nuiton.eugene.models.state.StateModelStateChart;
-import org.nuiton.eugene.models.state.xml.DigesterStateModelRuleSet;
-import org.nuiton.eugene.models.state.xml.StateModelImpl;
-import org.nuiton.util.FileUtil;
-import org.nuiton.util.RecursiveProperties;
-import org.xml.sax.SAXException;
/**
* StateModelGenerator.
@@ -55,7 +46,7 @@
*
* Last update : $Date$ By : $Author$
*/
-public class StateModelGenerator extends Generator {
+public class StateModelGenerator extends Generator<StateModel> {
/** Logger for this class */
private static Log log = LogFactory.getLog(StateModelGenerator.class);
@@ -63,8 +54,6 @@
/** Model */
protected StateModel model;
- protected StateModelReader reader;
-
/**
* Empty constructor
*/
@@ -91,17 +80,19 @@
* @see org.nuiton.eugene.Generator#generate(java.io.File[], java.io.File)
*/
@Override
+ @Deprecated
public void generate(File[] files, File destDir) {
- reader = new StateModelReader();
- StateModel stateModel = reader.read(files, destDir);
+ StateModelReader reader = new StateModelReader();
+ StateModel stateModel = reader.read(files);
+ setLastModifiedSource(reader.getLastModifiedSource());
// generate code
- try {
+ //try {
generate(stateModel, destDir);
- } catch (IOException e) {
+ /*} catch (IOException e) {
log.warn("Can't generate code for files", e);
- }
+ }*/
}
@@ -114,14 +105,14 @@
* @param destDir le dossier de destination
* @throws IOException
*/
- public void generate(StateModel stateModel, File destDir)
- throws IOException {
+ @Override
+ public void generate(StateModel stateModel, File destDir) {
model = stateModel;
String filename = getFilenameFromModel(stateModel);
File outputFile = getDestinationFile(destDir, filename);
- if (getOverwrite() || !reader.isNewerThanSource(outputFile)) {
+ if (getOverwrite() || !isNewerThanSource(outputFile)) {
try {
StringWriter out = new StringWriter();
MonitorWriter monitorOut = new MonitorWriter(out);
@@ -148,7 +139,7 @@
String filenameState = getFilenameFromState(state, chart
.getName());
File outputFiletate = getDestinationFile(destDir, filenameState);
- if (getOverwrite() || !reader.isNewerThanSource(outputFiletate)) {
+ if (getOverwrite() || !isNewerThanSource(outputFiletate)) {
try {
StringWriter out = new StringWriter();
MonitorWriter monitorOut = new MonitorWriter(out);
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java 2009-10-26 18:35:44 UTC (rev 660)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java 2009-10-27 10:32:23 UTC (rev 661)
@@ -26,12 +26,12 @@
* Mise a jour: $Date$
* par : $Author$
*/
-public class StateModelReader extends FileReader<StateModel> {
+public class StateModelReader extends ModelReader<StateModel> {
private static final Log log = LogFactory.getLog(StateModelReader.class);
@Override
- public StateModel read(File[] files, File destDir) {
+ public StateModel read(File[] files) {
Digester digester = new Digester();
digester.addRuleSet(new DigesterStateModelRuleSet());
Modified: branches/1.1.0-Javabuilder/eugene-test/pom.xml
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/pom.xml 2009-10-26 18:35:44 UTC (rev 660)
+++ branches/1.1.0-Javabuilder/eugene-test/pom.xml 2009-10-27 10:32:23 UTC (rev 661)
@@ -92,13 +92,14 @@
<groupId>org.nuiton.eugene</groupId>
<artifactId>maven-eugene-plugin</artifactId>
<version>${project.version}</version>
- <!--executions>
+ <executions>
<execution>
- <id>Test Java Generator</id>
+ <id>Test Generator</id>
<phase>generate-test-sources</phase>
<configuration>
+ <reader>org.nuiton.eugene.ObjectModelReader</reader>
<includes>**/*.objectmodel</includes>
- <templates>org.nuiton.eugene.test.generator.JavaGenerator</templates>
+ <templates>org.nuiton.eugene.test.generator.BeanGenerator</templates>
<defaultPackage>org.nuiton.eugene.test</defaultPackage>
<extraClassPathDirectory>target/classes</extraClassPathDirectory>
<generateResources>
@@ -109,7 +110,7 @@
<goal>generate</goal>
</goals>
</execution>
- </executions-->
+ </executions>
</plugin>
<!--plugin>
Added: branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java (rev 0)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java 2009-10-27 10:32:23 UTC (rev 661)
@@ -0,0 +1,618 @@
+/* *##% ToPIA - Persistence
+ * 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>. ##%*/
+
+/* *
+* BeanGenerator.java
+*
+* Created: 17 avril 2009
+*
+* @author tony Chemit <chemit(a)codelutin.com>
+* @version $Revision: 1334 $
+*
+* Mise a jour: $Date: 2009-01-29 16:47:42 +0100 (jeu 29 jan 2009) $
+* par : $Author: chemit $
+*/
+
+package org.nuiton.eugene.test.generator;
+
+import static org.nuiton.eugene.test.generator.TopiaGeneratorUtil.TAG_ANNOTATION;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import java.util.List;
+import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.ObjectModelGenerator;
+import org.nuiton.eugene.GeneratorUtil;
+import org.nuiton.eugene.ImportsManager;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelClassifier;
+import org.nuiton.eugene.models.object.ObjectModelDependency;
+import org.nuiton.eugene.models.object.ObjectModelInterface;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.eugene.models.object.ObjectModelParameter;
+//import org.nuiton.topia.persistence.TopiaEntity;
+import static org.nuiton.eugene.test.generator.TopiaGeneratorUtil.isPrimitiveType;
+import static org.nuiton.eugene.test.generator.TopiaGeneratorUtil.isDateType;
+
+/**
+ * DTO generator
+ */
+public class BeanGenerator extends ObjectModelGenerator {
+
+ /**
+ * Logger for this class
+ */
+ private static final Log log = LogFactory.getLog(BeanGenerator.class);
+
+ public BeanGenerator() {
+ super();
+ }
+
+ @Override
+ public String getFilenameForClass(ObjectModelClass clazz) {
+ return clazz.getQualifiedName().replace('.', File.separatorChar) + ".java";
+ }
+
+ @Override
+ public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
+ if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_BEAN) &&
+ !clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
+ return;
+ }
+ //
+ // première phase : calcul des variables
+ //
+ String copyright = TopiaGeneratorUtil.getCopyright(model);
+ String clazzName = clazz.getName();
+ String abstractStr = isAbstract(clazz) ? " abstract " : " ";
+ boolean needGetEntityMethod = false;
+ boolean generateToString = TopiaGeneratorUtil.generateToString(clazz, model);
+
+ ImportsManager imports = new ImportsManager();
+
+ String extendClass = "";
+ Iterator<ObjectModelClass> j = clazz.getSuperclasses().iterator();
+ if (j.hasNext()) {
+ ObjectModelClassifier p = j.next();
+ imports.addImport(p.getQualifiedName());
+ extendClass += p.getName();
+ }
+ String implInterface = "";
+ for (Iterator<ObjectModelInterface> i=clazz.getInterfaces().iterator(); i.hasNext();) {
+ ObjectModelClassifier parentInterface = i.next();
+ imports.addImport(parentInterface.getQualifiedName());
+ implInterface += parentInterface.getName();
+ if (i.hasNext()) {
+ implInterface += ", ";
+ }
+ }
+ // Add Serializable implements for DTO generation
+ if (clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
+ imports.addImport(Serializable.class);
+ if (!implInterface.isEmpty()) {
+ implInterface += ", ";
+ }
+ implInterface += Serializable.class.getName();
+ }
+ String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", clazz, model);
+
+ List<ObjectModelAttribute> attributes = new ArrayList<ObjectModelAttribute>();
+ List<ObjectModelAttribute> multipleAttr = new ArrayList<ObjectModelAttribute>();
+
+ setAttributesForDTO(clazz, attributes,imports);
+
+ boolean needListInImport=false;
+
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
+ if (attr.isNavigable()) {
+ attributes.add(attr);
+ imports.addImport(attr.getType());
+ if (GeneratorUtil.isNMultiplicity(attr)) {
+ multipleAttr.add(attr);
+ ObjectModelClass attrEntity = null;
+ if (model.hasClass(attr.getType())) {
+ attrEntity = model.getClass(attr.getType());
+ }
+ boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY));
+ needGetEntityMethod |= isEntity;
+ if (attr.isOrdered()) {
+ needListInImport = true;
+ }
+ }
+ }
+ }
+
+ imports.addImport(java.beans.PropertyChangeListener.class.getName());
+ imports.addImport(java.beans.PropertyChangeSupport.class.getName());
+
+ for (ObjectModelOperation operation : clazz.getOperations()) {
+ imports.addImport(operation.getReturnType());
+ for (ObjectModelParameter parameter : operation.getParameters()) {
+ imports.addImport(parameter.getType());
+ }
+ }
+
+ if (needGetEntityMethod) {
+ imports.addImport("org.nuiton.topia.persistence.TopiaEntity");
+ }
+ if (!multipleAttr.isEmpty()) {
+ imports.addImport(Collection.class);
+ }
+ if (needListInImport) {
+ imports.addImport(List.class);
+ }
+ if (generateToString) {
+ imports.addImport(org.apache.commons.lang.builder.ToStringBuilder.class);
+ }
+
+ boolean sortAttribute = TopiaGeneratorUtil.sortAttribute(clazz, model);
+ if (sortAttribute) {
+ Comparator<ObjectModelAttribute> comp = new Comparator<ObjectModelAttribute>(){
+
+ @Override
+ public int compare(ObjectModelAttribute o1, ObjectModelAttribute o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ };
+ java.util.Collections.sort(attributes,comp);
+ java.util.Collections.sort(multipleAttr,comp);
+ }
+ //
+ // seconde phase : génération
+ //
+
+ if (TopiaGeneratorUtil.notEmpty(copyright)) {
+/*{<%=copyright%>
+}*/
+ }
+
+/*{package <%=clazz.getPackageName()%>;
+
+ }*/
+
+ if (log.isDebugEnabled()) {
+ log.debug("imports for class <" + clazzName + ">");
+ }
+ //for (String anImport : imports) {
+ for (String anImport : imports.getImports(clazz.getPackageName())) {
+ if (log.isDebugEnabled()) {
+ log.debug("import " + anImport);
+ }
+/*{import <%=anImport%>;
+}*/
+ }
+/*{
+public<%=abstractStr%>class <%=clazzName%>}*/
+
+/*
+ * Définition de la super classe : il ne doit y avoir qu'une
+ */
+ if (extendClass.length() > 0) {
+/*{ extends <%=extendClass%>}*/
+ }
+
+ if (implInterface.length() > 0) {
+/*{ implements <%=implInterface%> {
+
+}*/
+ } else {
+ /*{ {
+
+}*/
+ }
+
+
+ // TODO Calculer un serialVersionUID si il n'y en a pas
+ if (svUID != null) {
+/*{ public static final long serialVersionUID = <%=svUID%>;
+
+}*/
+ }
+ generateInterfaceOperations(output, clazz);
+ generateAttributes(output, attributes);
+/*{ protected final PropertyChangeSupport pcs;
+
+ /**
+ * Default constructor of <%=clazzName%>.
+ *)
+ public <%=clazzName%>() {
+ pcs = new PropertyChangeSupport(this);
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(propertyName, listener);
+ }
+
+}*/
+ generateGetters(output, attributes);
+ generateSetters(output, attributes);
+ generateGetChild(output, multipleAttr);
+ generateAddChild(output, multipleAttr);
+ generateRemoveChild(output, multipleAttr);
+ if (generateToString) {
+ generateToString(output, clazz);
+ }
+ if (!multipleAttr.isEmpty()) {
+/*{
+
+ protected <T> T getChild(Collection<T> childs, int index) {
+ if (childs != null) {
+ int i = 0;
+ for (T o : childs) {
+ if (index == i) {
+ return o;
+ }
+ i++;
+ }
+ }
+ return null;
+ }
+
+ }*/
+ if (needGetEntityMethod) {
+/*{ protected <T extends TopiaEntity> T getEntity(Collection<T> childs, String topiaId) {
+ if (childs != null) {
+ for (T o : childs) {
+ if (topiaId.equals(o.getTopiaId())) {
+ return o;
+ }
+ }
+ }
+ return null;
+ }
+ }*/
+ }
+ }
+
+/*{
+ protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ pcs.firePropertyChange(propertyName, oldValue, newValue);
+ }
+
+} //<%=clazz.getName()%>
+}*/
+ }
+
+ protected void generateAttributes(Writer output, List<ObjectModelAttribute> attributes) throws IOException {
+
+ for (ObjectModelAttribute attr : attributes) {
+
+ if (!(attr.isNavigable()
+ || attr.hasAssociationClass())) {
+ continue;
+ }
+
+ if (TopiaGeneratorUtil.hasDocumentation(attr)) {
+/*{ /**
+ * <%=attr.getDocumentation()%>
+ *)
+}*/
+ }
+ String annotation = attr.getTagValue(TAG_ANNOTATION);
+ if (annotation != null && annotation.length() > 0) {
+/*{ <%=annotation%>
+}*/
+ }
+ String attrName = attr.getName();
+ String attrVisibility = attr.getVisibility();
+ String attrType = attr.getType();
+ if (attr.hasAssociationClass()) {
+ String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
+ attrType = attr.getAssociationClass().getName();
+ }
+ int dot = attrType.lastIndexOf(".");
+ if (dot>-1) {
+ attrType = attrType.substring(dot + 1);
+ }
+ if (GeneratorUtil.isNMultiplicity(attr)) {
+ attrType = getCollection(attr, attrType);
+ }
+
+/*{ <%=attrVisibility%> <%=attrType%> <%=attrName%>;
+}*/
+ }
+ }
+
+ protected void generateGetters(Writer output, List<ObjectModelAttribute> attributes) throws IOException {
+ /*
+ * Définition des getteurs et setteurs
+ */
+ for (ObjectModelAttribute attr : attributes) {
+
+ if (!attr.isNavigable()) {
+ continue;
+ }
+
+ String attrName = attr.getName();
+ String attrType = attr.getType();
+ if (attr.hasAssociationClass()) {
+ String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
+ attrType = attr.getAssociationClass().getName();
+ }
+ String attrNameCapitalized = GeneratorUtil.capitalize(attrName);
+ int dot = attrType.lastIndexOf(".");
+ if (dot>-1) {
+ attrType = attrType.substring(dot + 1);
+ }
+ if (GeneratorUtil.isNMultiplicity(attr)) {
+ attrType = getCollection(attr, attrType);
+ }
+/*{ public <%=attrType%> get<%=attrNameCapitalized%>() {
+ return <%=attrName%>;
+ }
+
+}*/
+ }
+ }
+
+ protected void generateSetters(Writer output, List<ObjectModelAttribute> attributes) throws IOException {
+ /*
+ * Définition des getteurs et setteurs
+ */
+ for (ObjectModelAttribute attr : attributes) {
+
+ if (!attr.isNavigable()) {
+ continue;
+ }
+
+ String attrName = attr.getName();
+ String attrType = attr.getType();
+
+ if (attr.hasAssociationClass()) {
+ String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
+ attrType = attr.getAssociationClass().getName();
+ }
+ String attrNameCapitalized = GeneratorUtil.capitalize(attrName);
+ int dot = attrType.lastIndexOf(".");
+ if (dot>-1) {
+ attrType = attrType.substring(dot + 1);
+ }
+ if (GeneratorUtil.isNMultiplicity(attr)) {
+ attrType = getCollection(attr, attrType);
+ }
+/*{ public void set<%=attrNameCapitalized%>(<%=attrType%> newValue) {
+ <%=attrType%> oldValue = get<%=attrNameCapitalized%>();
+ this.<%=attrName%> = newValue;
+ firePropertyChange("<%=attrName%>", oldValue, newValue);
+ }
+
+}*/
+ }
+ }
+
+ protected void generateGetChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException {
+
+ for (ObjectModelAttribute attr : multipleAttr) {
+
+ String attrName = attr.getName();
+ String attrNameCapitalized = GeneratorUtil.capitalize(attrName);
+ String attrType = attr.getType();
+ int dot = attrType.lastIndexOf(".");
+ if (dot>-1) {
+ attrType = attrType.substring(dot + 1);
+ }
+ ObjectModelClass attrEntity=null;
+ if (model.hasClass(attr.getType())) {
+ attrEntity = model.getClass(attr.getType());
+ }
+ boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY));
+/*{ public <%=attrType%> get<%=attrNameCapitalized%>(int index) {
+ <%=attrType%> o = getChild(<%=attrName%>, index);
+ return o;
+ }
+
+}*/
+ if (isEntity) {
+/*{ public <%=attrType%> get<%=attrNameCapitalized%>(String topiaId) {
+ <%=attrType%> o = getEntity(<%=attrName%>, topiaId);
+ return o;
+ }
+
+}*/
+ }
+ }
+ }
+ protected void generateAddChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException {
+ for (ObjectModelAttribute attr : multipleAttr) {
+
+ String attrName = attr.getName();
+ String attrNameCapitalized = GeneratorUtil.capitalize(attrName);
+ String attrType = attr.getType();
+ int dot = attrType.lastIndexOf(".");
+ if (dot>-1) {
+ attrType = attrType.substring(dot + 1);
+ }
+/*{ public <%=attrType%> add<%=attrNameCapitalized%>(<%=attrType%> <%=attrName%>) {
+ get<%=attrNameCapitalized%>().add(<%=attrName%>);
+ firePropertyChange("<%=attrName%>", null, <%=attrName%>);
+ return <%=attrName%>;
+ }
+
+}*/
+ }
+ }
+
+ protected void generateRemoveChild(Writer output, List<ObjectModelAttribute> multipleAttr) throws IOException {
+ for (ObjectModelAttribute attr : multipleAttr) {
+ String attrName = attr.getName();
+ String attrNameCapitalized = GeneratorUtil.capitalize(attrName);
+ String attrType = attr.getType();
+ int dot = attrType.lastIndexOf(".");
+ if (dot>-1) {
+ attrType = attrType.substring(dot + 1);
+ }
+/*{ public boolean remove<%=attrNameCapitalized%>(<%=attrType%> <%=attrName%>) {
+ boolean removed = get<%=attrNameCapitalized%>().remove(<%=attrName%>);
+ if (removed) {
+ firePropertyChange("<%=attrName%>", <%=attrName%>, null);
+ }
+ return removed;
+ }
+
+}*/
+ }
+ }
+
+ protected void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException {
+ for (ObjectModelOperation op : classifier.getOperations()) {
+ String opName = op.getName();
+/*{ /**
+}*/
+ if (TopiaGeneratorUtil.hasDocumentation(op)) {
+ String opDocumentation = op.getDocumentation();
+/*{ * <%=opName%> : <%=opDocumentation%>
+}*/
+ }
+ Collection<ObjectModelParameter> params = op.getParameters();
+ for (ObjectModelParameter param : params) {
+ String paramName = param.getName();
+ String paramDocumentation = param.getDocumentation();
+/*{ * @param <%=paramName%> <%=paramDocumentation%>
+ }*/
+ }
+ String opVisibility = op.getVisibility();
+ String opType = op.getReturnType();
+/*{ *)
+ <%=opVisibility%> abstract <%=opType%> <%=opName%>(}*/
+ String comma = "";
+ for (ObjectModelParameter param : params) {
+ String paramName = param.getName();
+ String paramType = param.getType();
+/*{<%=comma%><%=paramType%> <%=paramName%>}*/
+ comma = ", ";
+ }
+/*{)}*/
+ Set<String> exceptions = op.getExceptions();
+ comma = " throws ";
+ for (String exception : exceptions) {
+/*{<%=comma%><%=exception%>}*/
+ comma = ", ";
+ }
+/*{;
+
+}*/
+ }
+ }
+ protected void generateToString(Writer output, ObjectModelClass clazz) throws IOException {
+/*{
+ @Override
+ public String toString() {
+ String result = new ToStringBuilder(this).
+}*/
+ for (ObjectModelAttribute attr : clazz.getAttributes()) {
+ if (!(attr.isNavigable() || attr.hasAssociationClass())) {
+ continue;
+ }
+ //FIXME possibilité de boucles (non directes)
+ String attrName = attr.getName();
+/*{ append("<%=attrName%>", this.<%=attrName%>).
+}*/
+ }
+/*{ toString();
+ return result;
+ }
+ }*/
+ }
+
+ protected String getCollection(ObjectModelAttribute attr, String attrType) {
+ String nMultType;
+ if (attr.isOrdered()) {
+ nMultType = "List<";
+ } else {
+ nMultType = "Collection<";
+ }
+ nMultType += attrType;
+ nMultType += ">";
+ return nMultType;
+ }
+
+ protected boolean isAbstract(ObjectModelClass clazz) {
+ if (clazz.isAbstract()) {
+ return true;
+ }
+ return !clazz.getOperations().isEmpty();
+ }
+
+ /**
+ * Dependecy gestion for DTO generation.
+ * All primitives attributes (and dates) of dependencies entities of the DTO are
+ * copied in the DTO. This method only prepare a list of attributes to be generated.
+ * @param clazz DTO ObjectModelClass
+ * @param attributes list of attributes for the generation (may be not empty)
+ * @param imports the ImportsManager used to generate the header imports of the DTO
+ * @return the same list of attributes in parameter with attributes from entities dependencies
+ * @see org.nuiton.eugene.ImportsManager
+ * @see org.nuiton.eugene.models.object.ObjectModelDependency
+ */
+ private List<ObjectModelAttribute> setAttributesForDTO(ObjectModelClass clazz,
+ List<ObjectModelAttribute> attributes, ImportsManager imports) {
+
+ if (clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
+ if (log.isInfoEnabled()) {
+ log.info("DTO dependency gestion");
+ }
+ for (ObjectModelDependency dependency : clazz.getDependencies()) {
+ ObjectModelClass supplier = (ObjectModelClass)dependency.getSupplier();
+
+ // ENTITY dependency
+ // Copy all primitives attributes from the Entity (supplier) to the DTO
+ // Prepare a list to future generation of all object generated attributes
+ if (supplier.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)) {
+ if (log.isInfoEnabled()) {
+ log.info("Create primitive and date fields in DTO from Entity : "
+ + supplier.getQualifiedName());
+ }
+ for (ObjectModelAttribute attr : supplier.getAttributes()) {
+ if (isPrimitiveType(attr) || isDateType(attr)) {
+ attributes.add(attr);
+ imports.addImport(attr.getType());
+ }
+ if (GeneratorUtil.isNMultiplicity(attr)) {
+ imports.addImport("java.util.Collection");
+ }
+ }
+ }
+ }
+ }
+ return attributes;
+ }
+} //BeanGenerator
Added: branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java (rev 0)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java 2009-10-27 10:32:23 UTC (rev 661)
@@ -0,0 +1,946 @@
+/* *##% ToPIA - Persistence
+ * 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>. ##%*/
+/*******************************************************************************
+ * GeneratorUtil.java
+ *
+ * Created: 13 déc. 2005
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ *
+ * @version $Revision: 1298 $
+ *
+ * Mise a jour: $Date: 2009-01-15 00:01:45 +0100 (jeu 15 jan 2009) $ par : $Author: tchemit $
+ */
+package org.nuiton.eugene.test.generator;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
+import org.nuiton.eugene.Generator;
+import org.nuiton.eugene.GeneratorUtil;
+import org.nuiton.eugene.models.Model;
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelAssociationClass;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelElement;
+import org.nuiton.eugene.models.object.ObjectModelInterface;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.eugene.models.object.ObjectModelParameter;
+
+/** Classe regroupant divers méthodes utiles pour la génération des entités */
+public class TopiaGeneratorUtil extends GeneratorUtil {
+
+ /** Stéréotype pour les interfaces devant être générées sous forme de facades */
+ public final static String STEREOTYPE_FACADE = "facade";
+ /** Stéréotype pour les objets devant être générées sous forme d'entités */
+ public static final String STEREOTYPE_ENTITY = "entity";
+ /** Stéréotype pour les objets devant être générées sous forme de DTO */
+ public static final String STEREOTYPE_DTO = "dto";
+ /** Stéréotype pour les objets devant être générées sous forme de bean */
+ public static final String STEREOTYPE_BEAN = "bean";
+ /**
+ * Stéréotype pour les interfaces devant être générées sous forme de
+ * services
+ */
+ public static final String STEREOTYPE_SERVICE = "service";
+ /** Stéréotype pour les interfaces devant être générées sous forme de DAO */
+ public static final String STEREOTYPE_DAO = "dao";
+ /** Stéréotype pour les attributs à indexer en base */
+ public static final String STEREOTYPE_INDEXED = "indexed";
+ /** Stéréotype pour les collections avec unicité */
+ public static final String STEREOTYPE_UNIQUE = "unique";
+ /** Stéréotype pour les attributs étant des clés primaires */
+ public static final String STEREOTYPE_PRIMARYKAY = "primaryKey";
+ /** Tag pour le type de persistence */
+ public static final String TAG_PERSISTENCE_TYPE = "persistenceType";
+ /** Tag pour le nom du champ / entité en BD */
+ public static final String TAG_DB_NAME = "dbName";
+ /** Tag pour le nom du schema en BD */
+ public static final String TAG_SCHEMA_NAME = "dbSchema";
+ /** Tag pour la taille du champ en BD */
+ public static final String TAG_LENGTH = "length";
+ /** Tag pour ajouter une annotation à un champ */
+ public static final String TAG_ANNOTATION = "annotation";
+ /** Tag pour ajouter specifier le copyright d'un fichier */
+ public static final String TAG_COPYRIGHT = "copyright";
+ /** Tag pour specfier le type d'acces a un champ */
+ public static final String TAG_ACCESS = "access";
+ /** Tag pour specfier si on doit générer i18n */
+ public static final String TAG_I18N_PREFIX = "i18n";
+ /** Tag pour ajouter un attribut dans une clef métier */
+ public static final String TAG_NATURAL_ID = "naturalId";
+ /** Tag pour specifier si une clef metier est mutable */
+ public static final String TAG_NATURAL_ID_MUTABLE = "naturalIdMutable";
+ /** Tag pour spécifier la caractèrelazy d'une association multiple */
+ public static final String TAG_LAZY = "lazy";
+ /** Tag pour spécifier la caractère fetch d'une association multiple */
+ public static final String TAG_FETCH = "fetch";
+ /** Tag pour spécifier la caractère order-by d'une association multiple */
+ public static final String TAG_ORDER_BY = "orderBy";
+ /** Tag pour spécifier la caractère not-null d'un attribut */
+ public static final String TAG_NOT_NULL = "notNull";
+ /** Tag pour spécifier la caractère embed-xml d'une association */
+ public static final String TAG_EMBED_XML = "embedXml";
+ /**
+ * Tag pour configurer l'interface du proxy sur autre chose que l'implementation par defaut.
+ *
+ * Par defaut :
+ * null > generere le proxy sur l'interface de l'implementation
+ * Autre valeur :
+ * "none" > laisse la configuration par defaut d'hibernate
+ */
+ public static final String TAG_PROXY_INTERFACE = "hibernateProxyInterface";
+ /** Tag pour spécifier le permissions à la création */
+ public static final String TAG_SECURITY_CREATE = "securityCreate";
+ /** Tag pour spécifier le permissions au chargement */
+ public static final String TAG_SECURITY_LOAD = "securityLoad";
+ /** Tag pour spécifier le permissions à la mise à jour */
+ public static final String TAG_SECURITY_UPDATE = "securityUpdate";
+ /** Tag pour spécifier le permissions à la suppression */
+ public static final String TAG_SECURITY_DELETE = "securityDelete";
+ /** Tag pour specifier de ne pas generer la methode toString */
+ public static final String TAG_NOT_GENERATE_TO_STRING = "notGenerateToString";
+ /** Tag pour specifier de trier les attributs par nom lors de la generation */
+ public static final String TAG_SORT_ATTRIBUTE = "sortAttribute";
+ /** Tag pour specfier si on doit générer la methode getOperator dans les daohelpers )*/
+ public static final String TAG_GENERATE_OPERATOR_FOR_DAO_HELPER = "generateOperatorForDAOHelper";
+ /** Type de persistence Hibernate */
+ public static final String PERSISTENCE_TYPE_HIBERNATE = "hibernate";
+ /** Type de persistence LDAP */
+ public static final String PERSISTENCE_TYPE_LDAP = "ldap";
+ /** Type de persistence par défaut (si aucun précisé) */
+ public static final String PERSISTENCE_TYPE_DEFAULT = PERSISTENCE_TYPE_HIBERNATE;
+ /** Propriété des générateurs indiquant le package par défaut */
+ public static final String PROPERTY_DEFAULT_PACKAGE = "defaultPackage";
+ /** Le package par défaut si aucun n'est spécifié */
+ public static final String DEFAULT_PACKAGE = "org.codelutin.malo";
+
+ /**
+ * Renvoie le package par défaut pour le générateur donné
+ *
+ * @param generator le générateur donné
+ * @return le package par défaut du générator donné
+ */
+ public static String getDefaultPackage(Generator generator) {
+ String packageName = generator.getProperty(PROPERTY_DEFAULT_PACKAGE);
+ if (packageName == null || "".equals(packageName)) {
+ packageName = DEFAULT_PACKAGE;
+ }
+ return packageName;
+ }
+
+ /**
+ * @see GeneratorUtil#hasDocumentation
+ * @deprecated
+ */
+ @Deprecated
+ public static boolean hasDocumentation(ObjectModelElement element) {
+ return notEmpty(element.getDocumentation());
+ }
+
+ /**
+ * @see GeneratorUtil#notEmpty
+ * @deprecated
+ */
+ @Deprecated
+ public static boolean notEmpty(String s) {
+ return (s != null && !"".equals(s));
+ }
+
+ /**
+ * Renvoie l'interface DAO associée à la classe passée en paramètre
+ *
+ * @param clazz la classe à tester
+ * @param model le modele utilisé
+ * @return l'interface trouvée ou null sinon
+ */
+ public static ObjectModelInterface getDAOInterface(ObjectModelClass clazz,
+ ObjectModel model) {
+ for (Object o : model.getInterfaces()) {
+ ObjectModelInterface daoInterface = (ObjectModelInterface) o;
+ if (daoInterface.getName().equals(clazz.getName() + "DAO")) {
+ if (daoInterface.hasStereotype(STEREOTYPE_DAO)) {
+ return daoInterface;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Renvoie le type de persistence pour l'élément donné. Si aucun n'est
+ * trouvé, le type par défaut est utilisé
+ *
+ * @param element l'élément à tester
+ * @return le type de persitence pour l'élément donné.
+ */
+ public static String getPersistenceType(ObjectModelElement element) {
+ String tag = element.getTagValue(TAG_PERSISTENCE_TYPE);
+ if (tag == null) {
+ tag = PERSISTENCE_TYPE_DEFAULT;
+ }
+ return tag;
+ }
+
+ public static String getReverseDBName(ObjectModelAttribute attr) {
+ if (attr.getReverseAttribute() != null) {
+ return getDBName(attr.getReverseAttribute());
+ } else {
+ return getDBName(attr) + "_id";
+ }
+ }
+
+ /**
+ * Renvoie le nom BD de l'élement passé en paramètre. Elle se base sur le
+ * tag associé si il existe, sinon sur le nom de l'élément
+ *
+ * @param element l'élément à tester
+ * @return le nom de table
+ */
+ public static String getDBName(ObjectModelElement element) {
+ if (element == null) {
+ return null;
+ }
+ if (notEmpty(element.getTagValue(TAG_DB_NAME))) {
+ return element.getTagValue(TAG_DB_NAME);
+ }
+ return toLowerCaseFirstLetter(element.getName());
+ }
+
+ /**
+ * Cherche et renvoie le schema a utiliser sur cet element, sinon sur le model.
+ *
+ * @param element l'élément à tester
+ * @param model le modele utilisé
+ * @return le nom du schema ou null
+ */
+ public static String getSchemaName(ObjectModelElement element,
+ ObjectModel model) {
+ return findTagValue(TAG_SCHEMA_NAME, element, model);
+ }
+
+ /**
+ * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model.
+ *
+ * @param element l'élément à tester
+ * @param model le modele utilisé
+ * @return le prefix i18n ou <code>null</code> si non spécifié
+ */
+ public static String getI18nPrefix(ObjectModelElement element,
+ ObjectModel model) {
+ return GeneratorUtil.findTagValue(TAG_I18N_PREFIX, element, model);
+ }
+
+ /**
+ * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model.
+ *
+ * @param element l'élément à tester
+ * @param model le modele utilisé
+ * @return le prefix i18n ou <code>null</code> si non spécifié
+ */
+ public static boolean shouldgenerateOperatorForDAOHelper(ObjectModelElement element,
+ ObjectModel model) {
+ String tagValue = GeneratorUtil.findTagValue(TAG_GENERATE_OPERATOR_FOR_DAO_HELPER, element, model);
+ boolean generate = GeneratorUtil.notEmpty(tagValue) && Boolean.valueOf(tagValue);
+ return generate;
+ }
+
+ /**
+ * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
+ *
+ * @param clazz la classe à tester
+ * @return la liste des attributs de la clef métier ou null si pas de clef métier.
+ */
+ public static List<String> getNaturalId(ObjectModelClass clazz) {
+ String value = clazz.getTagValue(TAG_NATURAL_ID);
+ if (value == null || value.trim().isEmpty()) {
+ return java.util.Collections.emptyList();
+ }
+ List<String> result = new ArrayList<String>();
+ for (String attribute : value.split(",")) {
+ result.add(attribute.trim());
+ }
+ return result;
+ }
+
+ /**
+ * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
+ *
+ * @param clazz la classe à tester
+ * @param model le modele
+ * @return la liste des attributs de la clef métier ou null si pas de clef métier.
+ */
+ public static boolean generateToString(ObjectModelClass clazz,
+ ObjectModel model) {
+ String value;
+ value = model.getTagValue(TAG_NOT_GENERATE_TO_STRING);
+ if (value != null && !value.trim().isEmpty()) {
+ return false;
+ }
+ value = clazz.getTagValue(TAG_NOT_GENERATE_TO_STRING);
+ if (value != null && !value.trim().isEmpty()) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
+ *
+ * @param clazz la classe à tester
+ * @param model le modele
+ * @return la liste des attributs de la clef métier ou null si pas de clef métier.
+ */
+ public static boolean sortAttribute(ObjectModelClass clazz,
+ ObjectModel model) {
+ String value;
+ value = clazz.getTagValue(TAG_SORT_ATTRIBUTE);
+ if (value == null || value.trim().isEmpty() || "false".equals(value.trim())) {
+ return false;
+ }
+ if (value != null && "true".equals(value.trim())) {
+ return true;
+ }
+
+ value = model.getTagValue(TAG_SORT_ATTRIBUTE);
+ if (value == null || value.trim().isEmpty() || "false".equals(value.trim())) {
+ return false;
+ }
+ if (value != null && "true".equals(value.trim())) {
+ return true;
+ }
+ return true;
+ }
+
+ /**
+ * Detecte si un attribut fait partie d'une clef metier.
+ *
+ * @param attribute l'attribut à tester
+ * @return <code>true</code> si l'attribut fait partie d'une clef metier, <code>false</cdoe> sinon.
+ */
+ public static boolean isNaturalId(ObjectModelAttribute attribute) {
+ String value = attribute.getTagValue(TAG_NATURAL_ID);
+ if (!GeneratorUtil.notEmpty(value)) {
+ // valeur null, donc pas positionnee
+ return false;
+ }
+ try {
+ return Boolean.valueOf(value.trim());
+ } catch (Exception e) {
+ // on a pas reussi a convertir en boolean.
+ //todo peut-être declancher une exception ?
+ return false;
+ }
+ }
+
+ /**
+ * Cherches et renvoie le copyright a utiliser sur le model.
+ *
+ * @param model le modele utilisé
+ * @return le texte du copyright ou null
+ */
+ public static String getCopyright(Model model) {
+ return findTagValue(TAG_COPYRIGHT, null, model);
+ }
+
+ /**
+ * @see GeneratorUtil#findTagValue
+ * @deprecated
+ */
+ @Deprecated
+ public static String findTagValue(String tagName,
+ ObjectModelElement element, Model model) {
+ if (element == null) {
+ if (model != null) {
+ if (notEmpty(model.getTagValue(tagName))) {
+ return model.getTagValue(tagName);
+ }
+ }
+ return null;
+ }
+ if (notEmpty(element.getTagValue(tagName))) {
+ return element.getTagValue(tagName);
+ }
+ //On va chercher sur l'element declarant
+ return findTagValue(tagName, element.getDeclaringElement(), model);
+ }
+
+ public static <Type extends ObjectModelElement> Collection<Type> getElementsWithStereotype(
+ Collection<Type> elements, String... stereotypes) {
+ Collection<Type> result = new ArrayList<Type>();
+ for (Type element : elements) {
+ if (hasStereotypes(element, stereotypes)) {
+ result.add(element);
+ }
+ }
+ return result;
+ }
+
+ public static boolean hasStereotypes(ObjectModelElement element,
+ String... stereotypes) {
+ for (String stereotype : stereotypes) {
+ if (!element.hasStereotype(stereotype)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static String getPrimaryKeyAttributesListDeclaration(
+ ObjectModelClass clazz, boolean includeName) {
+ String attributes = "";
+ for (ObjectModelAttribute attr : getElementsWithStereotype(clazz.getAttributes(), STEREOTYPE_PRIMARYKAY)) {
+ attributes += attr.getType();
+ if (includeName) {
+ attributes += " " + attr.getName();
+ }
+ attributes += ", ";
+ }
+ if (attributes.length() > 0) {
+ attributes = attributes.substring(0, attributes.length() - 2);
+ }
+ return attributes;
+ }
+
+ public static String capitalize(String s) {
+ return StringUtils.capitalize(s);
+ }
+
+ public static boolean isAssociationClassDoublon(ObjectModelAttribute attr) {
+ return (attr.getReverseAttribute() != null) && (attr.getDeclaringElement().equals(attr.getReverseAttribute().getDeclaringElement())) && (!GeneratorUtil.isFirstAttribute(attr));
+ }
+
+ /**
+ * Renvoie le nom de l'attribut de classe d'association en fonction des cas:
+ * Si l'attribut porte le même nom que le type (extrémité inverse de
+ * l'association), on lui ajoute le nom de la classe d'association
+ *
+ * @param attr l'attribut a traiter
+ * @return le nom de l'attribut de classe d'association
+ */
+ public static String getAssocAttrName(ObjectModelAttribute attr) {
+ String typeName = attr.getType().substring(
+ attr.getType().lastIndexOf(".") + 1);
+ String result = attr.getName();
+ if (attr.getName().equalsIgnoreCase(typeName)) {
+ result += capitalize(attr.getAssociationClass().getName());
+ }
+ return result;
+ }
+
+ public static String getDOType(ObjectModelElement elem, ObjectModel model) {
+ String type = elem.getName();
+ if (elem instanceof ObjectModelAttribute) {
+ type = ((ObjectModelAttribute) elem).getType();
+ }
+ if (elem instanceof ObjectModelClass) {
+ type = ((ObjectModelClass) elem).getQualifiedName();
+ }
+ return getDOType(type, model);
+ }
+
+ public static String getDOType(String type, ObjectModel model) {
+ if (!model.hasClass(type)) {
+ return type;
+ }
+ ObjectModelClass clazz = model.getClass(type);
+ if (clazz.hasStereotype(STEREOTYPE_ENTITY)) {
+ if (shouldBeAbstract(clazz)) {
+ type += "Abstract";
+ } else {
+ type += "Impl";
+ }
+ }
+ return type;
+ }
+ private static final Set<String> numberTypes = new HashSet<String>();
+ private static final Set<String> textTypes = new HashSet<String>();
+ private static final Set<String> booleanTypes = new HashSet<String>();
+ private static final Set<String> primitiveTypes = new HashSet<String>();
+ private static final String VOID_TYPE = "void";
+
+ static {
+ numberTypes.add("byte");
+ numberTypes.add("java.lang.Byte");
+ numberTypes.add("Byte");
+ numberTypes.add("short");
+ numberTypes.add("java.lang.Short");
+ numberTypes.add("Short");
+ numberTypes.add("int");
+ numberTypes.add("java.lang.Integer");
+ numberTypes.add("Integer");
+ numberTypes.add("long");
+ numberTypes.add("java.lang.Long");
+ numberTypes.add("Long");
+ numberTypes.add("float");
+ numberTypes.add("java.lang.Float");
+ numberTypes.add("Float");
+ numberTypes.add("double");
+ numberTypes.add("java.lang.Double");
+ numberTypes.add("Double");
+
+ textTypes.add("char");
+ textTypes.add("java.lang.Char");
+ textTypes.add("Char");
+ textTypes.add("java.lang.String");
+ textTypes.add("String");
+
+ booleanTypes.add("boolean");
+ booleanTypes.add("java.lang.Boolean");
+ booleanTypes.add("Boolean");
+
+ primitiveTypes.addAll(numberTypes);
+ primitiveTypes.addAll(textTypes);
+ primitiveTypes.addAll(booleanTypes);
+ }
+
+ public static boolean isNumericType(ObjectModelAttribute attr) {
+ return numberTypes.contains(attr.getType());
+ }
+
+ public static boolean isTextType(ObjectModelAttribute attr) {
+ return textTypes.contains(attr.getType());
+ }
+
+ public static boolean isDateType(ObjectModelAttribute attr) {
+ return "java.util.Date".equals(attr.getType());
+ }
+
+ public static boolean isBooleanType(ObjectModelAttribute attr) {
+ return booleanTypes.contains(attr.getType());
+ }
+
+ public static boolean isPrimitiveType(ObjectModelAttribute attr) {
+ return primitiveTypes.contains(attr.getType());
+ }
+
+ /**
+ * Indique si la classe specifiee n'a aucune ou que des methodes abstraites
+ *
+ * @param clazz l'instance de ObjectModelClass
+ * @return true si la classe n'a que des operations abstraite ou aucune
+ * operation
+ */
+ public static boolean hasNothingOrAbstractMethods(ObjectModelClass clazz) {
+ boolean result = true;
+ Iterator<?> operations = clazz.getOperations().iterator();
+ while (result && operations.hasNext()) {
+ ObjectModelOperation op = (ObjectModelOperation) operations.next();
+ result = op.isAbstract();
+ }
+ return result;
+ }
+
+ /**
+ * Indique si la classe specifiee devrait etre abstraite
+ *
+ * @param clazz l'instance de ObjectModelClass
+ * @return true dans ce cas, false sinon
+ */
+ public static boolean shouldBeAbstract(ObjectModelClass clazz) {
+ return clazz != null && (clazz.isAbstract() && hasNothingOrAbstractMethods(clazz));
+ }
+
+ /**
+ * <p>
+ * Cette méthode permet de détecter si
+ * - l'attribut représente une relation 1-n
+ * - cette relation est unidirectionnelle
+ * - le type de l'attribut représente un entité
+ * - cette entité a des sous-classes dans le modèle
+ * <p/>
+ * Ce cas correspond à une incompatibilité d'Hibernate qui nous oblige a
+ * adopter un comportement particulier.
+ * </p>
+ *
+ * @param attr l'attribut a tester
+ * @param model le model
+ * @return true si et seulement si il s'agit bien de ce type de relation
+ */
+ public static boolean hasUnidirectionalRelationOnAbstractType(
+ ObjectModelAttribute attr, ObjectModel model) {
+ ObjectModelAttribute reverse = attr.getReverseAttribute();
+ //relation 1-n
+ if (reverse != null && isNMultiplicity(attr) && !isNMultiplicity(reverse)) {
+ //Pas de navigabilité
+ if (!reverse.isNavigable()) {
+ //Il s'agit d'une entity
+ ObjectModelClass clazz = model.getClass(attr.getType());
+ if (clazz != null && clazz.hasStereotype(STEREOTYPE_ENTITY)) {
+ //Cette classe a des sous-classes dans le modèle
+ for (ObjectModelClass subClass : model.getClasses()) {
+ if (subClass.getSuperclasses().contains(clazz)) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Renvoie le nom unique de table pour une relation ManyToMany en fonction
+ * de l'attribut <code>attr</code>
+ * <p/>
+ * Plusieurs cas de figure:
+ * <li>
+ *
+ * @param attr l'attribut servant de base au calcul du nom
+ * @return le nom de la table
+ */
+ public static String getManyToManyTableName(ObjectModelAttribute attr) {
+ String result;
+
+ if (attr.hasAssociationClass()) {
+ result = TopiaGeneratorUtil.getDBName(attr.getAssociationClass());
+ } else {
+ String name = attr.getName();
+ String revers = attr.getReverseAttributeName();
+
+ if (name.compareToIgnoreCase(revers) < 0) {
+ result = name + "_" + revers;
+ } else {
+ result = revers + "_" + name;
+ }
+ }
+ // String result;
+ // if (!Util.isFirstAttribute(attr)) {
+ // result = attr.getDeclaringElement().getName() + "_" + attr.getReverseAttribute().getDeclaringElement().getName();
+ // } else {
+ // result = attr.getReverseAttribute().getDeclaringElement().getName() + "_" + attr.getDeclaringElement().getName();
+ // }
+ return result.toLowerCase();
+ }
+
+ /**
+ * Renvoie le type d'interface à utiliser en fonction de l'attribut
+ *
+ * @param attr l'attribut a traiter
+ * @return String
+ */
+ public static String getNMultiplicityInterfaceType(ObjectModelAttribute attr) {
+ if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
+ return Set.class.getName();
+ } else if (attr.isIndexed() || attr.isOrdered()) {
+ return List.class.getName();
+ }
+ return Collection.class.getName();
+ }
+
+ /**
+ * Renvoie le type d'objet (instance) à utiliser en fonction de l'attribut
+ *
+ * @param attr l'attribut a traiter
+ * @return String
+ */
+ public static String getNMultiplicityObjectType(ObjectModelAttribute attr) {
+ if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
+ return HashSet.class.getName();
+ } else if (attr.isIndexed() || attr.isOrdered()) {
+ //On considère qu'on ne sait pas traiter vraiment l'attribut "ordered"
+ // puisqu'on va conserver l'ordre d'insertion, et non un ordre en
+ // fonction d'un élément donné. Donc on renvoi une ArrayList
+ return ArrayList.class.getName();
+ }
+ LinkedList.class.getName();
+ return ArrayList.class.getName();
+ }
+
+ /**
+ * Renvoie le type d'interface à utiliser en fonction de l'attribut
+ *
+ * @param attr l'attribut a traiter
+ * @return String
+ */
+ public static String getNMultiplicityHibernateType(ObjectModelAttribute attr) {
+ if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
+ return "set";
+ } else if (attr.isIndexed()) {
+ return "list";
+ }
+ //attr.isOrdered() - On génère le ordered en bag
+ return "bag";
+ }
+
+ /**
+ * Obtain the list of entities classes with the possibility to sort the result.
+ *
+ * @param model the current model to scan
+ * @param sort flag to allow sort the result
+ * @return the list of filtred classes by their stereotype
+ */
+ public static List<ObjectModelClass> getEntityClasses(ObjectModel model,
+ boolean sort) {
+ return getClassesByStereotype(STEREOTYPE_ENTITY, model, sort);
+ }
+
+ /**
+ * Obtain the list of classes for a given stereotype with the possibility to sort the result.
+ *
+ * @param stereotype filter stereotype
+ * @param model the current model to scan
+ * @param sort flag to allow sort the result
+ * @return the list of filtred classes by their stereotype
+ */
+ public static List<ObjectModelClass> getClassesByStereotype(
+ String stereotype, ObjectModel model, boolean sort) {
+ List<ObjectModelClass> classes = new ArrayList<ObjectModelClass>();
+ for (ObjectModelClass clazz : model.getClasses()) {
+ if (clazz.hasStereotype(stereotype)) {
+ classes.add(clazz);
+ }
+ }
+ if (sort && !classes.isEmpty()) {
+ java.util.Collections.sort(classes,
+ new java.util.Comparator<ObjectModelClass>() {
+
+ @Override
+ public int compare(ObjectModelClass o1,
+ ObjectModelClass o2) {
+ return o1.getQualifiedName().compareTo(
+ o2.getQualifiedName());
+ }
+ });
+ }
+ return classes;
+ }
+
+ /**
+ * Detecte si la clef metier d'une classe est mutable ou pas.
+ * <p/>
+ * On respecte la valeur par defaut d'hibernate, à savoir que par default une clef metier est non mutable.
+ *
+ * @param clazz la classe a tester
+ * @return <code>true</code> si le tag value a ete positionne sur la classe via le tag
+ * {@link #TAG_NATURAL_ID_MUTABLE}, , <code>false</code> sinon.
+ */
+ public static boolean isNaturalIdMutable(ObjectModelClass clazz) {
+ String value = clazz.getTagValue(TAG_NATURAL_ID_MUTABLE);
+ if (!notEmpty(value)) {
+ // valeur null, donc par default positionnee
+ return false;
+ }
+ try {
+ return Boolean.valueOf(value.trim());
+ } catch (Exception e) {
+ // on a pas reussi a convertir en boolean.
+ //todo peut-être declancher une exception ?
+ return false;
+ }
+ }
+
+ /**
+ * Obtain the list of fqn of object involed in the given class.
+ *
+ * @param aClass the clazz to inspect
+ * @param incomingFqns incoming fqns
+ * @return the list of fqn of attributes
+ */
+ public static List<String> getImports(ObjectModelClass aClass, String... incomingFqns) {
+ Set<String> tmp = new HashSet<String>();
+ tmp.addAll(Arrays.asList(incomingFqns));
+ getImports(aClass, tmp);
+ List<String> result = cleanImports(aClass.getPackageName(), tmp);
+ return result;
+ }
+
+ /**
+ * Obtain the list of fqn of object involed in the given interface.
+ *
+ * @param anInterface the interface to inspect
+ * @param incomingFqns incoming fqns
+ * @return the list of fqn of attributes
+ */
+ public static List<String> getImports(ObjectModelInterface anInterface, String... incomingFqns) {
+ Set<String> tmp = new HashSet<String>();
+ tmp.addAll(Arrays.asList(incomingFqns));
+ getImports(anInterface, tmp);
+ List<String> result = cleanImports(anInterface.getPackageName(), tmp);
+ return result;
+ }
+
+ public static String getSimpleName(String fqn) {
+ int lasIndex = fqn.lastIndexOf(".");
+ if (lasIndex == 1) {
+ // primitive type
+ return fqn;
+ }
+ return fqn.substring(lasIndex + 1);
+ /*if (lasIndex == aClass.getPackageName().length()) {
+ // same package
+ return fqn.substring(lasIndex + 1);
+ }
+
+ return fqn;*/
+ }
+
+ /**
+ * Obtain the list of fqn of object involed in the given class.
+ *
+ * @param aClass the class to inspect
+ * @param fqns where to store found fqns
+ */
+ protected static void getImports(ObjectModelClass aClass, Set<String> fqns) {
+ // scan attributes
+ for (ObjectModelAttribute attr : aClass.getAttributes()) {
+ fqns.add(attr.getType());
+ if (isNMultiplicity(attr)) {
+ String collectionType = getNMultiplicityInterfaceType(attr);
+ fqns.add(collectionType);
+ String collectionObject = getNMultiplicityObjectType(attr);
+ fqns.add(collectionObject);
+ }
+ }
+ for (ObjectModelAttribute attribute : aClass.getAllOtherAttributes()) {
+ fqns.add(attribute.getType());
+ }
+ // scan associations
+ if (aClass instanceof ObjectModelAssociationClass) {
+ ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) aClass;
+ for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
+ if (attr == null) {
+ continue;
+ }
+ fqns.add(attr.getType());
+ if (isNMultiplicity(attr)) {
+ String collectionType = getNMultiplicityInterfaceType(attr);
+ fqns.add(collectionType);
+ String collectionObject = getNMultiplicityObjectType(attr);
+ fqns.add(collectionObject);
+ }
+ }
+ }
+ // scan operations
+ for (ObjectModelOperation operation : aClass.getOperations()) {
+ getImports(operation, fqns);
+ }
+ // scan super interfaces
+ for (ObjectModelInterface modelInterface : aClass.getInterfaces()) {
+ fqns.add(modelInterface.getQualifiedName());
+ getImports(modelInterface, fqns);
+ }
+ // scan super classes
+ for (ObjectModelClass modelClass : aClass.getSuperclasses()) {
+ fqns.add(modelClass.getQualifiedName());
+ getImports(modelClass);
+ }
+ }
+
+ /**
+ * Obtain the list of fqn of object involed in the given interface.
+ *
+ * @param anInterface the interface to inspect
+ * @param fqns where to store found fqns
+ */
+ protected static void getImports(ObjectModelInterface anInterface, Set<String> fqns) {
+ // scan operations
+ for (ObjectModelOperation operation : anInterface.getOperations()) {
+ getImports(operation, fqns);
+ }
+ // scan super interfaces
+ for (ObjectModelInterface modelInterface : anInterface.getInterfaces()) {
+ fqns.add(modelInterface.getQualifiedName());
+ getImports(modelInterface, fqns);
+ }
+ }
+
+ /**
+ * Obtain the fqn's list of all involed type in a givne operation.
+ *
+ * @param operation operation to inspect
+ * @param fqns where to store found fqns
+ */
+ protected static void getImports(ObjectModelOperation operation, Set<String> fqns) {
+ String fqn = operation.getReturnType();
+ fqns.add(fqn);
+ for (ObjectModelParameter parameter : operation.getParameters()) {
+ fqns.add(parameter.getType());
+ }
+ }
+
+ /**
+ * Clean a set of fqns, transform it into a {@link List} and sort it.
+ *
+ * @param packageName the current package name
+ * @param fqns the dirty set of fqns
+ * @return the sorted cleaned list of fqns.
+ */
+ protected static List<String> cleanImports(String packageName, Set<String> fqns) {
+ fqns.removeAll(primitiveTypes);
+ fqns.remove(VOID_TYPE);
+ int packageLength = packageName.length();
+ List<String> genericType = new ArrayList<String>();
+ for (Iterator<String> it = fqns.iterator(); it.hasNext();) {
+ String fqn = it.next();
+ int lastIndex = fqn.lastIndexOf(".");
+ if (lastIndex == packageLength && fqn.startsWith(packageName)) {
+ // same package
+ it.remove();
+ continue;
+ }
+ int genericIndex = fqn.indexOf('<');
+ if (genericIndex != -1) {
+ genericType.add(fqn.substring(0, genericIndex));
+ it.remove();
+ }
+ }
+ fqns.addAll(genericType);
+
+ ArrayList<String> result = new ArrayList<String>(fqns);
+ java.util.Collections.sort(result);
+ return result;
+ }
+
+ /**
+ * Convertit un nom de variable en nom de constante.
+ *
+ * @param variableName le nom de variable a convertir
+ * @return le nom de la constante à partir du nom de la variable
+ */
+ public static String convertVariableNameToConstantName(String variableName) {
+ //TODO Faire des tests pour savoir si variableName est non null et valide
+ //TODO Ameliorer l'algo pour tenir compte des caractères non alpha
+ //TODO pour le moment cela convient, donc...
+ StringBuilder buffer = new StringBuilder();
+ boolean lastCarIsUp = false;
+ for (int i = 0, j = variableName.length(); i < j; i++) {
+ char c = variableName.charAt(i);
+ boolean carIsUp = Character.isUpperCase(c);
+ if (i > 0 && !lastCarIsUp && carIsUp) {
+ // ajout d'un _
+ buffer.append('_');
+ }
+ if (carIsUp) {
+ buffer.append(c);
+ } else {
+ buffer.append(Character.toUpperCase(c));
+ }
+ lastCarIsUp = carIsUp;
+ }
+ return buffer.toString();
+ }
+} // GeneratorUtil
+
Added: branches/1.1.0-Javabuilder/eugene-test/src/main/models/dtotest.objectmodel
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/models/dtotest.objectmodel (rev 0)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/models/dtotest.objectmodel 2009-10-27 10:32:23 UTC (rev 661)
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<objectModel xmlns="http://www.codelutin.org/eugene/objectModel" name="TopiaTest" version="1">
+ <class name="Personne" package="org.nuiton.eugene.test">
+ <stereotype name="entity"/>
+ <superclass name="org.nuiton.eugene.test.Party2" discriminator=""/>
+ <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="otherNames" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="0" maxMultiplicity="-1"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.Address" reverseAttributeName="" associationType="aggregate" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/>
+ </class>
+ <class name="Employe" package="org.nuiton.eugene.test">
+ <stereotype name="entity"/>
+ <superclass name="org.nuiton.eugene.test.Personne" discriminator=""/>
+ <attribute name="salary" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.Company" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="false" ordering="unordered"/>
+ <attribute name="lead" visibility="public" type="org.nuiton.eugene.test.Department" reverseAttributeName="leader" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="1" navigable="false" ordering="unordered"/>
+ </class>
+ <class name="Company" package="org.nuiton.eugene.test">
+ <stereotype name="entity"/>
+ <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.Employe" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/>
+ <attribute visibility="public" associationClassName="org.nuiton.eugene.test.Bill" type="org.nuiton.eugene.test.Store" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.Department" reverseAttributeName="" associationType="composite" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/>
+ </class>
+ <class name="Address" package="org.nuiton.eugene.test">
+ <stereotype name="entity"/>
+ <attribute name="city" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="adress" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.Personne" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="false" ordering="unordered"/>
+ </class>
+ <class name="Department" package="org.nuiton.eugene.test">
+ <stereotype name="entity"/>
+ <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="leader" visibility="public" type="org.nuiton.eugene.test.Employe" reverseAttributeName="lead" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.Company" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.Product" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/>
+ </class>
+ <class name="Product" package="org.nuiton.eugene.test">
+ <stereotype name="entity"/>
+ <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.Department" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="false" ordering="unordered"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.Type" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/>
+ </class>
+ <class name="Store" package="org.nuiton.eugene.test">
+ <stereotype name="entity"/>
+ <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="DEFAULT_NUM" associationType="composite" visibility="public" static="true" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="numStore" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <operation name="getDefaultNum" visibility="public" static="true">
+ <returnParameter type="java.lang.String"/>
+ </operation>
+ <class name="Row" package="org.nuiton.eugene.test">
+ <attribute name="num" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="position" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ </class>
+ <attribute visibility="public" associationClassName="org.nuiton.eugene.test.Bill" type="org.nuiton.eugene.test.Company" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="0" maxMultiplicity="-1" navigable="false" ordering="unordered"/>
+ </class>
+ <class name="Type" package="org.nuiton.eugene.test">
+ <stereotype name="entity"/>
+ <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.Product" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="false" ordering="unordered"/>
+ </class>
+ <associationClass name="Bill" package="org.nuiton.eugene.test">
+ <stereotype name="entity"/>
+ <participant name="org.nuiton.eugene.test.Company" attribute=""/>
+ <participant name="org.nuiton.eugene.test.Store" attribute=""/>
+ <attribute name="cost" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="date" associationType="composite" visibility="public" type="java.util.Date" minMultiplicity="1" maxMultiplicity="1"/>
+ </associationClass>
+ <class name="Voiture" abstract="true" package="org.nuiton.eugene.test.beangen">
+ <stereotype name="bean"/>
+ <tagValue name="documentation" value="Doc for BeanA"/>
+ <interface name="org.nuiton.eugene.test.beangen.Vehicule"/>
+ <attribute name="immatriculation" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1">
+ <tagValue name="documentation" value="attrA of BeanA"/>
+ </attribute>
+ <attribute name="modele" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="proprietaire" associationType="composite" visibility="public" type="org.nuiton.eugene.test.Personne" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.beangen.Roue" reverseAttributeName="" associationType="composite" reverseMaxMultiplicity="1" minMultiplicity="4" maxMultiplicity="4" navigable="true" ordering="unordered"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.beangen.Siege" reverseAttributeName="" associationType="composite" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="4" navigable="true" ordering="unordered"/>
+ </class>
+ <class name="Roue" package="org.nuiton.eugene.test.beangen">
+ <stereotype name="bean"/>
+ <operation name="mount" visibility="public">
+ <returnParameter type="void"/>
+ </operation>
+ <operation name="getModel" visibility="public">
+ <returnParameter type="org.nuiton.eugene.test.Product"/>
+ <parameter name="id" type="java.lang.String"/>
+ </operation>
+ <attribute visibility="public" type="org.nuiton.eugene.test.beangen.Voiture" reverseAttributeName="" reverseMaxMultiplicity="4" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/>
+ </class>
+ <class name="RelationDTO" package="org.nuiton.eugene.test.beangen">
+ <stereotype name="dto"/>
+ <attribute name="idCompany" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="idDepartement" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="dateDebut" associationType="composite" visibility="public" type="java.util.Date" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="person" visibility="public" type="org.nuiton.eugene.test.beangen.PersonneDTO" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/>
+ </class>
+ <class name="PersonneDTO" package="org.nuiton.eugene.test.beangen">
+ <dependency name="" supplierName="org.nuiton.eugene.test.Personne"/>
+ <stereotype name="dto"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.beangen.RelationDTO" reverseAttributeName="person" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="false" ordering="unordered"/>
+ </class>
+ <class name="Siege" package="org.nuiton.eugene.test.beangen">
+ <stereotype name="bean"/>
+ <attribute name="noSerie" associationType="composite" visibility="public" type="int" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute visibility="public" type="org.nuiton.eugene.test.beangen.Voiture" reverseAttributeName="" reverseMaxMultiplicity="4" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/>
+ </class>
+ <interface name="Vehicule" package="org.nuiton.eugene.test.beangen">
+ <operation name="start" visibility="public">
+ <returnParameter type="void"/>
+ </operation>
+ </interface>
+ <class name="Contact2" package="org.nuiton.eugene.test.deletetest">
+ <stereotype name="entity"/>
+ <attribute name="contactValue" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="type" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <operation name="findAllByCompany" visibility="public">
+ <returnParameter type="java.util.Set<Contact2>"/>
+ <parameter name="company" type="org.nuiton.eugene.test.Company"/>
+ <stereotype name="dao"/>
+ </operation>
+ <attribute visibility="public" type="org.nuiton.eugene.test.Party2" reverseAttributeName="contacts" reverseMaxMultiplicity="-1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/>
+ </class>
+ <class name="Telephone2" package="org.nuiton.eugene.test.deletetest">
+ <stereotype name="entity"/>
+ <superclass name="org.nuiton.eugene.test.Contact2" discriminator=""/>
+ <attribute name="prefix" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="country" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ </class>
+ <class name="Party2" package="org.nuiton.eugene.test.deletetest">
+ <stereotype name="entity"/>
+ <attribute name="contacts" visibility="public" type="org.nuiton.eugene.test.Contact2" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/>
+ </class>
+ <class name="Person" package="org.nuiton.topia.test.entities">
+ <stereotype name="entity"/>
+ <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="firstname" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute visibility="public" type="org.nuiton.topia.test.entities.Pet" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="0" maxMultiplicity="-1" navigable="true" ordering="unordered"/>
+ </class>
+ <class name="Pet" package="org.nuiton.topia.test.entities">
+ <stereotype name="entity"/>
+ <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute name="type" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute visibility="public" type="org.nuiton.topia.test.entities.Person" reverseAttributeName="" reverseMaxMultiplicity="-1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/>
+ <attribute visibility="public" type="org.nuiton.topia.test.entities.Race" reverseAttributeName="" associationType="composite" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="true" ordering="unordered"/>
+ </class>
+ <class name="Race" package="org.nuiton.topia.test.entities">
+ <stereotype name="entity"/>
+ <attribute name="name" associationType="composite" visibility="public" type="java.lang.String" minMultiplicity="1" maxMultiplicity="1"/>
+ <attribute visibility="public" type="org.nuiton.topia.test.entities.Pet" reverseAttributeName="" reverseMaxMultiplicity="1" minMultiplicity="1" maxMultiplicity="1" navigable="false" ordering="unordered"/>
+ </class>
+ <class name="Set<Contact2>" package="java.util"/>
+</objectModel>
Added: branches/1.1.0-Javabuilder/eugene-test/src/test/resources/log4j.properties
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/test/resources/log4j.properties (rev 0)
+++ branches/1.1.0-Javabuilder/eugene-test/src/test/resources/log4j.properties 2009-10-27 10:32:23 UTC (rev 661)
@@ -0,0 +1,12 @@
+# Global logging configuration
+log4j.rootLogger=ERROR, stdout
+
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
+
+# package level
+log4j.logger.org.nuiton.eugene=INFO
+log4j.logger.org.nuiton.eugene.test=DEBUG
+log4j.logger.org.nuiton.processor=DEBUG
Modified: branches/1.1.0-Javabuilder/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java
===================================================================
--- branches/1.1.0-Javabuilder/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java 2009-10-26 18:35:44 UTC (rev 660)
+++ branches/1.1.0-Javabuilder/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java 2009-10-27 10:32:23 UTC (rev 661)
@@ -33,7 +33,9 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
+import org.nuiton.eugene.ModelReader;
import org.nuiton.eugene.Generator;
+import org.nuiton.eugene.models.Model;
import org.nuiton.plugin.PluginIOContext;
import org.nuiton.plugin.PluginHelper;
@@ -136,10 +138,20 @@
*/
protected String generatedPackages;
+ /**
+ * Reader for transform input files in a Model to generate
+ *
+ * @parameter expression="${eugene.reader}"
+ * @since 1.1.0
+ */
+ protected String reader;
+
+
@Override
public void doAction() throws MojoExecutionException, MojoFailureException {
getLog().info("Generating java sources from models");
+ getLog().info(" reader : " + reader);
getLog().info(" includes : " + includes);
getLog().info(" using template : " + templates);
getLog().info(" using defaultPackage : " + defaultPackage);
@@ -156,6 +168,14 @@
}
}
+ ModelReader modelReader = getReader();
+ if (modelReader == null) {
+ // can skip
+ getLog().warn("no reader to use");
+ return;
+ }
+ Model model = modelReader.read(modelFiles);
+
List<String> packages = getPackagesToGenerate();
if (packages == null) {
@@ -164,13 +184,14 @@
getLog().info(" generating only for packages " + packages);
}
- List<Generator> generators = getGenerators(packages);
+ List<Generator> generators = getGenerators(packages, modelReader);
for (Generator generator : generators) {
getLog().info("Apply " + generator.getClass().getSimpleName() + " generator");
//TC-20090829 fix when loading more than one model together...
- generator.generate(modelFiles, generateResources.getOutput());
+
+ generator.generate(model, generateResources.getOutput());
// for (File modelFile : modelFiles) {
// getLog().debug(" on " + modelFile.getAbsolutePath());
//
@@ -261,7 +282,24 @@
// return modelFiles.toArray(new File[modelFiles.size()]);
// }
- protected List<Generator> getGenerators(List<String> generatedPackagesAsList) throws MojoFailureException, MojoExecutionException {
+ protected ModelReader getReader() throws MojoFailureException, MojoExecutionException {
+ ModelReader modelReader = null;
+ try {
+ ClassLoader fixedClassLoader = fixClassLoader();
+ modelReader = (ModelReader) Class.forName(reader,
+ true, fixedClassLoader).newInstance();
+ } catch (InstantiationException eee) {
+ throw new MojoFailureException("Can't instantiate reader : " + reader, eee);
+ } catch (IllegalAccessException eee) {
+ throw new MojoFailureException("Can't access reader : " + reader, eee);
+ } catch (ClassNotFoundException eee) {
+ throw new MojoFailureException("Can't found reader : " + reader, eee);
+ }
+ return modelReader;
+ }
+
+ protected List<Generator> getGenerators(List<String> generatedPackagesAsList, ModelReader modelReader)
+ throws MojoFailureException, MojoExecutionException {
// init generators
Properties generatorProperties = new Properties();
generatorProperties.setProperty("defaultPackage", defaultPackage);
@@ -279,6 +317,7 @@
generator.setProperties(generatorProperties);
generator.setOverwrite(overwrite);
generator.setEncoding(encoding);
+ generator.setLastModifiedSource(modelReader.getLastModifiedSource());
generator.setGeneratedPackages(generatedPackagesAsList);
generators.add(generator);
} catch (InstantiationException e) {
1
0
r659 - branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene
by fdesbois@users.nuiton.org 27 Oct '09
by fdesbois@users.nuiton.org 27 Oct '09
27 Oct '09
Author: fdesbois
Date: 2009-10-26 19:18:35 +0100 (Mon, 26 Oct 2009)
New Revision: 659
Added:
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/FileReader.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java
Log:
- Create FileReader abstract
- Create ObjectModelReader
Added: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/FileReader.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/FileReader.java (rev 0)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/FileReader.java 2009-10-26 18:18:35 UTC (rev 659)
@@ -0,0 +1,65 @@
+
+package org.nuiton.eugene;
+
+import java.io.File;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.models.Model;
+
+/**
+ * FileReader
+ *
+ * Created: 26 oct. 2009
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public abstract class FileReader<M extends Model> {
+
+ private static final Log log = LogFactory.getLog(FileReader.class);
+
+ /** date de derniere modification de la source la plus recente */
+ protected long lastModifiedSource = 0;
+
+ protected void setLastModifiedSource(File[] files) {
+ for (File file : files) {
+ if (isNewerThanSource(file)) {
+ lastModifiedSource = file.lastModified();
+ log.debug("source date: " + lastModifiedSource
+ + " files[i] date: " + file.lastModified() + "(" + file
+ + ")");
+ }
+ }
+ }
+
+ protected long getLastModifiedSource() {
+ return lastModifiedSource;
+ }
+
+ /**
+ * @param file fichier a tester
+ * @return vrai si le fichier passé en parametre est plus recent que
+ * les sources sur generateur.
+ */
+ protected boolean isNewerThanSource(File file) {
+ if (log.isDebugEnabled()) {
+ log.debug("source date: " + getLastModifiedSource()
+ + " file date: " + file.lastModified() + "(" + file + ")");
+ }
+ return file.lastModified() > getLastModifiedSource();
+ }
+
+ public M read(File file, File destDir) {
+ return read(new File[] { file }, destDir);
+ }
+
+ public M read(File file) {
+ return read(new File[] { file }, new File("."));
+ }
+
+ public abstract M read(File[] file, File destDir);
+
+}
Added: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java (rev 0)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java 2009-10-26 18:18:35 UTC (rev 659)
@@ -0,0 +1,225 @@
+
+package org.nuiton.eugene;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.commons.digester.Digester;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.models.Model;
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelClassifier;
+import org.nuiton.eugene.models.object.ObjectModelElement;
+import org.nuiton.eugene.models.object.xml.DigesterObjectModelRuleSet;
+import org.nuiton.eugene.models.object.xml.ObjectModelClassifierImpl;
+import org.nuiton.eugene.models.object.xml.ObjectModelElementImpl;
+import org.nuiton.eugene.models.object.xml.ObjectModelImpl;
+import org.nuiton.eugene.models.object.xml.ObjectModelImplRef;
+import org.nuiton.eugene.models.object.xml.ObjectModelImplTagValue;
+import org.nuiton.util.FileUtil;
+import org.nuiton.util.RecursiveProperties;
+import org.nuiton.util.StringUtil;
+import org.xml.sax.SAXException;
+
+/**
+ * ObjectModelReader
+ *
+ * Created: 26 oct. 2009
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class ObjectModelReader extends FileReader<ObjectModel> {
+
+ private static final Log log = LogFactory.getLog(ObjectModelReader.class);
+
+ /**
+ * L'expression réguliere match les chaines de type
+ * <package.ClassName>.<class|attribute|operation>.[name].<stereotype|tagvalue>.[tag]
+ * fr.isisfish.entities.Population.class.stereotype=entity
+ * fr.isisfish.entities.Population.class.tagvalue.persistenceType=flatfile
+ * fr.isisfish.entities.Population.attribute.name.stereotype=...
+ * fr.isisfish.entities.Population.attribute.name.tagvalue.pk=topiaId
+ * fr.isisfish.entities.Population.operation.getRegion.stereotype=...
+ * fr.isisfish.entities.Population.operation.getRegion.tagvalue.pk=...
+ */
+ protected Pattern propertiesPattern = Pattern
+ .compile("((?:[_a-zA-Z0-9]+\\.)+(?:_?[A-Z][_a-zA-Z0-9]*\\.)+)(?:(class|attribute|operation)\\.)(?:([_a-z0-9][_a-zA-Z0-9]*)\\.)?(?:(stereotype|tagvalue)\\.?)([_a-z0-9][_a-zA-Z0-9]*)?");
+
+
+ /**
+ * @param files les noms des fichiers existant contenant du XML représentant
+ * des ObjectModel. Il est automatiquement recherche un fichier de
+ * propriété associé a ce fichier pour pouvoir ajouter des
+ * stereotype ou des tag value sur les class, attribute ou operation
+ * @param destDir le répertoire dans lequel il faudra mettre les fichiers
+ * générés
+ */
+ @Override
+ public ObjectModel read(File[] files, File destDir) {
+ setLastModifiedSource(files);
+ ObjectModel objectModel = new ObjectModelImpl();
+
+ // Digester parser configuration
+ Digester digester = new Digester();
+ digester.addRuleSet(new DigesterObjectModelRuleSet());
+
+ for (File file : files) {
+ try {
+ digester.push(objectModel);
+ objectModel = (ObjectModel) digester.parse(file);
+ } catch (IOException e) {
+ log.warn("Unable to parse ObjectModel input file : " + file, e);
+ } catch (SAXException e) {
+ log.warn("Unable to parse ObjectModel input file : " + file, e);
+ }
+
+ // recherche est charge le fichier propriete associe au modele
+ File dir = file.getParentFile();
+ String ext = FileUtil.extension(file);
+ String name = FileUtil.basename(file, "." + ext);
+ File propFile = new File(dir, name + ".properties");
+ RecursiveProperties prop = new RecursiveProperties();
+ if (!propFile.exists()) {
+ if (log.isInfoEnabled()) {
+ log.info("Pas de fichier de propriete " + propFile
+ + " associé au model");
+ }
+ } else {
+ if (log.isInfoEnabled()) {
+ log.info("Lecture du fichier de propriete " + propFile
+ + " associé au model");
+ }
+ try {
+ prop.load(new FileInputStream(propFile));
+ } catch (IOException eee) {
+ log.warn("Impossible de lire le fichier de propriete "
+ + propFile, eee);
+ }
+
+ // on ajoute les proprietes du fichier associe au model
+ for (Enumeration<Object> e = prop.keys(); e.hasMoreElements();) {
+ String key = (String) e.nextElement();
+ String value = prop.getProperty(key);
+
+ if (key.startsWith("model")) {
+ if (!key.startsWith("model.tagvalue.")) {
+ log.warn("only tagvalue is allowed on model in properties");
+ } else {
+ String tag = key.substring("model.tagvalue."
+ .length());
+
+ ObjectModelImplTagValue tagvalue = new ObjectModelImplTagValue();
+ tagvalue.setName(tag);
+ tagvalue.setValue(value);
+ ((ObjectModelImpl) objectModel)
+ .addTagValue(tagvalue);
+ }
+ } else {
+
+ Matcher matcher = propertiesPattern.matcher(key);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Propriete: '" + key + "'");
+ }
+
+ if (matcher.find()) {
+ // fqn is fully qualified name of class
+ String fqn = matcher.group(1);
+ fqn = StringUtil.substring(fqn, 0, -1); // remove ended
+ // .
+ // target is class, attribute or operation
+ String target = matcher.group(2);
+ String targetName = matcher.group(3);
+ // type is stereotype or tagvalue
+ String type = matcher.group(4);
+ String tag = matcher.group(5);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Propriete: '" + key + "' => "
+ + "fqn:" + fqn + " target:" + target
+ + " targetName:" + targetName
+ + " type:" + type + " tag:" + tag);
+ }
+
+ ObjectModelClassifier omc = objectModel
+ .getClassifier(fqn);
+ if (omc instanceof ObjectModelClassifierImpl) {
+ // on utilise une liste car il peut y avoir plusieur
+ // operation avec le nom donné
+ List<ObjectModelElement> elems = new ArrayList<ObjectModelElement>();
+ if ("class".equals(target)) {
+ elems.add(omc);
+ } else if ("attribute".equals(target)) {
+ ObjectModelClass classmodel = (ObjectModelClass) omc;
+ elems.add(classmodel
+ .getAttribute(targetName));
+ } else if ("operation".equals(target)) {
+ elems.addAll(omc.getOperations(targetName));
+ }
+ for (Object elem1 : elems) {
+ ObjectModelElementImpl elem = (ObjectModelElementImpl) elem1;
+ if ("stereotype".equals(type)) {
+ // pour les stereotypes
+ ObjectModelImplRef stereotype = new ObjectModelImplRef();
+ stereotype.setName(value);
+ elem.addStereotype(stereotype);
+ continue;
+ }
+
+ if ("tagvalue".equals(type)) {
+ // pour les tagvalues
+ ObjectModelImplTagValue tagvalue = new ObjectModelImplTagValue();
+ tagvalue.setName(tag);
+ tagvalue.setValue(value);
+ if (log.isDebugEnabled()) {
+ log.debug("tagValue:" + tagvalue
+ + ", tag:" + tag
+ + ", value:" + value
+ + ", element:" + elem);
+ }
+ if (elem == null) {
+ log.warn("can not attach tagValue "
+ + key);
+ } else {
+ elem.addTagValue(tagvalue);
+ }
+ }
+ }
+ } else {
+ // TODO il faudra avoir des methodes d'acces en
+ // Set sur l'interface pour eviter ce message
+ if (log.isWarnEnabled()) {
+ log.warn("Can't add properties to model, it's not an ObjectModelClassifierImpl");
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if (log.isDebugEnabled()) {
+ for (ObjectModelClass m : objectModel.getClasses()) {
+ log.debug("loaded class in objectmodel : " + m.getName());
+ }
+ }
+ return objectModel;
+ /*try {
+ generate(objectModel, destDir);
+ } catch (IOException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Unable to generate for file", eee);
+ }
+ }*/
+ }
+}
3
2
r660 - in branches/1.1.0-Javabuilder/eugene/src: main/java/org/nuiton/eugene main/java/org/nuiton/eugene/models/ui main/java/org/nuiton/eugene/models/ui/impl main/java/org/nuiton/eugene/models/ui/javaxml main/java/org/nuiton/eugene/models/ui/xml test/java/org/nuiton/eugene/models/ui/javaxml
by fdesbois@users.nuiton.org 26 Oct '09
by fdesbois@users.nuiton.org 26 Oct '09
26 Oct '09
Author: fdesbois
Date: 2009-10-26 19:35:44 +0100 (Mon, 26 Oct 2009)
New Revision: 660
Added:
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java
Removed:
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/UIModelGenerator.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModel.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelArguments.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelChild.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelConstraint.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelEvent.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelObject.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelProperty.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelArgumentsImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelChildImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelConstraintImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelEventImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelObjectImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelPropertyImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/javaxml/JavaXMLParser.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/DigesterUIModelRuleSet.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelArgumentsImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelChildImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelConstraintImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelEventImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelObjectImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelPropertyImpl.java
branches/1.1.0-Javabuilder/eugene/src/test/java/org/nuiton/eugene/models/ui/javaxml/JavaXMLParserTest.java
Modified:
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java
Log:
- Suppress old UIModel
- Refactor Generators to use Readers
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -46,8 +46,6 @@
protected Properties properties = new Properties();
protected boolean overwrite = true;
- /** date de derniere modification de la source la plus recente */
- protected long lastModifiedSource = 0;
protected List<String> excludeTemplates;
@@ -75,14 +73,6 @@
setEncoding(parent.getEncoding());
}
- public void generate(File file, File destDir) {
- generate(new File[] { file }, destDir);
- }
-
- public void generate(File file) {
- generate(new File[] { file }, new File("."));
- }
-
public void setProperties(Properties p) {
this.properties = p;
}
@@ -129,7 +119,7 @@
}
return properties.getProperty(name);
}
-
+/*
protected void setLastModifiedSource(File[] files) {
for (File file : files) {
if (isNewerThanSource(file)) {
@@ -148,18 +138,13 @@
return lastModifiedSource;
}
- /**
- * @param file fichier a tester
- * @return vrai si le fichier passé en parametre est plus recent que
- * les sources sur generateur.
- */
protected boolean isNewerThanSource(File file) {
if (log.isDebugEnabled()) {
log.debug("source date: " + getLastModifiedSource()
+ " file date: " + file.lastModified() + "(" + file + ")");
}
return file.lastModified() > getLastModifiedSource();
- }
+ }*/
protected File getDestinationFile(File destDir, String filename) {
return new File(destDir, filename);
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -91,18 +91,7 @@
protected ObjectModel model = null;
- /**
- * L'expression réguliere match les chaines de type
- * <package.ClassName>.<class|attribute|operation>.[name].<stereotype|tagvalue>.[tag]
- * fr.isisfish.entities.Population.class.stereotype=entity
- * fr.isisfish.entities.Population.class.tagvalue.persistenceType=flatfile
- * fr.isisfish.entities.Population.attribute.name.stereotype=...
- * fr.isisfish.entities.Population.attribute.name.tagvalue.pk=topiaId
- * fr.isisfish.entities.Population.operation.getRegion.stereotype=...
- * fr.isisfish.entities.Population.operation.getRegion.tagvalue.pk=...
- */
- protected Pattern propertiesPattern = Pattern
- .compile("((?:[_a-zA-Z0-9]+\\.)+(?:_?[A-Z][_a-zA-Z0-9]*\\.)+)(?:(class|attribute|operation)\\.)(?:([_a-z0-9][_a-zA-Z0-9]*)\\.)?(?:(stereotype|tagvalue)\\.?)([_a-z0-9][_a-zA-Z0-9]*)?");
+ protected ObjectModelReader reader;
public ObjectModelGenerator() {
super();
@@ -126,152 +115,8 @@
*/
@Override
public void generate(File[] files, File destDir) {
- setLastModifiedSource(files);
- ObjectModel objectModel = new ObjectModelImpl();
-
- // Digester parser configuration
- Digester digester = new Digester();
- digester.addRuleSet(new DigesterObjectModelRuleSet());
-
- for (File file : files) {
- try {
- digester.push(objectModel);
- objectModel = (ObjectModel) digester.parse(file);
- } catch (IOException e) {
- log.warn("Unable to parse ObjectModel input file : " + file, e);
- } catch (SAXException e) {
- log.warn("Unable to parse ObjectModel input file : " + file, e);
- }
-
- // recherche est charge le fichier propriete associe au modele
- File dir = file.getParentFile();
- String ext = FileUtil.extension(file);
- String name = FileUtil.basename(file, "." + ext);
- File propFile = new File(dir, name + ".properties");
- RecursiveProperties prop = new RecursiveProperties();
- if (!propFile.exists()) {
- if (log.isInfoEnabled()) {
- log.info("Pas de fichier de propriete " + propFile
- + " associé au model");
- }
- } else {
- if (log.isInfoEnabled()) {
- log.info("Lecture du fichier de propriete " + propFile
- + " associé au model");
- }
- try {
- prop.load(new FileInputStream(propFile));
- } catch (IOException eee) {
- log.warn("Impossible de lire le fichier de propriete "
- + propFile, eee);
- }
-
- // on ajoute les proprietes du fichier associe au model
- for (Enumeration<Object> e = prop.keys(); e.hasMoreElements();) {
- String key = (String) e.nextElement();
- String value = prop.getProperty(key);
-
- if (key.startsWith("model")) {
- if (!key.startsWith("model.tagvalue.")) {
- log.warn("only tagvalue is allowed on model in properties");
- } else {
- String tag = key.substring("model.tagvalue."
- .length());
-
- ObjectModelImplTagValue tagvalue = new ObjectModelImplTagValue();
- tagvalue.setName(tag);
- tagvalue.setValue(value);
- ((ObjectModelImpl) objectModel)
- .addTagValue(tagvalue);
- }
- } else {
-
- Matcher matcher = propertiesPattern.matcher(key);
-
- if (log.isDebugEnabled()) {
- log.debug("Propriete: '" + key + "'");
- }
-
- if (matcher.find()) {
- // fqn is fully qualified name of class
- String fqn = matcher.group(1);
- fqn = StringUtil.substring(fqn, 0, -1); // remove ended
- // .
- // target is class, attribute or operation
- String target = matcher.group(2);
- String targetName = matcher.group(3);
- // type is stereotype or tagvalue
- String type = matcher.group(4);
- String tag = matcher.group(5);
-
- if (log.isDebugEnabled()) {
- log.debug("Propriete: '" + key + "' => "
- + "fqn:" + fqn + " target:" + target
- + " targetName:" + targetName
- + " type:" + type + " tag:" + tag);
- }
-
- ObjectModelClassifier omc = objectModel
- .getClassifier(fqn);
- if (omc instanceof ObjectModelClassifierImpl) {
- // on utilise une liste car il peut y avoir plusieur
- // operation avec le nom donné
- List<ObjectModelElement> elems = new ArrayList<ObjectModelElement>();
- if ("class".equals(target)) {
- elems.add(omc);
- } else if ("attribute".equals(target)) {
- ObjectModelClass classmodel = (ObjectModelClass) omc;
- elems.add(classmodel
- .getAttribute(targetName));
- } else if ("operation".equals(target)) {
- elems.addAll(omc.getOperations(targetName));
- }
- for (Object elem1 : elems) {
- ObjectModelElementImpl elem = (ObjectModelElementImpl) elem1;
- if ("stereotype".equals(type)) {
- // pour les stereotypes
- ObjectModelImplRef stereotype = new ObjectModelImplRef();
- stereotype.setName(value);
- elem.addStereotype(stereotype);
- continue;
- }
-
- if ("tagvalue".equals(type)) {
- // pour les tagvalues
- ObjectModelImplTagValue tagvalue = new ObjectModelImplTagValue();
- tagvalue.setName(tag);
- tagvalue.setValue(value);
- if (log.isDebugEnabled()) {
- log.debug("tagValue:" + tagvalue
- + ", tag:" + tag
- + ", value:" + value
- + ", element:" + elem);
- }
- if (elem == null) {
- log.warn("can not attach tagValue "
- + key);
- } else {
- elem.addTagValue(tagvalue);
- }
- }
- }
- } else {
- // TODO il faudra avoir des methodes d'acces en
- // Set sur l'interface pour eviter ce message
- if (log.isWarnEnabled()) {
- log.warn("Can't add properties to model, it's not an ObjectModelClassifierImpl");
- }
- }
- }
- }
- }
- }
- }
- if (log.isDebugEnabled()) {
- for (ObjectModelClass m : objectModel.getClasses()) {
- log.debug("loaded class in objectmodel : " + m.getName());
- }
- }
+ reader = new ObjectModelReader();
+ ObjectModel objectModel = reader.read(files, destDir);
try {
generate(objectModel, destDir);
} catch (IOException eee) {
@@ -381,7 +226,7 @@
if (canGenerateElement(element)) {
File outputFile = getDestinationFile(destDir, filename);
- if (!getOverwrite() && isNewerThanSource(outputFile)) {
+ if (!getOverwrite() && reader.isNewerThanSource(outputFile)) {
if (log.isDebugEnabled()) {
log.debug("file " + outputFile + " is up-to-date");
}
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -63,6 +63,8 @@
/** Model */
protected StateModel model;
+ protected StateModelReader reader;
+
/**
* Empty constructor
*/
@@ -91,28 +93,9 @@
@Override
public void generate(File[] files, File destDir) {
- Digester digester = new Digester();
- digester.addRuleSet(new DigesterStateModelRuleSet());
+ reader = new StateModelReader();
+ StateModel stateModel = reader.read(files, destDir);
- StateModelImpl stateModel = new StateModelImpl();
-
- // process each file
- for (File file : files) {
-
- // fin a deplacer
- try {
- digester.push(stateModel);
- digester.parse(file);
-
- // try to load property file
- loadPropertyFile(file, stateModel);
- } catch (IOException e) {
- log.warn("Can't read model file", e);
- } catch (SAXException e) {
- log.warn("Can't read model file", e);
- }
- }
-
// generate code
try {
generate(stateModel, destDir);
@@ -121,50 +104,7 @@
}
}
- /**
- * Try to load property file, associated to current statemodel file
- *
- * @param stateModelFile
- * @param stateModel
- */
- protected void loadPropertyFile(File stateModelFile,
- StateModelImpl stateModel) {
- // recherche et charge le fichier propriete associe au modele
- File dir = stateModelFile.getParentFile();
- String ext = FileUtil.extension(stateModelFile);
- String name = FileUtil.basename(stateModelFile, "." + ext);
- File propFile = new File(dir, name + ".properties");
- RecursiveProperties prop = new RecursiveProperties();
- if (!propFile.exists()) {
- if (log.isInfoEnabled()) {
- log.info("No property file associated to model : " + propFile);
- }
- } else {
- if (log.isInfoEnabled()) {
- log.info("Reading model property file " + propFile);
- }
- try {
- prop.load(new FileInputStream(propFile));
- } catch (IOException e) {
- log.warn("Cannot read property file " + propFile, e);
- }
-
- // on ajoute les proprietes du fichier associe au model
- for (Enumeration<Object> e = prop.keys(); e.hasMoreElements();) {
- String key = (String) e.nextElement();
- String value = prop.getProperty(key);
-
- if (!key.startsWith("model.tagvalue.")) {
- log.warn("only tagvalue is allowed on model in properties");
- } else {
- String tag = key.substring("model.tagvalue.".length());
- stateModel.addTagValue(tag, value);
- }
- }
- }
- }
-
/**
* Par défaut, appel {@link #generateFromModel(MonitorWriter, org.nuiton.eugene.models.state.StateModel)} pour le
* model et {@link #generateFromState(Writer,StateModelState)} pour tous les
@@ -181,7 +121,7 @@
String filename = getFilenameFromModel(stateModel);
File outputFile = getDestinationFile(destDir, filename);
- if (getOverwrite() || !isNewerThanSource(outputFile)) {
+ if (getOverwrite() || !reader.isNewerThanSource(outputFile)) {
try {
StringWriter out = new StringWriter();
MonitorWriter monitorOut = new MonitorWriter(out);
@@ -208,7 +148,7 @@
String filenameState = getFilenameFromState(state, chart
.getName());
File outputFiletate = getDestinationFile(destDir, filenameState);
- if (getOverwrite() || !isNewerThanSource(outputFiletate)) {
+ if (getOverwrite() || !reader.isNewerThanSource(outputFiletate)) {
try {
StringWriter out = new StringWriter();
MonitorWriter monitorOut = new MonitorWriter(out);
Added: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java (rev 0)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -0,0 +1,102 @@
+
+package org.nuiton.eugene;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+import org.apache.commons.digester.Digester;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.models.state.StateModel;
+import org.nuiton.eugene.models.state.xml.DigesterStateModelRuleSet;
+import org.nuiton.eugene.models.state.xml.StateModelImpl;
+import org.nuiton.util.FileUtil;
+import org.nuiton.util.RecursiveProperties;
+import org.xml.sax.SAXException;
+
+/**
+ * StateModelReader
+ *
+ * Created: 26 oct. 2009
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class StateModelReader extends FileReader<StateModel> {
+
+ private static final Log log = LogFactory.getLog(StateModelReader.class);
+
+ @Override
+ public StateModel read(File[] files, File destDir) {
+ Digester digester = new Digester();
+ digester.addRuleSet(new DigesterStateModelRuleSet());
+
+ StateModelImpl stateModel = new StateModelImpl();
+
+ // process each file
+ for (File file : files) {
+
+ // fin a deplacer
+ try {
+ digester.push(stateModel);
+ digester.parse(file);
+
+ // try to load property file
+ loadPropertyFile(file, stateModel);
+ } catch (IOException e) {
+ log.warn("Can't read model file", e);
+ } catch (SAXException e) {
+ log.warn("Can't read model file", e);
+ }
+ }
+ return stateModel;
+ }
+
+ /**
+ * Try to load property file, associated to current statemodel file
+ *
+ * @param stateModelFile
+ * @param stateModel
+ */
+ protected void loadPropertyFile(File stateModelFile,
+ StateModelImpl stateModel) {
+ // recherche et charge le fichier propriete associe au modele
+ File dir = stateModelFile.getParentFile();
+ String ext = FileUtil.extension(stateModelFile);
+ String name = FileUtil.basename(stateModelFile, "." + ext);
+ File propFile = new File(dir, name + ".properties");
+ RecursiveProperties prop = new RecursiveProperties();
+
+ if (!propFile.exists()) {
+ if (log.isInfoEnabled()) {
+ log.info("No property file associated to model : " + propFile);
+ }
+ } else {
+ if (log.isInfoEnabled()) {
+ log.info("Reading model property file " + propFile);
+ }
+ try {
+ prop.load(new FileInputStream(propFile));
+ } catch (IOException e) {
+ log.warn("Cannot read property file " + propFile, e);
+ }
+
+ // on ajoute les proprietes du fichier associe au model
+ for (Enumeration<Object> e = prop.keys(); e.hasMoreElements();) {
+ String key = (String) e.nextElement();
+ String value = prop.getProperty(key);
+
+ if (!key.startsWith("model.tagvalue.")) {
+ log.warn("only tagvalue is allowed on model in properties");
+ } else {
+ String tag = key.substring("model.tagvalue.".length());
+ stateModel.addTagValue(tag, value);
+ }
+ }
+ }
+ }
+}
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/UIModelGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/UIModelGenerator.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/UIModelGenerator.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,176 +0,0 @@
-/*
- * \*##% Eugene
- * 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.nuiton.eugene;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.commons.digester.Digester;
-import org.dom4j.DocumentException;
-import org.nuiton.eugene.models.ui.UIModel;
-import org.nuiton.eugene.models.ui.UIModelObject;
-import org.nuiton.eugene.models.ui.UIModelProperty;
-import org.nuiton.eugene.models.ui.impl.UIModelImpl;
-import org.nuiton.eugene.models.ui.javaxml.JavaXMLParser;
-import org.nuiton.util.ResourceNotFoundException;
-import org.xml.sax.SAXException;
-
-/**
- * UIModelGenerator.java
- *
- * @author cecrid
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class UIModelGenerator extends Generator {
-
- protected UIModel model = null;
-
- public UIModelGenerator() {
- super();
-
- }
-
- public UIModelGenerator(Generator parent) {
- super(parent);
-
- }
-
- public UIModel getModel() {
- return model;
- }
-
- @Override
- public void generate(File[] tabUIFilesName, File destDir) {
- setLastModifiedSource(tabUIFilesName);
- for (int i = 0; i < tabUIFilesName.length; i++) {
- try {
- String fileName = tabUIFilesName[i].getName();
- UIModel ui = null;
- if (fileName.endsWith(".javaxml")) {
- JavaXMLParser parser = new JavaXMLParser();
- ui = parser.parse(tabUIFilesName[i]);
- } else {
-
- // New parser : commons-digester
- Digester digester = new Digester();
- ui = new UIModelImpl();
- digester.push(ui);
- digester.parse(tabUIFilesName[i]);
- }
- if (ui != null) {
- generate(ui, destDir);
- }
- } catch (ResourceNotFoundException eee) {
- System.out.println("Unable to parse topiaUI input file : " + i);
- eee.printStackTrace();
- } catch (IOException eee) {
- System.out.println("Unable to generate for file");
- eee.printStackTrace();
- } catch (DocumentException eee) {
- System.out.println("Error during the processing of a DOM4J");
- eee.printStackTrace();
- } catch (SAXException e) {
- System.out.println("Error during the parsing with digester");
- e.printStackTrace();
- }
- }
- }
-
- public void generate(UIModel ui, File destDir) throws IOException {
- {
- this.model = ui;
-
- String filename = getFilenameForUIModel(ui);
- File outputFile = getDestinationFile(destDir, filename);
- if (getOverwrite() || !isNewerThanSource(outputFile)) {
- StringWriter out = new StringWriter();
- MonitorWriter monitorOut = new MonitorWriter(out);
- generateFromUIModel(monitorOut, model);
- write(outputFile, monitorOut);
- } else {
- Logger.getLogger(getClass().getName() + ".generate").log(
- Level.FINE, "file " + outputFile + "is up-to-date");
- }
- }
-
- for (UIModelObject uimodelobject : ui.getObjects()) {
-
- String filename = getFilenameForUIModelObject(uimodelobject);
- File outputFile = getDestinationFile(destDir, filename);
- if (getOverwrite() || !isNewerThanSource(outputFile)) {
- StringWriter out = new StringWriter();
- MonitorWriter monitorOut = new MonitorWriter(out);
- generateFromUIModelObject(monitorOut, uimodelobject);
- write(outputFile, monitorOut);
- } else {
- Logger.getLogger(getClass().getName() + ".generate").log(
- Level.FINE, "file " + outputFile + "is up-to-date");
- }
- }
- }
-
- /**
- * Par defaut cette methode retourne le getName du model. Si l'on souhaite
- * utiliser la methode generateFromUIModel il vaut mieux surcharger cette
- * methode
- * @param model le modele a utiliser
- * @return le getName du model
- */
- public String getFilenameForUIModel(UIModel model) {
- return model.getRoot().getName().concat(".java");
- }
-
- public String getFilenameForUIModelObject(UIModelObject object) {
- return object.getName().concat(".java");
- }
-
- public void generateFromUIModel(Writer output, UIModel model)
- throws IOException {
- }
-
- public void generateFromUIModelObject(Writer output, UIModelObject object)
- throws IOException {
- }
-
- public String capitalizeName(UIModelObject o) {
- String name = o.getName();
- if (name == null) {
- throw new GeneratorException("L'objet " + o.getType()
- + " doit avoir un nom valide");
- }
- return GeneratorUtil.capitalize(name);
- }
-
- public String capitalizeName(UIModelProperty p) {
- String name = p.getName();
- if (name == null) {
- throw new GeneratorException("La propriete " + p
- + " doit avoir un nom valide");
- }
- return GeneratorUtil.capitalize(name);
- }
-}
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModel.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModel.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModel.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,76 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui;
-
-import java.util.Collection;
-
-/**
-* UIModel.java
-*
-* Created: Jun 2, 2004
-*
-* @author pineau
-* @version $Revision$
-*
-* Last update : $Date$
-* by : $Author$
-*
-* Abstraction for the root node of ui model trees.
-* This an entry point for browsing an ui model tree.
-* This object offers as well several facilities for
-* a direct access to some of the ui model elements.
-*/
-public interface UIModel {
-
- /**
- * Returns the version of this model.
- *
- * @return the version of this model.
- */
- public String getVersion();
-
- /**
- * Returns the package of this model.
- *
- * @return the package of this model.
- */
- public String getPackage();
-
- /**
- * Returns the object root defined in this ui model.
- * @see UIModelObject
- *
- * @return the object root defined in this ui model.
- */
- public UIModelObject getRoot();
-
- /**
- * Returns all objects defined in this ui model.
- * @see UIModelObject
- *
- * @return a Collection containing all UIModelObjects for this ui model.
- */
- public Collection<UIModelObject> getObjects();
-
- /**
- * Method used to add objects in this model
- * @see UIModelObject
- *
- */
- public void addObject(UIModelObject object);
-}
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelArguments.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelArguments.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelArguments.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,43 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui;
-
-import java.util.List;
-
-/**
- * UIModelArguments.
- *
- * Created: Jun 2, 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * Copyright Code Lutin
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public interface UIModelArguments { // UIModelArguments
-
- /**
- * Returns a arguments list.
- * @return a arguments list.
- */
- public List<Object> getArguments();
-
-} // UIModelArguments
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelChild.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelChild.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelChild.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,51 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui;
-
-/**
- * UIModelChild.
- *
- * Created: Jun 1, 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * Copyright Code Lutin
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public interface UIModelChild { // UIModelChild
-
- /**
- * Returns a UIModelObject for this child.
- * @see UIModelObject
- *
- * @return a UIModelObject for this child.
- */
- public UIModelObject getObject();
-
- /**
- * Returns a UIModelConstraint for this child.
- * @see UIModelObject
- *
- * @return a UIModelConstraint for this child.
- */
- public UIModelConstraint getConstraint();
-
-} // UIModelChild
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelConstraint.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelConstraint.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelConstraint.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,50 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui;
-
-/**
- * UIModelConstraint.
- *
- * Created: Jun 3, 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * Copyright Code Lutin
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public interface UIModelConstraint { // UIModelConstraint
-
- /**
- * Returns the value of this constraint.
- * the value returned can be an instance of UIModelObject
- * or String or null
- * @return the value of this constraint.
- */
- public Object getValue();
-
- /**
- * Returns the value of this constraint if the type is String
- * else return null
- * @return the value of this constraint.
- */
- public String getStringValue();
-
-} // UIModelConstraint
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelEvent.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelEvent.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelEvent.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,65 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui;
-
-/**
-* UIModelEvent.
-*
-* Created: Jun 1, 2004
-*
-* @author Benjamin Poussin <poussin(a)codelutin.com>
-* Copyright Code Lutin
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-public interface UIModelEvent { // UIModelEvent
-
- /**
- * Returns the addListenerMethod of this event
- * @return addListenerMethod
- */
- public String getAddMethod();
-
- /**
- * Returns the listenerInterface of this event
- * @return listenerInterface
- */
- public String getSource();
-
- /**
- * Returns the listenerMethodName of this event
- * @return listenerMethodName
- */
- public String getAction();
-
- /**
- * Returns the handler of this event
- * @return handler
- */
- public String getHandler();
-
- /**
- * Returns the eventPropertyName of this event
- * @return eventPropertyName
- */
- public String getArgument();
-
-} // UIModelEvent
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelObject.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelObject.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelObject.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,111 +0,0 @@
-/* *##% Eugene
- * 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>. ##%*/
-package org.nuiton.eugene.models.ui;
-
-import java.util.Collection;
-
-/**
-* UIModelObject.java
-*
-* Created: Jun 2, 2004
-*
-* @author pineau
-* @version $Revision$
-*
-* Last update : $Date$
-* by : $Author$
-*/
-public interface UIModelObject {
-
- /**
- * Returns the parent of this object.
- * Returns null if this object is root
- * @return the parent of this object.
- */
- public UIModelObject getParent();
-
- /**
- * Returns the type of this object.
- *
- * @return the type of this object.
- */
- public String getType();
-
- /**
- * Returns the value of the property "name" of this object
- *
- * @return the name of this object.
- */
- public String getName();
-
- /**
- * Returns the constraint of this object
- * @see UIModelConstraint
- *
- * @return the constraint of this object.
- */
- public UIModelConstraint getConstraint();
-
- /**
- * Returns all arguments defined on this object.
- * This collection can contain UIModelObject or a primitive type
- *
- * @return a Collection containing all arguments for this object.
- */
- public Collection<Object> getArguments();
-
- /**
- * Returns all properties defined on this object.
- * @see UIModelProperty
- *
- * @return a Collection containing all UIModelProperty for this object.
- */
- public Collection<UIModelProperty> getProperties();
-
- /**
- * Returns the property defined on this object.
- * @see UIModelProperty
- * @param name the name of the property which must be returned
- * @return a UIModelProperty for this object with the .
- */
- public UIModelProperty getProperty(String name);
-
- /**
- * Returns all events defined on this object.
- * @see UIModelEvent
- *
- * @return a Collection containing all UIModelEvents for this object.
- */
- public Collection<UIModelEvent> getEvents();
-
- /**
- * Returns all children defined on this object.
- * @see UIModelChild
- *
- * @return a Collection containing all UIModelChildren for this object.
- */
- public Collection<UIModelChild> getChildren();
-
- /**
- * Returns the uimodel of this object.
- * @see UIModel
- *
- * @return the uimodel of this object.
- */
- public UIModel getModel();
-
-}
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelProperty.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelProperty.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/UIModelProperty.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,110 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui;
-
-/**
- * UIModelProperty.java
- *
- * Created: Jun 2, 2004
- *
- * @author pineau
- * @version $Revision$
- *
- * Last update : $Date$
- * by : $Author$
- */
-public interface UIModelProperty {
-
- /**
- * Returns the name of this property.
- *
- * @return the name of this property.
- */
- public String getName();
-
- /**
- * Returns the value of this property.
- * the value returned can be an instance of UIModelObject
- * or String or Integer or Boolean or Character
- * @return the value of this property.
- */
- public Object getValue();
-
- /**
- * Returns the index of this property if it's indexed property
- *
- * @return the index of this property.
- */
- public int getIndex() throws Exception;
-
- public boolean isIndexed();
-
- /**
- * Returns the value of this property if the type is int
- * @return the value of this property.
- */
- public int getIntValue();
-
- /**
- * Returns the value of this property if the type is boolean
- * @return the value of this property.
- */
- public boolean getBooleanValue();
-
- /**
- * Returns the value of this property if the type is char
- * @return the value of this property.
- */
- public char getCharValue();
-
- /**
- * Returns the value of this property if the type is String
- * @return the value of this property.
- */
- public String getStringValue();
-
- /**
- * Returns the value of this property if the type is byte
- * @return the value of this property.
- */
- public byte getByteValue();
-
- /**
- * Returns the value of this property if the type is Short
- * @return the value of this property.
- */
- public short getShortValue();
-
- /**
- * Returns the value of this property if the type is long
- * @return the value of this property.
- */
- public long getLongValue();
-
- /**
- * Returns the value of this property if the type is float
- * @return the value of this property.
- */
- public float getFloatValue();
-
- /**
- * Returns the value of this property if the type is double
- * @return the value of this property.
- */
- public double getDoubleValue();
-}
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelArgumentsImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelArgumentsImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelArgumentsImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,80 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.impl;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.nuiton.eugene.models.ui.UIModelArguments;
-
-/**
-* UIModelArgumentsImpl.
-*
-* Created: Aug 9, 2004
-*
-* @author Benjamin Poussin <poussin(a)codelutin.com>
-* Copyright Code Lutin
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-public class UIModelArgumentsImpl implements UIModelArguments { // UIModelArgumentsImpl
-
- protected List<Object> arguments = new ArrayList<Object>();
-
- /**
- * Changes the arguments list.
- * @param arguments - a new arguments list.
- */
- public void setArguments(List<Object> arguments) {
- this.arguments = arguments;
- }
-
- /**
- * Returns a arguments list.
- * @return a arguments list.
- */
- public List<Object> getArguments() {
- return arguments;
- }
-
- /**
- * Add an argument to the arguments list
- * @param arg - object argument
- */
- public void addArgument(Object arg) {
- arguments.add(arg);
- }
-
- /**
- * @return a string representation of the object
- */
- public String toString() {
- String argString = "[";
- for (Iterator<Object> i = arguments.iterator(); i.hasNext();) {
- Object arg = i.next();
- argString = argString + " " + arg.toString();
- }
- argString = argString + "]";
- return argString;
- }
-
-} // UIModelArgumentsImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelChildImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelChildImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelChildImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,97 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.impl;
-
-import org.nuiton.eugene.models.ui.UIModelChild;
-import org.nuiton.eugene.models.ui.UIModelConstraint;
-import org.nuiton.eugene.models.ui.UIModelObject;
-
-/**
- * UIModelChildImpl.
- *
-* Created: Aug 9, 2004
-*
-* @author Benjamin Poussin <poussin(a)codelutin.com>
-* Copyright Code Lutin
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-public class UIModelChildImpl implements UIModelChild { // UIModelChildImpl
-
- protected UIModelObject object = null;
- protected UIModelConstraint constraint = null;
-
- /**
- * Changes the UIModelObject for this child.
- * @see UIModelObject
- *
- * @param object - a new UIModelObject
- */
- public void setObject(UIModelObject object) {
- this.object = object;
- }
-
- /**
- * Changes the UIModelConstraint for this child.
- * @see UIModelConstraint
- *
- * @param constraint - a new UIModelConstraint
- */
- public void setConstraint(UIModelConstraint constraint) {
- this.constraint = constraint;
- }
-
- /**
- * Returns a UIModelObject for this child.
- * @see UIModelObject
- *
- * @return a UIModelObject for this child.
- */
- public UIModelObject getObject() {
- return object;
- }
-
- /**
- * Returns a UIModelConstraint for this child.
- * @see UIModelConstraint
- *
- * @return a UIModelConstraint for this child.
- */
- public UIModelConstraint getConstraint() {
- return constraint;
- }
-
- /**
- * @return a string representation of the object
- */
- public String toString() {
- String childString = "[";
- childString = childString + " child : " + object.toString() + " \n";
- if (constraint != null)
- childString = childString + "constraint : " + constraint.toString()
- + " \n";
- childString = childString + "]";
- return childString;
- }
-
-} // UIModelChildImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelConstraintImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelConstraintImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelConstraintImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,84 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.impl;
-
-import org.nuiton.eugene.models.ui.UIModelConstraint;
-
-/**
-* UIModelConstraintImpl.
-*
-* Created: Aug 9, 2004
-*
-* @author Benjamin Poussin <poussin(a)codelutin.com>
-* Copyright Code Lutin
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-public class UIModelConstraintImpl implements UIModelConstraint { // UIModelConstraintImpl
-
- protected Object value = null;
-
- /**
- * Changes the value of this constraint.
- * the value can be an instance of UIModelObject
- * or String or null
- * @param value - the new value of this constraint.
- */
- public void setValue(Object value) {
- this.value = value;
- }
-
- /**
- * Returns the value of this constraint.
- * the value returned can be an instance of UIModelObject
- * or String or null
- * @return the value of this constraint.
- */
- public Object getValue() {
- return value;
- }
-
- /**
- * Returns the value of this constraint
- * if the type is String else returnnull
- *
- * @return the value of this constraint.
- */
- public String getStringValue() {
- if (value instanceof String)
- return (String) value;
- return null;
- }
-
- /**
- * @return a string representation of the object
- */
- public String toString() {
- String toString = null;
- if (value != null) {
- toString = value.toString();
- }
- return toString;
- }
-
-} // UIModelConstraintImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelEventImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelEventImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelEventImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,137 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.impl;
-
-import org.nuiton.eugene.models.ui.UIModelEvent;
-
-/**
-* UIModelEventImpl.
-*
-* Created: Aug 9, 2004
-*
-* @author Benjamin Poussin <poussin(a)codelutin.com>
-* Copyright Code Lutin
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-public class UIModelEventImpl implements UIModelEvent { // UIModelEventImpl
-
- protected String addMethod = null;
- protected String source = null;
- protected String action = null;
- protected String handler = null;
- protected String argument = null;
-
- /**
- * Changes the addListenerMethod of this event
- * @param addMethod - the new addListenerMethod
- */
- public void setAddMethod(String addMethod) {
- this.addMethod = addMethod;
- }
-
- /**
- * Changes the listenerInterface of this event
- * @param source - the new listenerInterface
- */
- public void setSource(String source) {
- this.source = source;
- }
-
- /**
- * Changes the listenerMethodName of this event
- * @param action - the new listenerMethodName
- */
- public void setAction(String action) {
- this.action = action;
- }
-
- /**
- * Changes the handler of this event
- * @param handler - the new handler
- */
- public void setHandler(String handler) {
- this.handler = handler;
- }
-
- /**
- * Changes the eventPropertyName of this event
- * @param argument - the new eventPropertyName
- */
- public void setArgument(String argument) {
- this.argument = argument;
- }
-
- /**
- * Returns the addListenerMethod of this event
- * @return addListenerMethod
- */
- public String getAddMethod() {
- return addMethod;
- }
-
- /**
- * Returns the listenerInterface of this event
- * @return listenerInterface
- */
- public String getSource() {
- return source;
- }
-
- /**
- * Returns the listenerMethodName of this event
- * @return listenerMethodName
- */
- public String getAction() {
- return action;
- }
-
- /**
- * Returns the handler of this event
- * @return handler
- */
- public String getHandler() {
- return handler;
- }
-
- /**
- * Returns the eventPropertyName of this event
- * @return eventPropertyName
- */
- public String getArgument() {
- return argument;
- }
-
- /**
- * @return a string representation of the object
- */
- public String toString() {
- String eventString = "[ addMethod : " + addMethod + ", ";
- eventString = eventString + "source " + source + ", ";
- eventString = eventString + "action " + action + ", ";
- eventString = eventString + "handler " + handler + ", ";
- eventString = eventString + "argument : " + argument + " ]";
- return eventString;
- }
-
-} // UIModelEventImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,137 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.impl;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.nuiton.eugene.models.ui.UIModel;
-import org.nuiton.eugene.models.ui.UIModelObject;
-
-/**
-* UIModelImpl.
-*
-* Created: Aug 6, 2004
-*
-* @author Benjamin Poussin <poussin(a)codelutin.com>
-* Copyright Code Lutin
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-public class UIModelImpl implements UIModel { // UIModelImpl
-
- protected String version = null;
- protected String packageName = null;
- protected UIModelObject root = null;
- /**
- * Contient tous les objets du model.
- * key: nom de l'objet; value: l'objet
- */
- protected Map<String, UIModelObject> objects = new HashMap<String, UIModelObject>();
-
- /**
- * Changes the version of this model
- * @param version - version of this model
- */
- public void setVersion(String version) {
- this.version = version;
- }
-
- /**
- * Changes the package of this model
- * @param packageName - package name
- */
- public void setPackageName(String packageName) {
- this.packageName = packageName;
- }
-
- /**
- * Changes the object root defined in this model.
- * @see UIModelObject
- * @param root - object root
- */
- public void setRoot(UIModelObject root) {
- this.root = root;
- }
-
- /**
- * Returns the version of this model.
- *
- * @return the version of this model.
- */
- public String getVersion() {
- return version;
- }
-
- /**
- * Returns the package of this model.
- *
- * @return the package of this model.
- */
- public String getPackage() {
- return packageName;
- }
-
- /**
- * Returns the object root defined in this ui model.
- * @see UIModelObject
- *
- * @return the object root defined in this ui model.
- */
- public UIModelObject getRoot() {
- return root;
- }
-
- /**
- * Returns all objects defined in this ui model.
- * @see UIModelObject
- *
- * @return a Collection containing all UIModelObjects for this ui model.
- */
- public Collection<UIModelObject> getObjects() {
- return objects.values();
- }
-
- /**
- * Method used to add objects in this model
- * @see UIModelObject
- *
- */
- public void addObject(UIModelObject object) {
- if (object.getName() != null) {
- objects.put(object.getName(), object);
- }
- }
-
- /**
- * @return a string representation of the object
- */
- public String toString() {
- String modelString = "version : " + version + ", ";
- modelString = modelString + "package : " + packageName + ", ";
- modelString = modelString + "root : " + root.toString();
- return modelString;
- }
-
-} // UIModelImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelObjectImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelObjectImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelObjectImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,310 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.impl;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.nuiton.eugene.models.ui.UIModel;
-import org.nuiton.eugene.models.ui.UIModelArguments;
-import org.nuiton.eugene.models.ui.UIModelChild;
-import org.nuiton.eugene.models.ui.UIModelConstraint;
-import org.nuiton.eugene.models.ui.UIModelEvent;
-import org.nuiton.eugene.models.ui.UIModelObject;
-import org.nuiton.eugene.models.ui.UIModelProperty;
-
-/**
-* UIModelObjectImpl.
-*
-* Created: Aug 9, 2004
-*
-* @author Benjamin Poussin <poussin(a)codelutin.com>
-* Copyright Code Lutin
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-public class UIModelObjectImpl implements UIModelObject { // UIModelObjectImpl
-
- // model et parent semblent inutiles dans cette implantation mais obligatoire pour l'heritage
- protected UIModel model = null;
- protected UIModelObject parent = null;
-
- protected String type = null;
- protected String name = null;
- protected UIModelConstraint constraint = null;
-
- protected UIModelArguments arguments = null;
- protected List<UIModelProperty> properties = new ArrayList<UIModelProperty>();
- protected List<UIModelEvent> events = new ArrayList<UIModelEvent>();
- protected List<UIModelChild> children = new ArrayList<UIModelChild>();
-
- /**
- * Changes the model of this object.
- * @see UIModel
- *
- * @param model - the new model of this object.
- */
- public void setModel(UIModel model) {
- this.model = model;
- }
-
- /**
- * Changes the type of this object.
- *
- * @param type - the new type of this object.
- */
- public void setType(String type) {
- this.type = type;
- }
-
- /**
- * Changes the parent of this object.
- * Returns null if this object is root
- * @param parent - the parent of this object.
- */
- public void setParent(UIModelObject parent) {
- this.parent = parent;
- }
-
- /**
- * Changes the constraint of this object
- * @see UIModelConstraint
- *
- * @param constraint - the new constraint of this object.
- */
- public void setConstraint(UIModelConstraint constraint) {
- this.constraint = constraint;
- }
-
- /**
- * Changes all arguments defined on this object.
- * This collection can contain UIModelObject or a primitive type
- *
- * @param arguments - a Collection containing all arguments for this object.
- */
- public void setArguments(UIModelArguments arguments) {
- this.arguments = arguments;
- }
-
- /**
- * Changes all properties defined on this object.
- * @see UIModelProperty
- *
- * @param properties - a Collection containing all UIModelProperty for this object.
- */
- public void setProperties(List<UIModelProperty> properties) {
- this.properties = properties;
- }
-
- /**
- * Changes all events defined on this object.
- * @see UIModelEvent
- *
- * @param events - a Collection containing all UIModelEvents for this object.
- */
- public void setEvents(List<UIModelEvent> events) {
- this.events = events;
- }
-
- /**
- * Changes all children defined on this object.
- * @see UIModelChild
- *
- * @param children - a Collection containing all UIModelChildren for this object.
- */
- public void setChildren(List<UIModelChild> children) {
- this.children = children;
- }
-
- /**
- * Returns the uimodel of this object.
- * @see UIModel
- * @deprecated
- * @return the uimodel of this object.
- */
- public UIModel getModel() {
- return model;
- }
-
- /**
- * Returns the type of this object.
- *
- * @return the type of this object.
- */
- public String getType() {
- return type;
- }
-
- /**
- * Returns the value of the property "name" of this object
- *
- * @return the name of this object.
- */
- public String getName() {
- if (name == null) {
- UIModelProperty propName = getProperty("name");
- if (propName != null) {
- name = propName.getStringValue();
- }
- }
- return name;
- }
-
- /**
- * Returns the parent of this object.
- * Returns null if this object is root
- * @deprecated
- * @return the parent of this object.
- */
- public UIModelObject getParent() {
- return parent;
- }
-
- /**
- * Returns the constraint of this object
- * @see UIModelConstraint
- *
- * @return the constraint of this object.
- */
- public UIModelConstraint getConstraint() {
- return constraint;
- }
-
- /**
- * Returns all arguments defined on this object.
- * This collection can contain UIModelObject or a primitive type
- *
- * @return a Collection containing all arguments for this object.
- */
- public Collection<Object> getArguments() {
- return arguments.getArguments();
- }
-
- /**
- * Returns all properties defined on this object.
- * @see UIModelProperty
- *
- * @return a Collection containing all UIModelProperty for this object.
- */
- public Collection<UIModelProperty> getProperties() {
- return properties;
- }
-
- /**
- * Returns all events defined on this object.
- * @see UIModelEvent
- *
- * @return a Collection containing all UIModelEvents for this object.
- */
- public Collection<UIModelEvent> getEvents() {
- return events;
- }
-
- /**
- * Returns all children defined on this object.
- * @see UIModelChild
- *
- * @return a Collection containing all UIModelChildren for this object.
- */
- public Collection<UIModelChild> getChildren() {
- return children;
- }
-
- /**
- * Returns the property defined on this object.
- * @see UIModelProperty
- * @param propName the name of the property which must be returned
- * @return a UIModelProperty for this object with the .
- */
- public UIModelProperty getProperty(String propName) {
- Iterator<UIModelProperty> i = properties.iterator();
- UIModelPropertyImpl prop = null;
- boolean find = false;
- while (i.hasNext() && find == false) {
- prop = (UIModelPropertyImpl) i.next();
- if (propName.equals(prop.getName())) {
- find = true;
- }
- }
-
- return prop;
- }
-
- /**
- * Add a UIModelProperty to the properties list
- * @see UIModelProperty
- * @param prop - a new UIModelProperty
- */
- public void addProperty(UIModelProperty prop) {
- properties.add(prop);
- }
-
- /**
- * Add a UIModelEvent to the events list
- * @see UIModelEvent
- * @param event - a new UIModelEvent
- */
- public void addEvent(UIModelEvent event) {
- events.add(event);
- }
-
- /**
- * Add a UIModelChild to the children list
- * @see UIModelChild
- * @param child - a new UIModelChild
- */
- public void addChild(UIModelChild child) {
- children.add(child);
- }
-
- /**
- * @return a string representation of the object
- */
- public String toString() {
- String objectString = "\n[ type : " + type + ", ";
- objectString = objectString + " name : " + getName() + ", ";
- objectString = objectString + " arguments : " + arguments.toString();
-
- objectString = objectString + " properties : ";
- for (Iterator<UIModelProperty> i = properties.iterator(); i.hasNext();) {
- Object prop = i.next();
- objectString = objectString + " " + prop.toString();
- }
-
- objectString = objectString + " events : ";
- for (Iterator<UIModelEvent> i = events.iterator(); i.hasNext();) {
- Object event = i.next();
- objectString = objectString + " " + event.toString();
- }
-
- objectString = objectString + " children : ";
- for (Iterator<UIModelChild> i = children.iterator(); i.hasNext();) {
- Object child = i.next();
- objectString = objectString + " " + child.toString();
- }
-
- objectString = objectString + "]\n";
- return objectString;
- }
-
-} // UIModelObjectImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelPropertyImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelPropertyImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/impl/UIModelPropertyImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,238 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.impl;
-
-import org.nuiton.eugene.GeneratorException;
-import org.nuiton.eugene.models.ui.UIModelProperty;
-
-/**
-* UIModelPropertyImpl.
-*
-* Created: Aug 9, 2004
-*
-* @author Benjamin Poussin <poussin(a)codelutin.com>
-* Copyright Code Lutin
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-public class UIModelPropertyImpl implements UIModelProperty { // UIModelPropertyImpl
-
- protected String name;
- protected UIModelArgumentsImpl arguments;
-
- /**
- * Returns the name of this property.
- *
- * @return the name of this property.
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns the UIModelArgumentsImpl of this property.
- * UIModelArgumentsImpl contains the arguments list
- * @return UIModelArgumentsImpl
- */
- public UIModelArgumentsImpl getArguments() {
- return arguments;
- }
-
- /**
- * Returns the value of this property.
- * the value returned can be an instance of UIModelObject
- * or String or Integer or Boolean or Character
- * @return the value of this property.
- */
- public Object getValue() {
- int i = arguments.getArguments().size() - 1;
- if (i >= 0) {
- return arguments.getArguments().get(i);
- }
- return null;
- }
-
- /**
- * Returns the index of this property if it's indexed property
- *
- * @return the index of this property.
- */
- public int getIndex() throws Exception {
- if (isIndexed()) {
- return ((Integer) arguments.getArguments().get(0)).intValue();
- }
- throw new Exception(
- "Impossible d'obtenir l'index d'une propriete non indexee");
- }
-
- /**
- * Returns true if the property is indexed
- * @return true if the property is indexed
- */
- public boolean isIndexed() {
- return arguments.getArguments().size() >= 2;
- }
-
- /**
- * Returns the value of this property if the type is int
- * @return the value of this property.
- */
- public int getIntValue() {
- Object object = getValue();
- if (object != null) {
- return ((Integer) object).intValue();
- }
- throw new GeneratorException("La propriete " + name
- + " n'a pas de valeur");
- }
-
- /**
- * Returns the value of this property if the type is boolean
- * @return the value of this property.
- */
- public boolean getBooleanValue() {
- Object object = getValue();
- if (object != null) {
- return ((Boolean) object).booleanValue();
- }
- throw new GeneratorException("La propriete " + name
- + " n'a pas de valeur");
- }
-
- /**
- * Returns the value of this property if the type is char
- * @return the value of this property.
- */
- public char getCharValue() {
- Object object = getValue();
- if (object != null) {
- return ((Character) object).charValue();
- }
- throw new GeneratorException("La propriete " + name
- + " n'a pas de valeur");
- }
-
- /**
- * Returns the value of this property if the type is String
- * @return the value of this property.
- */
- public String getStringValue() {
- Object object = getValue();
- if (object != null) {
- return getValue().toString();
- }
- throw new GeneratorException("La propriete " + name
- + " n'a pas de valeur");
- }
-
- /**
- * Returns the value of this property if the type is byte
- * @return the value of this property.
- */
- public byte getByteValue() {
- Object object = getValue();
- if (object != null) {
- return ((Byte) object).byteValue();
- }
- throw new GeneratorException("La propriete " + name
- + " n'a pas de valeur");
- }
-
- /**
- * Returns the value of this property if the type is long
- * @return the value of this property.
- */
- public long getLongValue() {
- Object object = getValue();
- if (object != null) {
- return ((Long) object).longValue();
- }
- throw new GeneratorException("La propriete " + name
- + " n'a pas de valeur");
- }
-
- /**
- * Returns the value of this property if the type is short
- * @return the value of this property.
- */
- public short getShortValue() {
- Object object = getValue();
- if (object != null) {
- return ((Short) object).shortValue();
- }
- throw new GeneratorException("La propriete " + name
- + " n'a pas de valeur");
- }
-
- /**
- * Returns the value of this property if the type is float
- * @return the value of this property.
- */
- public float getFloatValue() {
- Object object = getValue();
- if (object != null) {
- return ((Float) object).floatValue();
- }
- throw new GeneratorException("La propriete " + name
- + " n'a pas de valeur");
- }
-
- /**
- * Returns the value of this property if the type is double
- * @return the value of this property.
- */
- public double getDoubleValue() {
- Object object = getValue();
- if (object != null) {
- return ((Double) object).doubleValue();
- }
- throw new GeneratorException("La propriete " + name
- + " n'a pas de valeur");
- }
-
- /**
- * Changes the name of this property.
- *
- * @param name - the new name of this property.
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * Changes the UIModelArgumentsImpl of this property.
- * UIModelArgumentsImpl contains the arguments list
- * @param arguments - the new UIModelArgumentsImpl of this property.
- */
- public void setArguments(UIModelArgumentsImpl arguments) {
- this.arguments = arguments;
- }
-
- /**
- * @return a string representation of the object
- */
- public String toString() {
- return getValue().toString();
- }
-
-} // UIModelPropertyImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/javaxml/JavaXMLParser.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/javaxml/JavaXMLParser.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/javaxml/JavaXMLParser.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,448 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.javaxml;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.Element;
-import org.dom4j.io.SAXReader;
-import org.nuiton.eugene.models.ui.UIModelEvent;
-import org.nuiton.eugene.models.ui.UIModelObject;
-import org.nuiton.eugene.models.ui.UIModelProperty;
-import org.nuiton.eugene.models.ui.impl.UIModelArgumentsImpl;
-import org.nuiton.eugene.models.ui.impl.UIModelChildImpl;
-import org.nuiton.eugene.models.ui.impl.UIModelConstraintImpl;
-import org.nuiton.eugene.models.ui.impl.UIModelEventImpl;
-import org.nuiton.eugene.models.ui.impl.UIModelImpl;
-import org.nuiton.eugene.models.ui.impl.UIModelObjectImpl;
-import org.nuiton.eugene.models.ui.impl.UIModelPropertyImpl;
-
-/**
-* Parser of a xml file issue of XMLEncoder.
-*
-* Created: Aug 6, 2004
-*
-* @author Benjamin Poussin <poussin(a)codelutin.com>
-* Copyright Code Lutin
-* @version $Revision$
-*
-* Mise a jour: $Date$
-* par : $Author$
-*/
-public class JavaXMLParser { // JavaXMLParser
- protected Element rootElement;
- protected UIModelImpl uimodel;
-
- /**
- * Parses a xml file and return a uimodel
- * @param file - xml file issue of XMLEncoder
- * @return UIModelImpl
- */
- public UIModelImpl parse(File file) throws DocumentException,
- MalformedURLException {
- return parse(file.toURI().toURL());
- }
-
- /**
- * Parses a xml file and return a uimodel
- * @param url - url of xml file issue of XMLEncoder
- * @return UIModelImpl
- */
- public UIModelImpl parse(URL url) throws DocumentException,
- MalformedURLException {
- SAXReader reader = new SAXReader();
- Document document = reader.read(url);
-
- rootElement = document.getRootElement();
- UIModelImpl result = parseModel(rootElement);
- String urlName = url.getFile();
- // exemple
- // urlFileName = /home/mazelier/PROJECT/lutingenerator/src/test/org/codelutin/generator/models/ui/javaxml/org.codelutin.chorem.entities.ui.LoggedPanel.javaxml
- // on enleve la premiere partie de l'arborescence
- // org.codelutin.chorem.entities.ui.LoggedPanel.javaxml
- // on enleve l'extension .javaxml
- // org.codelutin.chorem.entities.ui.LoggedPanel
- // on enleve le nom du fichier pour obtenir le nom du package
- // org.codelutin.chorem.entities.ui
-
- int indexSlash = urlName.lastIndexOf("/");
- if (indexSlash != -1) {
- indexSlash++;
- String name = urlName.substring(indexSlash, urlName
- .lastIndexOf(".javaxml"));
-
- int indexPoint = name.lastIndexOf(".");
- if (indexPoint != -1) {
- name = name.substring(0, indexPoint);
- }
- result.setPackageName(name);
- }
- return result;
- }
-
- /**
- * Returns a UIModelImpl from a element
- * @param current - element root of model
- * @return UIModelImpl
- */
- protected UIModelImpl parseModel(Element current) {
- uimodel = new UIModelImpl();
-
- String version = current.attributeValue("version");
- uimodel.setVersion(version);
-
- // selectionne l'unique object racine de l'arbre
- Element rootElement = (Element) current
- .selectSingleNode("/java/object");
- UIModelObject root = parseObject(rootElement, null);
- uimodel.setRoot(root);
-
- return uimodel;
- }
-
- /**
- * Returns a UIModelObjectImpl equivalent to current element.
- * It has arguments, properties, events and children
- * @param current - element to parse
- * @return UIModelObjectImpl
- */
- protected UIModelObjectImpl parseObject(Element current,
- UIModelObject parent) {
-
- UIModelObjectImpl result = new UIModelObjectImpl();
-
- result.setModel(uimodel);
- result.setParent(parent);
-
- String type = current.attributeValue("class");
- result.setType(type);
-
- // parse la liste des attributs
- UIModelArgumentsImpl arguments = parseArguments(current, result);
- result.setArguments(arguments);
-
- // liste des enfants de l'objet (collection de UIModelChild)
- ArrayList children = null;
-
- // Cas ou l'objet est une instance de RootPaneContainer, les enfants se trouvent dans le contentPane
- Element contentPaneElem = (Element) current
- .selectSingleNode("void[@property=\"contentPane\"]");
-
- if (contentPaneElem != null) {
- children = parseChildren(contentPaneElem, result);
- } else {
- children = parseChildren(current, result);
- }
-
- result.setChildren(children);
-
- // liste des properties de l'objet courant, on est sur que le tag des properties est de la forme <void property="propertyName">, ce tag est un enfant de l'objet courant
- List propertiesElement = current.selectNodes("void[@property]");
- if (contentPaneElem != null) {
- Element layoutElement = (Element) contentPaneElem
- .selectSingleNode(" void[@property=\"layout\"]");
- propertiesElement.add(layoutElement);
- }
-
- for (Iterator i = propertiesElement.iterator(); i.hasNext();) {
- Element propElement = (Element) i.next();
- System.out.println(" propElement " + propElement);
- UIModelProperty prop = parseProperty(propElement, result);
- result.addProperty(prop);
- }
-
- /* liste des events de l'objet courant
- les evenements sont decrits par un tag <void method="addMethod">
- addMethod sera utilisee pour decrire l'event
- sous ce tag un objet de type EventHandler avec sa methode create
- dessous on trouve l'ensemble des proprietes de l'event (source, action ...)*/
- List eventsElement = current
- .selectNodes("void/object[@class=\"java.beans.EventHandler\" and @method=\"create\"]");
-
- for (Iterator i = eventsElement.iterator(); i.hasNext();) {
- Element eventProp = (Element) i.next();
- UIModelEvent event = parseEvent(eventProp);
- result.addEvent(event);
- }
-
- uimodel.addObject(result);
-
- return result;
- }
-
- /**
- * Returns UIModelArgumentsImpl equivalent to current element
- * A argument can be an object or a value with a primitiv type
- * @param current - element to parse
- * @return UIModelArgumentsImpl
- */
- protected UIModelArgumentsImpl parseArguments(Element current,
- UIModelObject parent) {
-
- UIModelArgumentsImpl result = new UIModelArgumentsImpl();
-
- //liste des arguments d'un propriete ou d'un objet. Ils ne sont pas des entites void mais int, double, ... (types primitfs), String
- List listPrimitivElement = current.selectNodes("*[not(self::void)]");
-
- for (Iterator i = listPrimitivElement.iterator(); i.hasNext();) {
- Element element = (Element) i.next();
- String type = element.getQualifiedName();
- // pour eviter le cas ou l'element est de type <null/>
- if (!type.equals("null")) {
- String valueString = element.getText();
- Object value = valueString;
- if (type.equals("int")) {
- value = new Integer(valueString);
- } else if (type.equals("float")) {
- value = new Float(valueString);
- } else if (type.equals("double")) {
- value = new Double(valueString);
- } else if (type.equals("long")) {
- value = new Long(valueString);
- } else if (type.equals("short")) {
- value = new Short(valueString);
- } else if (type.equals("boolean")) {
- value = new Boolean(valueString);
- } else if (type.equals("byte")) {
- value = new Byte(valueString);
- } else if (type.equals("object")) {
- value = parseObject(element, parent);
- }
- result.addArgument(value);
- }
-
- }
- return result;
- }
-
- /**
- * Returns UIModelPropertyImpl equivalent to current element
- * A property has a name and a list of Arguments
- * @param current - element to parse
- * @return UIModelPropertyImpl
- */
- protected UIModelPropertyImpl parseProperty(Element current,
- UIModelObject parent) {
-
- // la propriete possede un nom definit par la valeur de l'attribut property
- UIModelPropertyImpl result = new UIModelPropertyImpl();
- System.out.println(" current " + current);
- String name = current.attributeValue("property");
- result.setName(name);
-
- // la propriete possede aussi une liste d'arguments
- UIModelArgumentsImpl arguments = parseArguments(current, parent);
- result.setArguments(arguments);
-
- return result;
- }
-
- /**
- * Returns UIModelEventImpl equivalent to current element
- * A event has a addMethod, source, handler, argument and an action
- * @param current - element to parse
- * @return UIModelEventImpl
- */
- protected UIModelEventImpl parseEvent(Element current) {
- UIModelEventImpl result = new UIModelEventImpl();
-
- /* Modele d'un event
- <void method="addMethod">
- <objet class="EventHandler" method="create">
- <class>source</class>
- <string>target</string>
- <string>handler</handler>
- <string>arguments</string> (attention ou <null/>)
- <string>action</string>
- </objet>
- </void>
- */
- // parfois il n'y aura pas d'arguments et il est possible que handler soit vide !
- // recuperation de la valeur de addMethod dans le tag parent void de l'objet courant avec l'attribut method
- Element addMethodElement = (Element) current
- .selectSingleNode("parent::void[@method]");
- result.setAddMethod(addMethodElement.attributeValue("method"));
-
- // la source est definie pour le tag class place juste en dessous de l'objet courant
- Element sourceElement = (Element) current.selectSingleNode("class");
- if (sourceElement != null) {
- result.setSource(sourceElement.getText());
- }
-
- // le handler sera le troisieme element en tout
- Element handlerElement = (Element) current
- .selectSingleNode("*[position()=3]");
- if (handlerElement != null) {
- result.setHandler(handlerElement.getText());
- }
-
- // on ne connait pas le type d'arguments (null ou string) d'ou * mais on sait que sa position sera toujours 4 !
- Element argumentsElement = (Element) current
- .selectSingleNode("*[position()=4]");
- if (argumentsElement != null) {
- result.setArgument(argumentsElement.getText());
- }
-
- // l'action est toujours de type string mais on ne peut pas vraiment determine sa position a cause de arguments : position= 4 si arguments est de type string 3 sinon mais on sait que action sera toujours en dernier position
- Element actionElement = (Element) current
- .selectSingleNode("*[position()=last()]");
- if (actionElement != null) {
- result.setAction(actionElement.getText());
- }
-
- return result;
- }
-
- protected ArrayList parseChildren(Element current, UIModelObject parent) {
- ArrayList result = new ArrayList();
-
- //liste des enfants de l'objet
-
- // l'objet est identifie par un id
- //un enfant est un objet qui a ete ajoute par la methode add au container
- // sous l'objet courant, on cherche la methode add du tag void puis on recupere l'objet se trouvant sous ce tag. L'enfant est alors identifie par un id ou idref (si l'objet a deja ete defini)
- List childrenElement = current
- .selectNodes("void[@method=\"add\"]/object");
-
- if (!childrenElement.isEmpty()) {
-
- for (Iterator i = childrenElement.iterator(); i.hasNext();) {
-
- Element childElem = (Element) i.next();
- String id = childElem.attributeValue("idref");
- // selectionner l'enfant qui possede le meme id que l'idref
- // cet enfant se trouve dans les descendants du noeud root
- if (id != null) {
- childElem = (Element) rootElement
- .selectSingleNode("descendant::object[@id=\"" + id
- + "\"]");
- }
-
- id = childElem.attributeValue("id");
- UIModelObjectImpl child = parseObject(childElem, parent);
-
- // selectionner la constraint
- // sous la propriete layout de l'objet, il y a l'argument object layout
- // sous cet objet layout, se trouve la methode addLayoutComponent
- // avec object ajoute au container avec un idref qui doit etre identique a l'un des enfants vus precedemment (definis dans la methode add) (cet objet est toujours en premiere position
- // en deuxieme position se trouve la constrainte du premier object (string ou object)
- Element constraintElem = (Element) current
- .selectSingleNode("descendant::void[@property=\"layout\"]/object[(@class)]/void[@method=\"addLayoutComponent\"]/object[1][(@idref=\""
- + id
- + "\") or (@id=\""
- + id
- + "\")]/../*[2][(self::object) or (self::string)]");
-
- // ATTENTION : dans l'expression XPath on trouve deux conditions car dans le cas des panels generes l'argument de la proptriete layout n'apparait pas, nous n'avons pas du determine l'origine de l'erreur
- if (constraintElem == null) {
- constraintElem = (Element) current
- .selectSingleNode("descendant::void[@property=\"layout\"]/void[@method=\"addLayoutComponent\"]/object[1][(@idref=\""
- + id
- + "\") or (@id=\""
- + id
- + "\")]/../*[2][(self::object) or (self::string)]");
- }
-
- UIModelConstraintImpl constraint = null;
-
- if (constraintElem != null) {
- constraint = parseConstraint(constraintElem, parent);
- }
-
- // uimodelChild est compose un child et d'une contrainte
- UIModelChildImpl ch = new UIModelChildImpl();
- ch.setObject(child);
- ch.setConstraint(constraint);
-
- //child.setConstraint(constraint);
-
- result.add(ch);
-
- }
- } else {
-
- childrenElement = current
- .selectNodes("void[@property=\"layout\"]/void[@method=\"addLayoutComponent\"]");
-
- for (Iterator i = childrenElement.iterator(); i.hasNext();) {
-
- Element objElem = (Element) i.next();
- Element childElem = (Element) objElem
- .selectSingleNode("object[1]");
- UIModelObjectImpl child = parseObject(childElem, parent);
-
- Element constraintElem = (Element) current
- .selectSingleNode("*[2][(self::object) or (self::string)]");
-
- UIModelConstraintImpl constraint = null;
-
- if (constraintElem != null) {
- constraint = parseConstraint(constraintElem, parent);
- }
-
- // uimodelChild est compose un child et d'une contrainte
- UIModelChildImpl ch = new UIModelChildImpl();
- ch.setObject(child);
- ch.setConstraint(constraint);
-
- //child.setConstraint(constraint);
-
- result.add(ch);
-
- }
- }
-
- return result;
- }
-
- /**
- * Returns UIModelConstraintImpl ewuivalent to current element
- * This is ths constraint of an object. It has an object value.
- * @param current - element to parse
- * @return UIModelConstraintImpl
- */
- protected UIModelConstraintImpl parseConstraint(Element current,
- UIModelObject parent) {
- UIModelConstraintImpl result = new UIModelConstraintImpl();
- Object value = null;
-
- if (current.matches("self::object")) {
- // la valeur de la constrainte est un objet
- value = parseObject(current, parent);
-
- } else if (current.matches("self::string")) {
- // la valeur de la constrainte est une string
- value = current.getData();
-
- }
-
- result.setValue(value);
-
- return result;
-
- }
-
-} // JavaXMLParser
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/DigesterUIModelRuleSet.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/DigesterUIModelRuleSet.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/DigesterUIModelRuleSet.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,70 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.xml;
-
-import org.apache.commons.digester.Digester;
-import org.apache.commons.digester.RuleSetBase;
-
-/**
- * DigesterUIModelRules
- *
- * Definit principalement : - la classe d'implementation a utiliser pour chaque
- * noeud - la methode a appeler apres chaque noeud
- *
- * Ce jeu de regle ne cree pas l'element racine. Il doit etre cree et ajoute a
- * la pile digester avant l'appel a <tt>Digester.parse(File)</tt>.
- *
- * Exemple: <code>
- * UIModel monModel = new UIModelImpl()
- * Digester d = new Digester();
- * d.push(monModel);
- * d.parse(file);
- * </code>
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$ By : $Author$
- */
-public class DigesterUIModelRuleSet extends RuleSetBase {
-
- protected String prefix = null;
-
- public DigesterUIModelRuleSet() {
- this("");
- }
-
- public DigesterUIModelRuleSet(String prefix) {
- super();
- this.prefix = prefix;
- this.namespaceURI = "http://www.codelutin.org/lutingenerator/uiModel";
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.commons.digester.RuleSetBase#addRuleInstances(org.apache.commons.digester.Digester)
- */
- @Override
- public void addRuleInstances(Digester d) {
-
- // FIXME pas d'exemple pour pouvoir definir les regles
-
- }
-
-}
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelArgumentsImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelArgumentsImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelArgumentsImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,109 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.xml;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.nuiton.eugene.models.ui.UIModelArguments;
-import org.nuiton.eugene.models.ui.UIModelObject;
-
-/**
- * UIModelArgumentsImpl.
- *
- * Created: Jun 4, 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * Copyright Code Lutin
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class UIModelArgumentsImpl implements UIModelArguments { // UIModelArgumentsImpl
-
- // protected UIModel model = null;
- // protected UIModelObject parent = null;
- // Liste des arguments de differents types (object, int, bool, String, ...)
- protected List<Object> arguments = new ArrayList<Object>();
-
- public UIModelArgumentsImpl() {
- super();
- }
-
- public void addObject(UIModelObject value) {
- // if(value == null) {
- // return new UIModelObjectImpl(model, parent);
- // }
-
- arguments.add(value);
- // return value;
- }
-
- public void addInt(Integer value) {
- arguments.add(value);
- }
-
- public void addBoolean(Boolean value) {
- arguments.add(value);
- }
-
- public void addChar(Character value) {
- arguments.add(value);
- }
-
- public void addString(String value) {
- arguments.add(value);
- }
-
- public void addLong(Long value) {
- arguments.add(value);
- }
-
- public void addFloat(Float value) {
- arguments.add(value);
- }
-
- public void addByte(Byte value) {
- arguments.add(value);
- }
-
- public void addShort(Short value) {
- arguments.add(value);
- }
-
- public void addDouble(Double value) {
- arguments.add(value);
- }
-
- /**
- * Returns a arguments list.
- *
- * @see UIModelObject This list can contain UIModelObject or a primitive
- * type
- *
- * @return a arguments list.
- */
- public List<Object> getArguments() {
- return arguments;
- }
-
-} // UIModelArgumentsImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelChildImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelChildImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelChildImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,92 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.xml;
-
-import org.nuiton.eugene.models.ui.UIModelChild;
-import org.nuiton.eugene.models.ui.UIModelConstraint;
-import org.nuiton.eugene.models.ui.UIModelObject;
-
-/**
- * UIModelChildImpl.
- *
- * Created: Jun 4, 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * Copyright Code Lutin
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class UIModelChildImpl implements UIModelChild { // UIModelChildImpl
-
- // protected UIModel model = null;
- // protected UIModelObject parent = null;
-
- protected UIModelObject object = null;
-
- protected UIModelConstraintImpl constraint = null;
-
- public UIModelChildImpl() {
- super();
- }
-
- public void setObject(UIModelObject object) {
- // if(object == null) {
- // return new UIModelObjectImpl(model, parent);
- // }
-
- this.object = object;
- // return object;
- }
-
- public void setLayout(UIModelConstraintImpl constraint) {
- // if (constraint == null) {
- // return new UIModelConstraintImpl(model, parent);
- // }
-
- this.constraint = constraint;
- // return constraint;
- }
-
- /**
- * Returns a UIModelObject for this child.
- *
- * @see UIModelObject
- *
- * @return a UIModelObject for this child.
- */
- public UIModelObject getObject() {
- return object;
- }
-
- /**
- * Returns a UIModelConstraint for this child
- *
- * @see UIModelConstraint
- *
- * @return a UIModelConstraint for this child.
- */
- public UIModelConstraint getConstraint() {
- return constraint;
- }
-
-} // UIModelChildImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelConstraintImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelConstraintImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelConstraintImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,84 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.xml;
-
-import org.nuiton.eugene.models.ui.UIModelConstraint;
-
-/**
- * UIModelConstraintImpl.
- *
- * Created: Jun 4, 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com> Copyright Code Lutin
- *
- * @version $Revision$
- *
- * Mise a jour: $Date$ par : $Author$
- */
-public class UIModelConstraintImpl implements UIModelConstraint { // UIModelConstraintImpl
-
- // protected UIModel model = null;
- // protected UIModelObject parent = null;
-
- // valeur de la constraint de type UIModelObject ou String (cas du
- // borderLayout)
- protected Object value = null;
-
- public UIModelConstraintImpl() {
- // this.model = model;
- // this.parent = parent;
- }
-
- public void setObject(UIModelObjectImpl value) {
- // if (value == null) {
- // return new UIModelObjectImpl(model, parent);
- // }
-
- this.value = value;
- // return value;
- }
-
- public void setString(String value) {
- this.value = value;
- }
-
- /**
- * Returns the value of this constraint. the value returned can be an
- * instance of UIModelObject or String or null
- *
- * @return the value of this constraint.
- */
- public Object getValue() {
- return value;
- }
-
- /**
- * Returns the value of this constraint if the type is String else return
- * null
- *
- * @return the value of this constraint.
- */
- public String getStringValue() {
- if (value instanceof String) {
- return (String) value;
- }
- return null;
- }
-
-} // UIModelConstraintImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelEventImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelEventImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelEventImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,121 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.xml;
-
-import org.nuiton.eugene.models.ui.UIModelEvent;
-
-/**
- * UIModelEventImpl.
- *
- * Created: Jun 4, 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * Copyright Code Lutin
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class UIModelEventImpl implements UIModelEvent { // UIModelEventImpl
-
- //protected UIModel model = null;
-
- protected String addMethod = null;
-
- protected String source = null;
-
- protected String action = null;
-
- protected String handler = null;
-
- protected String argument = null;
-
- public UIModelEventImpl() {
- super();
- }
-
- public void setAddmethod(String addMethod) {
- this.addMethod = addMethod;
- }
-
- public void setSource(String source) {
- this.source = source;
- }
-
- public void setAction(String action) {
- this.action = action;
- }
-
- public void setHandler(String handler) {
- this.handler = handler;
- }
-
- public void setArgument(String argument) {
- this.argument = argument;
- }
-
- /**
- * Return the method which will have the EventHandler in parameter
- *
- * @return String
- */
- public String getAddMethod() {
- return addMethod;
- }
-
- /**
- * Return the listener interface to create a proxy for
- *
- * @return String
- */
- public String getSource() {
- return source;
- }
-
- /**
- * Return the name of the method in the listener interface that should
- * trigger the action
- *
- * @return String
- */
- public String getAction() {
- return action;
- }
-
- /**
- * Return the name of a writable method on the target
- *
- * @return String
- */
- public String getHandler() {
- return handler;
- }
-
- /**
- * Return the name of a readable property of the incoming event
- *
- * @return String
- */
- public String getArgument() {
- return argument;
- }
-
-} // UIModelEventImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,135 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.xml;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.nuiton.eugene.models.ui.UIModel;
-import org.nuiton.eugene.models.ui.UIModelObject;
-
-/**
- * UIModelImpl.
- *
- * Created: Jun 4, 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * Copyright Code Lutin
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class UIModelImpl implements UIModel { // UIModelImpl
-
- protected String version = null;
- protected String packageUIModel = null;
- protected UIModelObjectImpl root = null;
-
- /**
- * Contient tous les objets du model.
- * key: nom de l'objet; value: l'objet
- */
- protected Map<String, UIModelObject> objects = new HashMap<String, UIModelObject>();
-
- public UIModelImpl() {
- super();
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public void setPackage(String packageUIModel) {
- this.packageUIModel = packageUIModel;
- }
-
- /**
- * TODO pas setObject, mais addObject
- * TODO il y aurait ambiguite lors de l'appel par digester
- * @param object
- */
- public void setObject(UIModelObjectImpl object) {
- //if (object == null) {
- // return new UIModelObjectImpl(this, null);
- //}
-
- // set model and parent
- object.setParent(null);
- object.setModel(this);
-
- root = object;
- addObject(root);
- //return object;
- }
-
- /**
- * Method used to add objects in this model
- * @see UIModelObject
- */
- public void addObject(UIModelObject object) {
- if (object.getName() != null) {
- objects.put(object.getName(), object);
- }
- }
-
- /**
- * Returns the version of this model.
- *
- * @return the version of this model.
- */
- public String getVersion() {
- return version;
- }
-
- /**
- * Returns the package of this model.
- *
- * @return the package of this model.
- */
- public String getPackage() {
- return packageUIModel;
- }
-
- /**
- * Return the object root defined in this ui model.
- * @see UIModelObject
- *
- * @return the object root defined in this ui model.
- */
- public UIModelObject getRoot() {
- return root;
- }
-
- /**
- * Returns all objects defined in this ui model.
- * @see UIModelObject
- *
- * @return a Collection containing all UIModelObjects for this ui model.
- */
- public Collection<UIModelObject> getObjects() {
- return objects.values();
- }
-
- public UIModelObject getObject(String name) {
- return (UIModelObject) objects.get(name);
- }
-
-} // UIModelImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelObjectImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelObjectImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelObjectImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,263 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.xml;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.nuiton.eugene.models.ui.UIModel;
-import org.nuiton.eugene.models.ui.UIModelChild;
-import org.nuiton.eugene.models.ui.UIModelConstraint;
-import org.nuiton.eugene.models.ui.UIModelEvent;
-import org.nuiton.eugene.models.ui.UIModelObject;
-import org.nuiton.eugene.models.ui.UIModelProperty;
-
-/**
- * UIModelObjectImpl.
- *
- * Created: Jun 4, 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>Copyright Code Lutin
- *
- * @version $Revision$
- *
- * Mise a jour: $Date$ par : $Author$
- */
-public class UIModelObjectImpl implements UIModelObject { // UIModelObjectImpl
-
- protected UIModel model = null;
-
- protected UIModelObject parent = null;
-
- protected UIModelConstraint constraint = null;
-
- protected String type = null;
-
- protected String name = null;
-
- protected UIModelArgumentsImpl arguments = null;
-
- protected List<UIModelProperty> properties = new ArrayList<UIModelProperty>();
-
- protected List<UIModelEvent> events = new ArrayList<UIModelEvent>();
-
- /** Collection de UIModelObject */
- protected List<UIModelChild> children = new ArrayList<UIModelChild>();
-
- public UIModelObjectImpl() {
- super();
- }
-
- public void setClass(String type) {
- this.type = type;
- }
-
- public void setArguments(UIModelArgumentsImpl argument) {
- // if (argument == null) {
- // return new UIModelArgumentsImpl(model, this);
- // }
-
- this.arguments = argument;
- // return argument;
- }
-
- public void addProperty(UIModelPropertyImpl property) {
- // if (property == null) {
- // return new UIModelPropertyImpl(model, this);
- // }
-
- if (property.getValue() instanceof UIModelObjectImpl) {
- getModel().addObject((UIModelObject) property.getValue());
- }
-
- if (property.getName().equals("name")) {
- name = property.getStringValue();
- }
- properties.add(property);
- // return property;
- }
-
- public void addEvent(UIModelEventImpl event) {
- // if (event == null) {
- // return new UIModelEventImpl(model);
- // }
-
- events.add(event);
- // return event;
- }
-
- public void addChild(UIModelChildImpl child) {
- // if (child == null) {
- // return new UIModelChildImpl(model, this);
- // }
-
- UIModelObjectImpl childObject = (UIModelObjectImpl) child.getObject();
- UIModelConstraintImpl childConstraint = (UIModelConstraintImpl) child
- .getConstraint();
- childObject.setConstraint(childConstraint);
-
- getModel().addObject(childObject);
-
- children.add(child);
- // return child;
- }
-
- public void setConstraint(UIModelConstraintImpl constraint) {
- this.constraint = constraint;
- }
-
- /**
- * Returns the parent of this object. Returns null if this object is root
- *
- * @return the parent of this object.
- */
- public UIModelObject getParent() {
- return parent;
- }
-
- /**
- * Set the parent of this object.
- */
- public void setParent(UIModelObject parent) {
- this.parent = parent;
- }
-
- /**
- * Returns the type of this object.
- *
- * @return the type of this object.
- */
- public String getType() {
- return type;
- }
-
- /**
- * Returns the value of the property "name" of this object
- *
- * @return the name of this object.
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns the constraint of this object
- *
- * @see UIModelConstraint
- *
- * @return the constraint of this object.
- */
- public UIModelConstraint getConstraint() {
- return constraint;
- }
-
- /**
- * Returns all arguments defined on this object. if this objects hasn't
- * arguments return null This collection can contain UIModelObject or a
- * primitive type
- *
- * @return a Collection containing all arguments for this object.
- */
- public Collection<Object> getArguments() {
- if (arguments != null) {
- return arguments.getArguments();
- }
- return new ArrayList<Object>();
- }
-
- /**
- * Returns all properties defined on this object.
- *
- * @see UIModelProperty
- *
- * @return a Collection containing all UIModelProperties for this object.
- */
- public Collection<UIModelProperty> getProperties() {
- return properties;
- }
-
- /**
- * Returns the property defined on this object.
- *
- * @see UIModelProperty
- * @param name the name of the property which must be returned
- * @return a UIModelProperty for this object with the .
- */
- public UIModelProperty getProperty(String name) {
-
- UIModelProperty property = null;
- int position = 0;
-
- while (position < properties.size()) {
-
- property = (UIModelProperty) properties.get(position);
-
- if (property.getName().equals(name)) {
- break;
- }
- position++;
- }
-
- if (position >= properties.size()) {
- throw new IllegalStateException("Propriete " + name
- + " inexistante pour l'objet " + this.name);
- }
- return property;
- }
-
- /**
- * Returns all events defined on this object.
- *
- * @see UIModelEvent
- *
- * @return a Collection containing all UIModelEvents for this object.
- */
- public Collection<UIModelEvent> getEvents() {
- return events;
- }
-
- /**
- * Returns all children defined on this object.
- *
- * @return a Collection containing all UIModelObject for this object.
- */
- public Collection<UIModelChild> getChildren() {
- return children;
- }
-
- /**
- * Returns the uimodel of this object.
- *
- * @see UIModel
- *
- * @return the uimodel of this object.
- */
- public UIModel getModel() {
- return model;
- }
-
- /**
- * Set model
- */
- public void setModel(UIModel model) {
- this.model = model;
- }
-
-} // UIModelObjectImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelPropertyImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelPropertyImpl.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/ui/xml/UIModelPropertyImpl.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,181 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.xml;
-
-import org.nuiton.eugene.models.ui.UIModelProperty;
-
-/**
- * UIModelPropertyImpl.
- *
- * Created: Jun 4, 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * Copyright Code Lutin
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class UIModelPropertyImpl implements UIModelProperty { // UIModelPropertyImpl
-
- // protected UIModel model = null;
- // protected UIModelObject parent = null;
-
- protected String name = null;
-
- protected UIModelArgumentsImpl arguments = null;
-
- public UIModelPropertyImpl() {
- super();
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public void setArguments(UIModelArgumentsImpl argument) {
- // if (argument == null) {
- // return new UIModelArgumentsImpl(model, parent);
- // }
-
- this.arguments = argument;
- // return argument;
- }
-
- /**
- * Returns the name of this property.
- *
- * @return the name of this property.
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns the value of this property. the value returned can be an instance
- * of UIModelObject or String or Integer or Boolean or Character
- *
- * @return the value of this property.
- */
- public Object getValue() {
- int i = (arguments.getArguments().size()) - 1;
- return arguments.getArguments().get(i);
- }
-
- /**
- * Returns the index of this property if it's indexed property
- *
- * @return the index of this property.
- */
- public int getIndex() throws Exception {
- if (isIndexed()) {
- return ((Integer) arguments.getArguments().get(0)).intValue();
- }
- throw new Exception(
- "Impossible d'obtenir l'index d'une propriete non indexee");
- }
-
- public boolean isIndexed() {
- return arguments.getArguments().size() >= 2;
- }
-
- /**
- * Returns the value of this property if the type is int
- *
- * @return the value of this property.
- */
- public int getIntValue() {
- return ((Integer) getValue()).intValue();
- }
-
- /**
- * Returns the value of this property if the type is boolean
- *
- * @return the value of this property.
- */
- public boolean getBooleanValue() {
- return ((Boolean) getValue()).booleanValue();
- }
-
- /**
- * Returns the value of this property if the type is char
- *
- * @return the value of this property.
- */
- public char getCharValue() {
- return ((Character) getValue()).charValue();
- }
-
- /**
- * Returns the value of this property if the type is String
- *
- * @return the value of this property.
- */
- public String getStringValue() {
- return getValue().toString();
- }
-
- /**
- * Returns the value of this property if the type is byte
- *
- * @return the value of this property.
- */
- public byte getByteValue() {
- return ((Byte) getValue()).byteValue();
- }
-
- /**
- * Returns the value of this property if the type is long
- *
- * @return the value of this property.
- */
- public long getLongValue() {
- return ((Long) getValue()).longValue();
- }
-
- /**
- * Returns the value of this property if the type is short
- *
- * @return the value of this property.
- */
- public short getShortValue() {
- return ((Short) getValue()).shortValue();
- }
-
- /**
- * Returns the value of this property if the type is float
- *
- * @return the value of this property.
- */
- public float getFloatValue() {
- return ((Float) getValue()).floatValue();
- }
-
- /**
- * Returns the value of this property if the type is double
- *
- * @return the value of this property.
- */
- public double getDoubleValue() {
- return ((Double) getValue()).doubleValue();
- }
-
-} // UIModelPropertyImpl
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/test/java/org/nuiton/eugene/models/ui/javaxml/JavaXMLParserTest.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/test/java/org/nuiton/eugene/models/ui/javaxml/JavaXMLParserTest.java 2009-10-26 18:18:35 UTC (rev 659)
+++ branches/1.1.0-Javabuilder/eugene/src/test/java/org/nuiton/eugene/models/ui/javaxml/JavaXMLParserTest.java 2009-10-26 18:35:44 UTC (rev 660)
@@ -1,126 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene.models.ui.javaxml;
-
-import java.io.File;
-import java.util.List;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.nuiton.eugene.models.ui.UIModel;
-import org.nuiton.eugene.models.ui.impl.UIModelChildImpl;
-import org.nuiton.eugene.models.ui.impl.UIModelEventImpl;
-import org.nuiton.eugene.models.ui.impl.UIModelObjectImpl;
-import org.nuiton.util.Resource;
-
-/**
- * JavaXMLParserTest.
- *
- * Created: Aug 9, 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * Copyright Code Lutin
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class JavaXMLParserTest { // JavaXMLParserTest
-
- @Test
- public void testParse() throws Exception {
-
- // 1 panel, 2 boutons, gridbaglayout
- File testFile = new File(Resource.getURL("models/uimodel/test.javaxml").toURI());
-
- // 1 panel, 1 bouton, borderlayout
- File testFile1 = new File(Resource.getURL("models/uimodel/test1.javaxml").toURI());
-
- // alarmPanel de Chorem dans une JFrame
- File testFile2 = new File(Resource.getURL("models/uimodel/test2.javaxml").toURI());
-
- if (testFile.exists() && testFile1.exists() && testFile2.exists()) {
-
- JavaXMLParser parser = new JavaXMLParser();
- UIModel ui = parser.parse(testFile);
- UIModel ui1 = parser.parse(testFile1);
- UIModel ui2 = parser.parse(testFile2);
- //UIModel ui3 = parser.parse(testFile3);
-
- //System.out.println("UI : \n" + ui);
- //System.out.println("UI1 : \n" + ui1);
- //System.out.println("UI2 : \n" + ui2);
- //System.out.println("UI3 : \n" + ui3);
-
- // test si l'element racine est parse
- Assert.assertNotNull(ui.getRoot());
- Assert.assertNotNull(ui.getRoot().getName());
-
- // tests sur tous les elements du root
- Assert.assertTrue(ui.getRoot().getArguments().size() == 0);
- Assert.assertTrue(ui.getRoot().getChildren().size() == 2);
- Assert.assertTrue(ui.getRoot().getEvents().size() == 1);
- Assert.assertTrue(ui.getRoot().getProperties().size() == 2);
-
- // test si le layout est bien recupere
- UIModelObjectImpl object = (UIModelObjectImpl) ui.getRoot().getProperty("layout").getValue();
-
- Assert.assertEquals(object.getType(), "java.awt.GridBagLayout");
-
- // test sur un event de l'enfant
- List<?> children = (List<?>) ui.getRoot().getChildren();
- UIModelChildImpl child = (UIModelChildImpl) children.get(0);
-
- List<?> events = (List<?>) child.getObject().getEvents();
- UIModelEventImpl event = (UIModelEventImpl) events.get(0);
-
- Assert.assertEquals(event.getAction(), "actionPerformed");
- Assert.assertNotNull(event.getAddMethod());
-
- // test sur constraint de l'enfant
- UIModelObjectImpl constraint = (UIModelObjectImpl) child.getConstraint().getValue();
- List<?> argConstraint = (List<?>) constraint.getArguments();
-
- Assert.assertEquals(constraint.getType(), "java.awt.GridBagConstraints");
-
- Assert.assertEquals(argConstraint.get(1).toString(), "0");
-
- // test sur le nombre d'enfant d'un enfant
- Assert.assertTrue(child.getObject().getChildren().size() == 0);
-
- // test sur une contrainte string (BorderLayout)
- List<?> children1 = (List<?>) ui1.getRoot().getChildren();
- UIModelChildImpl child1 = (UIModelChildImpl) children1.get(0);
-
- Object constraint1 = child1.getConstraint().getValue();
- Assert.assertEquals(constraint1, "Center");
-
- // test sur le nombre d'enfants d'une Frame est correct
- List<?> children2 = (List<?>) ui2.getRoot().getChildren();
- Assert.assertTrue(children2.size() == 1);
-
- // test sur une contrainte d'un panel genere
- UIModelChildImpl child2 = (UIModelChildImpl) children2.get(0);
-
- Object constraint2 = child2.getConstraint().getValue();
- Assert.assertEquals(constraint2, "Center");
- }
- }
-
-} // JavaXMLParserTest
-
1
0
r658 - branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene
by fdesbois@users.nuiton.org 26 Oct '09
by fdesbois@users.nuiton.org 26 Oct '09
26 Oct '09
Author: fdesbois
Date: 2009-10-26 19:10:59 +0100 (Mon, 26 Oct 2009)
New Revision: 658
Removed:
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/AbstractObjectModelGenerator.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ChildGenerator.java
Modified:
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/UIModelGenerator.java
Log:
- Fusion Generator and ChildGenerator
- Refactor inheritance
- Suppress unused (even in ToPIA) AbstractObjectModelGenerator
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/AbstractObjectModelGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/AbstractObjectModelGenerator.java 2009-10-26 17:57:23 UTC (rev 657)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/AbstractObjectModelGenerator.java 2009-10-26 18:10:59 UTC (rev 658)
@@ -1,54 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene;
-
-import org.nuiton.eugene.models.object.ObjectModelElement;
-
-/**
- * AbstractObjectModelGenerator.
- *
- * Created: Jun 25, 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * Copyright Code Lutin
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class AbstractObjectModelGenerator extends ObjectModelGenerator { // AbstractObjectModelGenerator
-
- public AbstractObjectModelGenerator() {
- super();
- }
-
- public AbstractObjectModelGenerator(Generator parent) {
- super(parent);
- }
-
- public String capitalizeName(ObjectModelElement e) {
- String name = e.getName();
- if (name == null) {
- throw new GeneratorException("Element " + e
- + " must have an valid name");
- }
- return GeneratorUtil.capitalize(name);
- }
-
-} // AbstractObjectModelGenerator
-
Deleted: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ChildGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ChildGenerator.java 2009-10-26 17:57:23 UTC (rev 657)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ChildGenerator.java 2009-10-26 18:10:59 UTC (rev 658)
@@ -1,94 +0,0 @@
-/* *##% Eugene
- * 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.nuiton.eugene;
-
-/**
- * ChildGenerator.
- *
- * Created: 5 août 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public abstract class ChildGenerator extends Generator { // ChildGenerator
-
- protected Generator parent = null;
-
- public ChildGenerator() {
- super();
- }
-
- public ChildGenerator(Generator parent) {
- setParent(parent);
- }
-
- @Override
- public String getProperty(String name) {
- String propName = null;
- if (parent == null) {
- propName = super.getProperty(name);
- } else {
- propName = parent.getProperty(name);
- }
- return propName;
- }
-
- @Override
- public boolean getOverwrite() {
- boolean result;
- if (parent == null) {
- result = super.getOverwrite();
- } else {
- result = parent.getOverwrite();
- }
- return result;
- }
-
- @Override
- protected long getLastModifiedSource() {
- long lastModified = 0;
- if (parent == null) {
- lastModified = super.getLastModifiedSource();
- } else {
- lastModified = parent.getLastModifiedSource();
- }
- return lastModified;
- }
-
- @Override
- protected boolean canGeneratePackage(String packageName) {
- boolean canGenerate = true;
-
- if (parent == null) {
- canGenerate = super.canGeneratePackage(packageName);
- } else {
- canGenerate = parent.canGeneratePackage(packageName);
- }
-
- return canGenerate;
- }
-
- public void setParent(Generator parent) {
- this.parent = parent;
- setEncoding(parent.getEncoding());
- }
-
-} // ChildGenerator
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java 2009-10-26 17:57:23 UTC (rev 657)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/Generator.java 2009-10-26 18:10:59 UTC (rev 658)
@@ -60,9 +60,21 @@
protected String encoding;
+
+ protected Generator parent = null;
+
public Generator() {
}
+ public Generator(Generator parent) {
+ setParent(parent);
+ }
+
+ public void setParent(Generator parent) {
+ this.parent = parent;
+ setEncoding(parent.getEncoding());
+ }
+
public void generate(File file, File destDir) {
generate(new File[] { file }, destDir);
}
@@ -80,6 +92,9 @@
}
public boolean getOverwrite() {
+ if (parent != null) {
+ return getOverwrite();
+ }
return overwrite;
}
@@ -109,6 +124,9 @@
* @return la valeur de la propriété
*/
public String getProperty(String name) {
+ if (parent != null) {
+ return parent.getProperty(name);
+ }
return properties.getProperty(name);
}
@@ -124,7 +142,9 @@
}
protected long getLastModifiedSource() {
-
+ if (parent != null) {
+ return parent.getLastModifiedSource();
+ }
return lastModifiedSource;
}
@@ -199,7 +219,9 @@
*/
protected boolean canGeneratePackage(String packageName) {
boolean canGenerate = true;
-
+ if (parent != null) {
+ return parent.canGeneratePackage(packageName);
+ }
// if not generation restriction, generate everything
if (generatedPackages != null && !generatedPackages.isEmpty()) {
canGenerate = false;
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java 2009-10-26 17:57:23 UTC (rev 657)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java 2009-10-26 18:10:59 UTC (rev 658)
@@ -84,7 +84,7 @@
*
* Mise a jour: $Date$ par : $Author$
*/
-public class ObjectModelGenerator extends ChildGenerator {
+public class ObjectModelGenerator extends Generator {
/** Logger for this class. */
private static Log log = LogFactory.getLog(ObjectModelGenerator.class);
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java 2009-10-26 17:57:23 UTC (rev 657)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java 2009-10-26 18:10:59 UTC (rev 658)
@@ -55,7 +55,7 @@
*
* Last update : $Date$ By : $Author$
*/
-public class StateModelGenerator extends ChildGenerator {
+public class StateModelGenerator extends Generator {
/** Logger for this class */
private static Log log = LogFactory.getLog(StateModelGenerator.class);
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/UIModelGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/UIModelGenerator.java 2009-10-26 17:57:23 UTC (rev 657)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/UIModelGenerator.java 2009-10-26 18:10:59 UTC (rev 658)
@@ -45,7 +45,7 @@
* Last update : $Date$
* By : $Author$
*/
-public class UIModelGenerator extends ChildGenerator {
+public class UIModelGenerator extends Generator {
protected UIModel model = null;
1
0
r657 - branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator
by fdesbois@users.nuiton.org 26 Oct '09
by fdesbois@users.nuiton.org 26 Oct '09
26 Oct '09
Author: fdesbois
Date: 2009-10-26 18:57:23 +0100 (Mon, 26 Oct 2009)
New Revision: 657
Modified:
branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java
Log:
- Add fqn for attributes type
Modified: branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java 2009-10-22 15:54:03 UTC (rev 656)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java 2009-10-26 17:57:23 UTC (rev 657)
@@ -28,8 +28,8 @@
getHelper().addAttribute(roleClass, "name", "String");
this.addImportForClassifier(roleClass, Date.class);
- getHelper().addAttribute(roleClass, "fromDate", "Date");
- getHelper().addAttribute(roleClass, "thruDate", "Date");
+ getHelper().addAttribute(roleClass, "fromDate", "java.util.Date");
+ getHelper().addAttribute(roleClass, "thruDate", "java.util.Date");
}
private void createPerson() {
@@ -40,7 +40,7 @@
getHelper().addAttribute(personneClass, "firstName", "String");
this.addImportForClassifier(personneClass, List.class);
- getHelper().addAttribute(personneClass, "roles", "List<Role>");
+ getHelper().addAttribute(personneClass, "roles", "java.util.List<Role>");
ObjectModelOperation setLastName = getHelper().addOperation(personneClass, "setLastName", null, "String", "lastName");
1
0
r656 - in branches/1.1.0-Javabuilder: eugene/src/main/java/org/nuiton/eugene eugene/src/main/java/org/nuiton/eugene/models/object eugene/src/main/java/org/nuiton/eugene/models/object/xml eugene-test eugene-test/src/main/java/org/nuiton/eugene/test/generator eugene-test/src/main/resources
by fdesbois@users.nuiton.org 22 Oct '09
by fdesbois@users.nuiton.org 22 Oct '09
22 Oct '09
Author: fdesbois
Date: 2009-10-22 17:54:03 +0200 (Thu, 22 Oct 2009)
New Revision: 656
Added:
branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/JavaGenerator.java
Modified:
branches/1.1.0-Javabuilder/eugene-test/pom.xml
branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/DTOBuilder.java
branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java
branches/1.1.0-Javabuilder/eugene-test/src/main/resources/log4j.properties
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/JavaBuilder.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModel.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassifierImpl.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java
Log:
- Simplify imports managment : put map of importsManager directly into ObjectModel
- No longer use of JavaFile
- Add template JavaGenerator
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/JavaBuilder.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/JavaBuilder.java 2009-10-22 12:39:16 UTC (rev 655)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/JavaBuilder.java 2009-10-22 15:54:03 UTC (rev 656)
@@ -1,20 +1,39 @@
package org.nuiton.eugene;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import org.apache.commons.digester.Digester;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
import org.nuiton.eugene.models.object.ObjectModelBuilderHelper;
import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelClassifier;
import org.nuiton.eugene.models.object.ObjectModelElement;
import org.nuiton.eugene.models.object.ObjectModelEnumeration;
import org.nuiton.eugene.models.object.ObjectModelInterface;
-import org.nuiton.eugene.models.object.builder.JavaClassFile;
-import org.nuiton.eugene.models.object.builder.JavaFile;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.eugene.models.object.ObjectModelParameter;
+import org.nuiton.eugene.models.object.xml.DigesterObjectModelRuleSet;
import org.nuiton.eugene.models.object.xml.ObjectModelClassImpl;
+import org.nuiton.eugene.models.object.xml.ObjectModelClassifierImpl;
+import org.nuiton.eugene.models.object.xml.ObjectModelElementImpl;
import org.nuiton.eugene.models.object.xml.ObjectModelImpl;
+import org.nuiton.eugene.models.object.xml.ObjectModelImplRef;
+import org.nuiton.eugene.models.object.xml.ObjectModelImplTagValue;
+import org.nuiton.util.FileUtil;
+import org.nuiton.util.RecursiveProperties;
+import org.nuiton.util.StringUtil;
+import org.xml.sax.SAXException;
/**
*
@@ -22,21 +41,16 @@
*/
public abstract class JavaBuilder {
+ private static final Log log = LogFactory.getLog(JavaBuilder.class);
+
protected ObjectModelImpl objectModel;
- protected Map<String, JavaFile> javaFiles;
-
private static ObjectModelBuilderHelper helper = new ObjectModelBuilderHelper();
public JavaBuilder() {
this.objectModel = new ObjectModelImpl();
- this.javaFiles = new HashMap<String, JavaFile>();
}
- public JavaFile getFile(String qualifiedName) {
- return javaFiles.get(qualifiedName);
- }
-
public ObjectModel getModel() {
return objectModel;
}
@@ -45,24 +59,46 @@
return helper;
}
- protected void initFiles() {
- javaFiles.clear();
- for (ObjectModelClass clazz : objectModel.getClasses()) {
- JavaClassFile javaFile = new JavaClassFile(clazz);
- javaFiles.put(clazz.getQualifiedName(), javaFile);
+ public void addImportForClassifier(ObjectModelClassifier classifier, String imports) {
+ ImportsManager manager = objectModel.getImportsManager(classifier.getQualifiedName());
+ manager.addImport(imports);
+ }
+
+ public void addImportForClassifier(ObjectModelClassifier classifier, Class<?> imports) {
+ ImportsManager manager = objectModel.getImportsManager(classifier.getQualifiedName());
+ manager.addImport(imports);
+ }
+
+ public void addClassToModel(ObjectModelClass clazz) {
+ objectModel.addClass((ObjectModelClassImpl)clazz);
+ ImportsManager manager = setImports(clazz);
+
+ // extension for superclass
+ Iterator<ObjectModelClass> it = clazz.getSuperclasses().iterator();
+ if (it.hasNext()) {
+ ObjectModelClass superclass = it.next();
+ manager.addImport(superclass.getQualifiedName());
}
- // init Imports ?
}
- protected JavaClassFile createJavaClassFile(ObjectModelClass clazz) {
- if (javaFiles.containsKey(clazz.getQualifiedName())) {
- throw new IllegalArgumentException("ClassFile '" + clazz.getQualifiedName() + "' already exist");
+ private ImportsManager setImports(ObjectModelClassifier classifier) {
+ ImportsManager manager = objectModel.getImportsManager(classifier.getQualifiedName());
+ // attributes
+ for (ObjectModelAttribute attribute : classifier.getAttributes()) {
+ manager.addImport(attribute.getType());
}
- JavaClassFile javaFile = new JavaClassFile(clazz);
- objectModel.addClass((ObjectModelClassImpl)clazz);
- javaFiles.put(clazz.getQualifiedName(), javaFile);
- // init Imports ?
- return javaFile;
+ // implemented interfaces
+ for (ObjectModelInterface interfacez : classifier.getInterfaces()) {
+ manager.addImport(interfacez.getQualifiedName());
+ }
+ // operations
+ for (ObjectModelOperation operation : classifier.getOperations()) {
+ manager.addImport(operation.getReturnType());
+ for (ObjectModelParameter parameter : operation.getParameters()) {
+ manager.addImport(parameter.getType());
+ }
+ }
+ return manager;
}
public void build() {
@@ -71,7 +107,7 @@
public void build(ObjectModel objectModel) {
this.objectModel = (ObjectModelImpl)objectModel;
- initFiles();
+ //initFiles();
build(); // Ajout elements, ...
//String filename = getFilenameForModel(objectModel);
@@ -136,5 +172,4 @@
public void buildFromEnumeration(ObjectModelEnumeration model) {
}
-
}
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModel.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModel.java 2009-10-22 12:39:16 UTC (rev 655)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModel.java 2009-10-22 15:54:03 UTC (rev 656)
@@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.List;
+import org.nuiton.eugene.ImportsManager;
import org.nuiton.eugene.models.Model;
/**
@@ -120,4 +121,12 @@
*/
public List<String> getComments();
+ /**
+ * Return specific ImportsManager for a classifier
+ *
+ * @param qualifiedName of the classifier
+ * @return the ImportsManager associated to the classifier, create a new one if not exist
+ */
+ public List<String> getImports(ObjectModelClassifier element);
+
} //ObjectModel
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassifierImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassifierImpl.java 2009-10-22 12:39:16 UTC (rev 655)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassifierImpl.java 2009-10-22 15:54:03 UTC (rev 656)
@@ -58,6 +58,7 @@
protected String type = null;
+ @Override
public String toString() {
return "" + getQualifiedName() + " implements " + getInterfaces();
}
@@ -66,6 +67,7 @@
super();
}
+ @Override
public void postInit() {
super.postInit();
qualifiedName = packageName + "." + name;
@@ -116,14 +118,17 @@
return extern;
}
+ @Override
public String getPackageName() {
return packageName;
}
+ @Override
public String getQualifiedName() {
return qualifiedName;
}
+ @Override
public Collection<ObjectModelInterface> getInterfaces() {
if (interfaces == null) {
interfaces = new ArrayList<ObjectModelInterface>();
@@ -134,6 +139,7 @@
return interfaces;
}
+ @Override
public Collection<ObjectModelOperation> getOperations(String name) {
List<ObjectModelOperation> result = new ArrayList<ObjectModelOperation>();
for (Iterator<ObjectModelOperation> i = getOperations().iterator(); i
@@ -146,6 +152,7 @@
return result;
}
+ @Override
public Collection<ObjectModelOperation> getOperations() {
return operations;
}
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java 2009-10-22 12:39:16 UTC (rev 655)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java 2009-10-22 15:54:03 UTC (rev 656)
@@ -26,6 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.ImportsManager;
import org.nuiton.eugene.models.object.ObjectModel;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
import org.nuiton.eugene.models.object.ObjectModelClass;
@@ -59,6 +60,8 @@
protected List<String> comments = new ArrayList<String>();
private Map<String, String> tagValues = new HashMap<String, String>();
+ private Map<String, ImportsManager> importsManagers = new HashMap<String, ImportsManager>();
+
private static Log log = LogFactory.getLog(ObjectModelImpl.class);
public void setName(String name) {
@@ -492,4 +495,23 @@
public String getTagValue(String tagValue) {
return (tagValue == null ? null : (String) tagValues.get(tagValue));
}
+
+ @Override
+ public List<String> getImports(ObjectModelClassifier classifier) {
+ ImportsManager manager = importsManagers.get(classifier.getQualifiedName());
+ if (manager == null) {
+ throw new IllegalArgumentException("ImportsManager is not defined for classifier '" +
+ classifier.getQualifiedName() + "'");
+ }
+ return manager.getImports(classifier.getPackageName());
+ }
+
+ public ImportsManager getImportsManager(String qualifiedName) {
+ ImportsManager manager = importsManagers.get(qualifiedName);
+ if (manager == null) {
+ manager = new ImportsManager();
+ importsManagers.put(qualifiedName, manager);
+ }
+ return manager;
+ }
}
Modified: branches/1.1.0-Javabuilder/eugene-test/pom.xml
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/pom.xml 2009-10-22 12:39:16 UTC (rev 655)
+++ branches/1.1.0-Javabuilder/eugene-test/pom.xml 2009-10-22 15:54:03 UTC (rev 656)
@@ -92,6 +92,24 @@
<groupId>org.nuiton.eugene</groupId>
<artifactId>maven-eugene-plugin</artifactId>
<version>${project.version}</version>
+ <!--executions>
+ <execution>
+ <id>Test Java Generator</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+ <includes>**/*.objectmodel</includes>
+ <templates>org.nuiton.eugene.test.generator.JavaGenerator</templates>
+ <defaultPackage>org.nuiton.eugene.test</defaultPackage>
+ <extraClassPathDirectory>target/classes</extraClassPathDirectory>
+ <generateResources>
+ <input>src/main/models</input>
+ </generateResources>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions-->
</plugin>
<!--plugin>
Modified: branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/DTOBuilder.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/DTOBuilder.java 2009-10-22 12:39:16 UTC (rev 655)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/DTOBuilder.java 2009-10-22 15:54:03 UTC (rev 656)
@@ -2,6 +2,7 @@
import java.util.List;
import org.apache.commons.lang.StringUtils;
+import org.nuiton.eugene.ImportsManager;
import org.nuiton.eugene.JavaBuilder;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
import org.nuiton.eugene.models.object.ObjectModelClass;
@@ -27,22 +28,24 @@
getHelper().addOperation(clazz, "set" + attributeNameCapitalize,
null, attribute.getType(), attributeName);
- getHelper().setOperationBody(operationSetter, "" /*{
- this.<%=attributeName%> = <%=attributeName%>;
- }*/);
+ getHelper().setOperationBody(operationSetter, ""
+/*{
+ this.<%=attributeName%> = <%=attributeName%>;
+ }*/
+ );
ObjectModelOperation operationGetter =
getHelper().addOperation(clazz, "get" + attributeNameCapitalize,
attribute.getType());
- getHelper().setOperationBody(operationGetter, "" /*{
- return this.<%=attributeName%>;
- }*/);
+ getHelper().setOperationBody(operationGetter, ""
+/*{
+ return this.<%=attributeName%>;
+}*/
+ );
}
-
-
- JavaFile file = getFile(clazz.getQualifiedName());
- file.addImport(List.class);
+
+ this.addImportForClassifier(clazz, List.class);
}
}
Added: branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/JavaGenerator.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/JavaGenerator.java (rev 0)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/JavaGenerator.java 2009-10-22 15:54:03 UTC (rev 656)
@@ -0,0 +1,196 @@
+
+package org.nuiton.eugene.test.generator;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+import org.nuiton.eugene.ObjectModelGenerator;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelClassifier;
+import org.nuiton.eugene.models.object.ObjectModelInterface;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.eugene.models.object.ObjectModelParameter;
+
+/*{generator option: parentheses = true}*/
+/*{generator option: writeString = output.write}*/
+/**
+ * JavaGenerator
+ *
+ * Created: 22 oct. 2009
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class JavaGenerator extends ObjectModelGenerator {
+
+ @Override
+ public String getFilenameForClass(ObjectModelClass clazz) {
+ return clazz.getName() + ".java";
+ }
+
+ @Override
+ public void generateFromClassifier(Writer output, ObjectModelClassifier classifier) {
+
+
+ }
+
+ @Override
+ public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
+
+ this.generateHeader(output, clazz); // Imports, package et documentation
+
+ String abstractStr = clazz.isAbstract() ? " abstract " : " ";
+ String className = clazz.getName();
+
+ String extend = "";
+ Iterator<ObjectModelClass> j = clazz.getSuperclasses().iterator();
+ if (j.hasNext()) {
+ ObjectModelClassifier p = j.next();
+ extend += p.getName();
+ }
+
+ String implement = "";
+ for (Iterator<ObjectModelInterface> i = clazz.getInterfaces().iterator(); i.hasNext();) {
+ ObjectModelClassifier parentInterface = i.next();
+ implement += parentInterface.getName();
+ if (i.hasNext()) {
+ implement += ", ";
+ }
+ }
+
+/*{
+public<%=abstractStr%>class <%=className%>}*/
+
+/*
+ * Définition de la super classe : il ne doit y avoir qu'une
+ */
+ if (extend.length() > 0) {
+/*{ extends <%=extend%>}*/
+ }
+
+ if (implement.length() > 0) {
+/*{ implements <%=implement%> {
+
+}*/
+ } else {
+ /*{ {
+
+}*/
+ }
+
+ this.generateAttributes(output, clazz.getAttributes());
+ this.generateOperations(output, clazz.getOperations());
+/*{
+} //<%=clazz.getName()%>
+}*/
+ }
+
+ protected void generateHeader(Writer output, ObjectModelClassifier classifier) throws IOException {
+
+ String packageName = classifier.getPackageName();
+/*{package <%=packageName%>;
+
+}*/
+ // potentiel crash si imports non defini
+ // dans ce cas, probleme de config utilisateur ! obligation de passer par un builder ?
+ for (String imports : getModel().getImports(classifier)) {
+/*{import <%=imports%>;
+ }*/
+ }
+
+ }
+
+ protected void generateAttributes(Writer output, Collection<ObjectModelAttribute> attributes) throws IOException {
+
+ for (ObjectModelAttribute attr : attributes) {
+
+ if (!attr.getDocumentation().isEmpty()) {
+/*{ /**
+ * <%=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 = getSimpleName(attr.getType());
+ String attrStatic = attr.isStatic() ? " static " : " ";
+ String attrFinal = attr.isFinal() ? " final " : " ";
+ String attrValue = !attr.getDefaultValue().isEmpty() ? " = " + attr.getDefaultValue() : "";
+
+/*{ <%=attrVisibility%><%=attrStatic%><%=attrFinal%><%=attrType%> <%=attrName%><%=attrValue%>;
+}*/
+ }
+ }
+
+ protected void generateOperations(Writer output, Collection<ObjectModelOperation> operations) throws IOException {
+ for (ObjectModelOperation op : operations) {
+ String opName = op.getName();
+/*{ /**
+}*/
+ if (!op.getDocumentation().isEmpty()) {
+ 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 opStatic = op.isStatic() ? " static " : "";
+ String opAbstract = op.isAbstract() ? " abstract " : "";
+
+ ObjectModelParameter returnParam = op.getReturnParameter();
+ String opReturn = getSimpleName(returnParam.getType());
+ if (!opReturn.equals("void")) {
+ String paramDocumentation = returnParam.getDocumentation();
+/*{ * @return <%=paramDocumentation%>
+ }*/
+ }
+/*{ *)
+ <%=opVisibility%><%=opStatic%><%=opAbstract%><%=opReturn%> <%=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 = ", ";
+ }
+/*{;
+
+}*/
+ }
+ }
+
+ private static String getSimpleName(String qualifiedName) {
+ String result = qualifiedName;
+ int dot = qualifiedName.lastIndexOf(".");
+ if (dot >- 1) {
+ result = qualifiedName.substring(dot + 1);
+ }
+ return result;
+ }
+}
Modified: branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java 2009-10-22 12:39:16 UTC (rev 655)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/TestBuilder.java 2009-10-22 15:54:03 UTC (rev 656)
@@ -6,11 +6,9 @@
import org.nuiton.eugene.JavaBuilder;
import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelOperation;
-import org.nuiton.eugene.models.object.builder.JavaFile;
/*{generator option: parentheses = false}*/
/*{generator option: writeString = +}*/
-
/**
*
* @author fdesbois
@@ -21,29 +19,27 @@
public void build() {
createRole();
createPerson();
-
-
}
private void createRole() {
ObjectModelClass roleClass = getHelper().createClass("Role", "org.chorem.bonzoms");
- JavaFile roleFile = this.createJavaClassFile(roleClass);
+ this.addClassToModel(roleClass);
getHelper().addAttribute(roleClass, "name", "String");
- roleFile.addImport(Date.class);
+ this.addImportForClassifier(roleClass, Date.class);
getHelper().addAttribute(roleClass, "fromDate", "Date");
getHelper().addAttribute(roleClass, "thruDate", "Date");
}
private void createPerson() {
ObjectModelClass personneClass = getHelper().createClass("Person", "org.chorem.bonzoms");
- JavaFile personneFile = this.createJavaClassFile(personneClass);
+ this.addClassToModel(personneClass);
getHelper().addAttribute(personneClass, "lastName", "String");
getHelper().addAttribute(personneClass, "firstName", "String");
- personneFile.addImport(List.class);
+ this.addImportForClassifier(personneClass, List.class);
getHelper().addAttribute(personneClass, "roles", "List<Role>");
Modified: branches/1.1.0-Javabuilder/eugene-test/src/main/resources/log4j.properties
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/resources/log4j.properties 2009-10-22 12:39:16 UTC (rev 655)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/resources/log4j.properties 2009-10-22 15:54:03 UTC (rev 656)
@@ -9,3 +9,4 @@
# package level
log4j.logger.org.nuiton.eugene=INFO
log4j.logger.org.nuiton.eugene.test=DEBUG
+log4j.logger.org.nuiton.processor=DEBUG
1
0
r655 - in branches/1.1.0-Javabuilder: eugene/src/main/java/org/nuiton/eugene eugene/src/main/java/org/nuiton/eugene/models/object/builder eugene-test/src/main/java/org/nuiton/eugene/test/generator eugene-test/src/test/java/org/nuiton/eugene/test/generator
by fdesbois@users.nuiton.org 22 Oct '09
by fdesbois@users.nuiton.org 22 Oct '09
22 Oct '09
Author: fdesbois
Date: 2009-10-22 14:39:16 +0200 (Thu, 22 Oct 2009)
New Revision: 655
Modified:
branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/DTOBuilder.java
branches/1.1.0-Javabuilder/eugene-test/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/JavaBuilder.java
branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/builder/JavaFile.java
Log:
Add same pattern for build as generator (buildFromClass, ...)
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/JavaBuilder.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/JavaBuilder.java 2009-10-22 10:50:13 UTC (rev 654)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/JavaBuilder.java 2009-10-22 12:39:16 UTC (rev 655)
@@ -1,12 +1,16 @@
package org.nuiton.eugene;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.nuiton.eugene.models.object.ObjectModel;
import org.nuiton.eugene.models.object.ObjectModelBuilderHelper;
import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelClassifier;
+import org.nuiton.eugene.models.object.ObjectModelElement;
+import org.nuiton.eugene.models.object.ObjectModelEnumeration;
+import org.nuiton.eugene.models.object.ObjectModelInterface;
import org.nuiton.eugene.models.object.builder.JavaClassFile;
import org.nuiton.eugene.models.object.builder.JavaFile;
import org.nuiton.eugene.models.object.xml.ObjectModelClassImpl;
@@ -29,38 +33,108 @@
this.javaFiles = new HashMap<String, JavaFile>();
}
- public void setModel(ObjectModel objectModel) {
- this.objectModel = (ObjectModelImpl)objectModel;
- initFiles();
+ public JavaFile getFile(String qualifiedName) {
+ return javaFiles.get(qualifiedName);
}
+ public ObjectModel getModel() {
+ return objectModel;
+ }
+
+ public ObjectModelBuilderHelper getHelper() {
+ return helper;
+ }
+
protected void initFiles() {
javaFiles.clear();
for (ObjectModelClass clazz : objectModel.getClasses()) {
JavaClassFile javaFile = new JavaClassFile(clazz);
javaFiles.put(clazz.getQualifiedName(), javaFile);
}
+ // init Imports ?
}
protected JavaClassFile createJavaClassFile(ObjectModelClass clazz) {
+ if (javaFiles.containsKey(clazz.getQualifiedName())) {
+ throw new IllegalArgumentException("ClassFile '" + clazz.getQualifiedName() + "' already exist");
+ }
JavaClassFile javaFile = new JavaClassFile(clazz);
objectModel.addClass((ObjectModelClassImpl)clazz);
javaFiles.put(clazz.getQualifiedName(), javaFile);
+ // init Imports ?
return javaFile;
}
- public JavaFile getFile(String qualifiedName) {
- return javaFiles.get(qualifiedName);
+ public void build() {
+
}
- public ObjectModel getModel() {
- return objectModel;
+ public void build(ObjectModel objectModel) {
+ this.objectModel = (ObjectModelImpl)objectModel;
+ initFiles();
+ build(); // Ajout elements, ...
+
+ //String filename = getFilenameForModel(objectModel);
+ buildFromElement(objectModel, ObjectModelType.OBJECT_MODEL);
+
+ buildFromElements(objectModel.getClassifiers(),
+ ObjectModelType.OBJECT_MODEL_CLASSIFIER);
+
+ buildFromElements(objectModel.getInterfaces(),
+ ObjectModelType.OBJECT_MODEL_INTERFACE);
+
+ buildFromElements(objectModel.getClasses(),
+ ObjectModelType.OBJECT_MODEL_CLASS);
+
+ buildFromElements(objectModel.getEnumerations(),
+ ObjectModelType.OBJECT_MODEL_ENUMERATION);
+
}
- public ObjectModelBuilderHelper getHelper() {
- return helper;
+ private void buildFromElements(Collection<? extends ObjectModelElement> elements, ObjectModelType type) {
+ for (ObjectModelElement element : elements) {
+ buildFromElement(element, type);
+ }
}
+
+ protected void buildFromElement(Object element, ObjectModelType type) {
+ switch (type) {
+ case OBJECT_MODEL:
+ buildFromModel((ObjectModel)element);
+ break;
+ case OBJECT_MODEL_CLASSIFIER:
+ buildFromClassifier((ObjectModelClassifier)element);
+ break;
+ case OBJECT_MODEL_INTERFACE:
+ buildFromInterface((ObjectModelInterface)element);
+ break;
+ case OBJECT_MODEL_CLASS:
+ buildFromClass((ObjectModelClass)element);
+ break;
+ case OBJECT_MODEL_ENUMERATION:
+ buildFromEnumeration((ObjectModelEnumeration)element);
+ break;
+ }
+ }
- public abstract void build();
+ public void buildFromModel(ObjectModel model) {
+ }
+
+ public void buildFromClassifier(ObjectModelClassifier model) {
+
+ }
+
+ public void buildFromInterface(ObjectModelInterface model) {
+
+ }
+
+ public void buildFromClass(ObjectModelClass model) {
+
+ }
+
+ public void buildFromEnumeration(ObjectModelEnumeration model) {
+
+ }
+
}
Modified: branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/builder/JavaFile.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/builder/JavaFile.java 2009-10-22 10:50:13 UTC (rev 654)
+++ branches/1.1.0-Javabuilder/eugene/src/main/java/org/nuiton/eugene/models/object/builder/JavaFile.java 2009-10-22 12:39:16 UTC (rev 655)
@@ -5,6 +5,7 @@
package org.nuiton.eugene.models.object.builder;
+import java.io.File;
import org.nuiton.eugene.ImportsManager;
import org.nuiton.eugene.models.object.ObjectModelClassifier;
import org.nuiton.eugene.models.object.xml.ObjectModelClassifierImpl;
Modified: branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/DTOBuilder.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/DTOBuilder.java 2009-10-22 10:50:13 UTC (rev 654)
+++ branches/1.1.0-Javabuilder/eugene-test/src/main/java/org/nuiton/eugene/test/generator/DTOBuilder.java 2009-10-22 12:39:16 UTC (rev 655)
@@ -6,10 +6,10 @@
import org.nuiton.eugene.models.object.ObjectModelAttribute;
import org.nuiton.eugene.models.object.ObjectModelClass;
import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.eugene.models.object.builder.JavaFile;
/*{generator option: parentheses = false}*/
/*{generator option: writeString = +}*/
-
/**
*
* @author fdesbois
@@ -17,41 +17,33 @@
public class DTOBuilder extends JavaBuilder {
@Override
- public void build() {
+ public void buildFromClass(ObjectModelClass clazz) {
- for (ObjectModelClass clazz : getModel().getClasses()) {
+ if (!clazz.hasStereotype("dto")) {
+ for (ObjectModelAttribute attribute : clazz.getAttributes()) {
+ String attributeNameCapitalize = StringUtils.capitalize(attribute.getName());
+ String attributeName = attribute.getName();
+ ObjectModelOperation operationSetter =
+ getHelper().addOperation(clazz, "set" + attributeNameCapitalize,
+ null, attribute.getType(), attributeName);
- if (clazz.hasStereotype("dto")) {
- for (ObjectModelAttribute attribute : clazz.getAttributes()) {
- String attributeNameCapitalize = StringUtils.capitalize(attribute.getName());
- String attributeName = attribute.getName();
- ObjectModelOperation operationSetter =
- getHelper().addOperation(clazz, "set" + attributeNameCapitalize,
- null, attribute.getType(), attributeName);
-
- getHelper().setOperationBody(operationSetter, "" /*{
+ getHelper().setOperationBody(operationSetter, "" /*{
this.<%=attributeName%> = <%=attributeName%>;
- }*/);
+ }*/);
- ObjectModelOperation operationGetter =
- getHelper().addOperation(clazz, "get" + attributeNameCapitalize,
- attribute.getType());
+ ObjectModelOperation operationGetter =
+ getHelper().addOperation(clazz, "get" + attributeNameCapitalize,
+ attribute.getType());
- getHelper().setOperationBody(operationGetter, "" /*{
+ getHelper().setOperationBody(operationGetter, "" /*{
return this.<%=attributeName%>;
- }*/);
- }
-
-
- getFile(clazz.getQualifiedName()).addImport(List.class);
+ }*/);
}
-
+ JavaFile file = getFile(clazz.getQualifiedName());
+ file.addImport(List.class);
}
}
-
-
-
}
Modified: branches/1.1.0-Javabuilder/eugene-test/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java
===================================================================
--- branches/1.1.0-Javabuilder/eugene-test/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java 2009-10-22 10:50:13 UTC (rev 654)
+++ branches/1.1.0-Javabuilder/eugene-test/src/test/java/org/nuiton/eugene/test/generator/TestBuilderTest.java 2009-10-22 12:39:16 UTC (rev 655)
@@ -60,7 +60,7 @@
assertEquals(result.getClasses().size(), 2);
ObjectModelClass clazz = result.getClass("org.chorem.bonzoms.Person");
assertNotNull(clazz);
- assertEquals(clazz.getAttributes().size(), 2);
+ assertEquals(clazz.getAttributes().size(), 3);
assertEquals(clazz.getOperations().size(), 2);
List<ObjectModelOperation> operations = (List<ObjectModelOperation>)clazz.getOperations();
ObjectModelOperation operation = operations.get(0);
1
0