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
- 1738 discussions
r785 - in trunk/eugene/src: main/java/org/nuiton/eugene test/java/org/nuiton/eugene
by echatellier@users.nuiton.org 07 Jan '10
by echatellier@users.nuiton.org 07 Jan '10
07 Jan '10
Author: echatellier
Date: 2010-01-07 16:48:04 +0100 (Thu, 07 Jan 2010)
New Revision: 785
Modified:
trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java
trunk/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java
Log:
Add a quick hack for test to pass
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java 2010-01-07 14:40:34 UTC (rev 784)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java 2010-01-07 15:48:04 UTC (rev 785)
@@ -602,10 +602,16 @@
return result;
}
+ /**
+ * Parse a fully qualified generic java type, and extract each
+ * imbricated types.
+ *
+ * @param str string to parse
+ * @return set of found types
+ */
public static Set<String> getTypesList(String str) {
- String regex = "^(([\\w\\s\\?]*\\s))?([\\w\\.]+)((<)(.*)(>))?(\\(\\))?$";
- Pattern p = Pattern.compile(regex);
+ Pattern p = Pattern.compile("^(([\\w\\s\\?]*\\s))?([\\w\\.]+)((<)(.*)(>))?(\\(\\))?$");
Matcher m = p.matcher(str);
Set<String> results = new HashSet<String>();
@@ -613,26 +619,14 @@
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*)")) {
+ // FIXME can not work in some case
+ if (m.group(6).matches("[^,]+<.*>")) {
+ results.addAll(getTypesList(m.group(6)));
+ }
+ else 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;
Modified: trunk/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java 2010-01-07 14:40:34 UTC (rev 784)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java 2010-01-07 15:48:04 UTC (rev 785)
@@ -195,10 +195,20 @@
log.info(str + " -> " + results);
assertEquals(4, results.size());
-// str = "java.util.List<java.util.Map<java.util.Date, java.lang.Integer>>";
-// results = GeneratorUtil.getTypesList(str);
-// log.info(str + " -> " + results);
-// assertEquals(4, results.size());
+ str = "java.util.List<java.util.Map<java.util.Date, java.lang.Integer>>";
+ results = GeneratorUtil.getTypesList(str);
+ log.info(str + " -> " + results);
+ assertEquals(4, results.size());
+
+ str = "java.util.List<java.util.Map<java.util.Date, java.lang.Integer>>";
+ results = GeneratorUtil.getTypesList(str);
+ log.info(str + " -> " + results);
+ assertEquals(4, results.size());
+
+ //str = "java.util.TreeMap<java.util.ArrayList<java.util.Date>, java.util.SortedSet<java.lang.Number, java.lang.Double>>";
+ //results = GeneratorUtil.getTypesList(str);
+ //log.info(str + " -> " + results);
+ //assertEquals(4, results.size());
// str = "<T extends org.nuiton.topia.TopiaEntity> T";
// results = GeneratorUtil.getTypesList(str);
1
0
07 Jan '10
Author: fdesbois
Date: 2010-01-07 15:40:34 +0100 (Thu, 07 Jan 2010)
New Revision: 784
Modified:
trunk/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java
Log:
Add failed test for parsing Imports
Modified: trunk/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java 2010-01-07 03:27:29 UTC (rev 783)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java 2010-01-07 14:40:34 UTC (rev 784)
@@ -157,44 +157,49 @@
String str = "List";
Set<String> results = GeneratorUtil.getTypesList(str);
log.info(str + " -> " + results);
- assertEquals(results.size(), 1);
+ assertEquals(1, results.size());
str = "java.util.Regex";
results = GeneratorUtil.getTypesList(str);
log.info(str + " -> " + results);
- assertEquals(results.size(), 1);
+ assertEquals(1, results.size());
str = "java.util.List<? extends org.chorem.bonzoms.Bonzoms>";
results = GeneratorUtil.getTypesList(str);
log.info(str + " -> " + results);
- assertEquals(results.size(), 2);
+ assertEquals(2, results.size());
str = "java.util.List<org.chorem.jtimer.Jtimer>";
results = GeneratorUtil.getTypesList(str);
log.info(str + " -> " + results);
- assertEquals(results.size(), 2);
+ assertEquals(2, results.size());
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);
+ assertEquals(3, results.size());
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);
+ assertEquals(4, results.size());
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);
+ assertEquals(3, results.size());
str = "java.util.Map<org.chorem.jtimer.Jtimer, java.util.Collection<String>>";
results = GeneratorUtil.getTypesList(str);
log.info(str + " -> " + results);
- assertEquals(results.size(), 4);
+ assertEquals(4, results.size());
+// str = "java.util.List<java.util.Map<java.util.Date, java.lang.Integer>>";
+// results = GeneratorUtil.getTypesList(str);
+// log.info(str + " -> " + results);
+// assertEquals(4, results.size());
+
// str = "<T extends org.nuiton.topia.TopiaEntity> T";
// results = GeneratorUtil.getTypesList(str);
// log.info(str + " -> " + results);
1
0
Author: tchemit
Date: 2010-01-07 04:27:29 +0100 (Thu, 07 Jan 2010)
New Revision: 783
Modified:
trunk/pom.xml
Log:
use mavenpom 1.1.4
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-01-01 17:19:03 UTC (rev 782)
+++ trunk/pom.xml 2010-01-07 03:27:29 UTC (rev 783)
@@ -9,7 +9,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom</artifactId>
- <version>1.1.4-SNAPSHOT</version>
+ <version>1.1.4</version>
</parent>
<artifactId>eugene</artifactId>
1
0
Author: tchemit
Date: 2010-01-01 18:19:03 +0100 (Fri, 01 Jan 2010)
New Revision: 782
Modified:
trunk/maven-eugene-plugin/pom.xml
trunk/pom.xml
Log:
- use javadoc configuration from mavenpom
- clean comment code in pom
Modified: trunk/maven-eugene-plugin/pom.xml
===================================================================
--- trunk/maven-eugene-plugin/pom.xml 2010-01-01 16:53:29 UTC (rev 781)
+++ trunk/maven-eugene-plugin/pom.xml 2010-01-01 17:19:03 UTC (rev 782)
@@ -85,13 +85,7 @@
<execution>
<goals>
<goal>generate-metadata</goal>
- <!--<goal>merge-metadata</goal>-->
</goals>
- <!--configuration>
- <descriptors>
- <descriptor>${maven.src.dir}/main/plexus/components.xml</descriptor>
- </descriptors>
- </configuration-->
</execution>
</executions>
</plugin>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-01-01 16:53:29 UTC (rev 781)
+++ trunk/pom.xml 2010-01-01 17:19:03 UTC (rev 782)
@@ -288,195 +288,6 @@
<version>1.4.0</version>
</plugin>
- <plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>${javadoc.version}</version>
- <configuration>
- <docencoding>${project.reporting.outputEncoding}</docencoding>
- <encoding>${project.reporting.outputEncoding}</encoding>
- <charset>${project.reporting.outputEncoding}</charset>
- <quiet>true</quiet>
- <skip>${maven.javadoc.skip}</skip>
- <taglets>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>
- org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>
- org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
-
- <taglet>
- <tagletClass>org.codehaus.plexus.javadoc.PlexusComponentTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-component-javadoc</artifactId>
- <version>1.3.0</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.codehaus.plexus.javadoc.PlexusConfigurationTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-component-javadoc</artifactId>
- <version>1.3.0</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.codehaus.plexus.javadoc.PlexusRequirementTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-component-javadoc</artifactId>
- <version>1.3.0</version>
- </tagletArtifact>
- </taglet>
- </taglets>
- </configuration>
- </plugin>
-
</plugins>
</pluginManagement>
@@ -488,186 +299,6 @@
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${javadoc.version}</version>
- <configuration>
- <quiet>true</quiet>
- <skip>${maven.javadoc.skip}</skip>
- <docencoding>${project.build.sourceEncoding}</docencoding>
- <encoding>${project.build.sourceEncoding}</encoding>
- <charset>${project.reporting.outputEncoding}</charset>
- <excludePackageNames>${maven.javadoc.excludePackageNames}</excludePackageNames>
- <taglets>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>
- org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet
- </tagletClass>
- <tagletArtifact>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-tools-javadoc</artifactId>
- <version>2.5.1</version>
- </tagletArtifact>
- </taglet>
-
- <taglet>
- <tagletClass>org.codehaus.plexus.javadoc.PlexusComponentTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-component-javadoc</artifactId>
- <version>1.3.0</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.codehaus.plexus.javadoc.PlexusConfigurationTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-component-javadoc</artifactId>
- <version>1.3.0</version>
- </tagletArtifact>
- </taglet>
- <taglet>
- <tagletClass>org.codehaus.plexus.javadoc.PlexusRequirementTaglet</tagletClass>
- <tagletArtifact>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-component-javadoc</artifactId>
- <version>1.3.0</version>
- </tagletArtifact>
- </taglet>
- </taglets>
- </configuration>
<reportSets>
<reportSet>
<reports>
1
0
r781 - in trunk: . maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin
by tchemit@users.nuiton.org 01 Jan '10
by tchemit@users.nuiton.org 01 Jan '10
01 Jan '10
Author: tchemit
Date: 2010-01-01 17:53:29 +0100 (Fri, 01 Jan 2010)
New Revision: 781
Modified:
trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/CopyVersionFiles.java
trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugeneAbstractMojo.java
trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java
trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/SmartGenerateMojo.java
trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2Model.java
trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2ObjectModel.java
trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2StateModel.java
trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Zargo2Xmi.java
trunk/pom.xml
Log:
- use last version of mavenpom and maven-helper-plugin new api
- review exception management (should review it again together I think)
Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/CopyVersionFiles.java
===================================================================
--- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/CopyVersionFiles.java 2009-12-20 16:49:46 UTC (rev 780)
+++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/CopyVersionFiles.java 2010-01-01 16:53:29 UTC (rev 781)
@@ -123,7 +123,7 @@
protected File fVersionDir;
@Override
- public void doAction() throws MojoExecutionException, MojoFailureException {
+ public void doAction() throws Exception {
// find version and model name
findVersionAndModelName();
@@ -138,11 +138,11 @@
String destDir = copyVersionDir.replace("%MODELNAME%", modelNameFound) + File.separator + versionFound;
fVersionDir = new File(destDir);
if (overwrite || !checkExistence()) {
- try {
+// try {
PluginHelper.copyFiles(copyVersionResources.getOutput(), fVersionDir, new String[]{copyVersionFiles}, null, true);
- } catch (IOException ex) {
- throw new MojoExecutionException("could not copy some files for reason " + ex.getMessage(), ex);
- }
+// } catch (IOException ex) {
+// throw new MojoExecutionException("could not copy some files for reason " + ex.getMessage(), ex);
+// }
}
}
Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugeneAbstractMojo.java
===================================================================
--- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugeneAbstractMojo.java 2009-12-20 16:49:46 UTC (rev 780)
+++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugeneAbstractMojo.java 2010-01-01 16:53:29 UTC (rev 781)
@@ -23,7 +23,6 @@
import org.nuiton.plugin.PluginIOContext;
import java.io.File;
-import java.io.IOException;
import java.util.Arrays;
import org.apache.maven.plugin.MojoExecutionException;
@@ -146,7 +145,8 @@
}
@Override
- protected boolean init() throws Exception {
+ protected void init() throws Exception {
+// protected boolean init() throws Exception {
// init goal io context
PluginIOContext p = initResources();
@@ -158,13 +158,14 @@
throw new MojoExecutionException("no output defined");
}
- if (!p.getOutput().exists()) {
- boolean b = p.getOutput().mkdirs();
- if (!b) {
- throw new IOException("could not create directory " + p.getOutput());
- }
- }
- return true;
+ createDirectoryIfNecessary(p.getOutput());
+// if (!p.getOutput().exists()) {
+// boolean b = p.getOutput().mkdirs();
+// if (!b) {
+// throw new IOException("could not create directory " + p.getOutput());
+// }
+// }
+// return true;
}
@Override
Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java
===================================================================
--- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java 2009-12-20 16:49:46 UTC (rev 780)
+++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/EugenePlugin.java 2010-01-01 16:53:29 UTC (rev 781)
@@ -18,20 +18,6 @@
* ##%*/
package org.nuiton.eugene.plugin;
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Properties;
-import java.util.Map.Entry;
-
-import java.util.Set;
-
import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Resource;
@@ -41,9 +27,16 @@
import org.nuiton.eugene.ModelReader;
import org.nuiton.eugene.Template;
import org.nuiton.eugene.models.Model;
-import org.nuiton.plugin.PluginIOContext;
import org.nuiton.plugin.PluginHelper;
+import org.nuiton.plugin.PluginIOContext;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.*;
+import java.util.Map.Entry;
+
/**
* Effectue toutes les générations et copie les fichiers générés
* dans le répertoire de compilation
@@ -154,7 +147,7 @@
@Override
- public void doAction() throws MojoExecutionException, MojoFailureException {
+ public void doAction() throws Exception {
getLog().info("Generating java sources from models");
getLog().info(" reader : " + reader);
@@ -179,7 +172,8 @@
fixCompileSourceRoots();
}
- protected <M extends Model> void generate(File[] modelFiles, ModelReader<M> modelReader) throws MojoFailureException, MojoExecutionException {
+ protected <M extends Model> void generate(File[] modelFiles, ModelReader<M> modelReader) throws Exception {
+// protected <M extends Model> void generate(File[] modelFiles, ModelReader<M> modelReader) throws MojoFailureException, MojoExecutionException {
if (modelReader == null) {
// can skip
@@ -201,11 +195,11 @@
for (Template<M> template : templatesList) {
getLog().info("Apply " + template.getClass().getSimpleName() + " generator");
- try {
+// try {
template.applyTemplate(model, generateResources.getOutput());
- } catch (IOException eee) {
- throw new MojoExecutionException("Generation problem", eee);
- }
+// } catch (IOException eee) {
+// throw new MojoExecutionException("Generation problem", eee);
+// }
}
}
Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/SmartGenerateMojo.java
===================================================================
--- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/SmartGenerateMojo.java 2009-12-20 16:49:46 UTC (rev 780)
+++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/SmartGenerateMojo.java 2010-01-01 16:53:29 UTC (rev 781)
@@ -286,7 +286,8 @@
protected ClassLoader fixedClassLoader;
@Override
- protected boolean init() throws Exception {
+ protected void init() throws Exception {
+// protected boolean init() throws Exception {
modelType = modelType.trim().toLowerCase();
@@ -326,8 +327,9 @@
}
if (engine.getSelectedWriters().isEmpty()) {
- getLog().warn("No phase was detected, skip the goal.");
- return false;
+ return;
+// getLog().warn("No phase was detected, skip the goal.");
+// return false;
}
if (properties == null) {
@@ -353,6 +355,15 @@
properties.put(ModelChainedFileWriter.PROP_EXCLUDE_TEMPLATES, getExcludeTemplatesAsString());
}
+// return true;
+ }
+
+ @Override
+ protected boolean checkSkip() {
+ if (engine.getSelectedWriters().isEmpty()) {
+ getLog().warn("No phase was detected, skip the goal.");
+ return false;
+ }
return true;
}
@@ -402,11 +413,11 @@
getLog().debug("Generating files and copying resources...");
}
- try {
+// try {
writer.generate(this);
- } catch (Exception e) {
- throw new MojoExecutionException("could not generate for writer " + writer.getInputProtocol(), e);
- }
+// } catch (Exception e) {
+// throw new MojoExecutionException("could not generate for writer " + writer.getInputProtocol(), e);
+// }
if ("model".equals(writer.getInputProtocol())) {
Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2Model.java
===================================================================
--- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2Model.java 2009-12-20 16:49:46 UTC (rev 780)
+++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2Model.java 2010-01-01 16:53:29 UTC (rev 781)
@@ -21,7 +21,6 @@
import org.nuiton.plugin.PluginIOContext;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URL;
@@ -40,7 +39,6 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.nuiton.plugin.PluginHelper;
import org.nuiton.util.FasterCachedResourceResolver;
@@ -155,7 +153,7 @@
protected abstract String getStyleSheet(File model);
@Override
- public void doAction() throws MojoExecutionException, MojoFailureException {
+ public void doAction() throws Exception {
long t0 = System.nanoTime();
try {
@@ -186,12 +184,12 @@
getLog().info("Copy resources files");
- try {
+// try {
String[] excludes = getSuffixPattern("**/*");
PluginHelper.copyFiles(xmiResources, null, excludes, overwrite);
- } catch (IOException ex) {
- throw new MojoExecutionException("could not copy some files for reason " + ex.getMessage(), ex);
- }
+// } catch (IOException ex) {
+// throw new MojoExecutionException("could not copy some files for reason " + ex.getMessage(), ex);
+// }
}
@Override
@@ -241,7 +239,8 @@
File dstDir = xmiResources.getOutput();
if (!relatifPath.isEmpty()) {
dstDir = new File(dstDir, relatifPath);
- dstDir.mkdirs();
+ createDirectoryIfNecessary(dstDir);
+// dstDir.mkdirs();
}
File result = new File(dstDir, filename);
if (!overwrite && file.lastModified() < result.lastModified()) {
Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2ObjectModel.java
===================================================================
--- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2ObjectModel.java 2009-12-20 16:49:46 UTC (rev 780)
+++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2ObjectModel.java 2010-01-01 16:53:29 UTC (rev 781)
@@ -19,19 +19,16 @@
*/
package org.nuiton.eugene.plugin;
-import java.io.File;
-import java.io.IOException;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import java.io.File;
+import java.io.IOException;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
/**
* Converti les fichiers XMI en fichier ObjectModel
*
@@ -43,7 +40,8 @@
public class Xmi2ObjectModel extends Xmi2Model {
@Override
- public void doAction() throws MojoExecutionException, MojoFailureException {
+ public void doAction() throws Exception {
+// public void doAction() throws MojoExecutionException, MojoFailureException {
getLog().info("Conversion of XMI files into ObjectModel");
super.doAction();
}
Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2StateModel.java
===================================================================
--- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2StateModel.java 2009-12-20 16:49:46 UTC (rev 780)
+++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Xmi2StateModel.java 2010-01-01 16:53:29 UTC (rev 781)
@@ -20,9 +20,6 @@
import java.io.File;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-
/**
* Converti les fichiers XMI en fichier StateModel
*
@@ -31,7 +28,8 @@
public class Xmi2StateModel extends Xmi2Model {
@Override
- public void doAction() throws MojoExecutionException, MojoFailureException {
+ public void doAction() throws Exception {
+// public void doAction() throws MojoExecutionException, MojoFailureException {
getLog().info("Conversion of XMI files into StateModel");
super.doAction();
}
Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Zargo2Xmi.java
===================================================================
--- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Zargo2Xmi.java 2009-12-20 16:49:46 UTC (rev 780)
+++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/Zargo2Xmi.java 2010-01-01 16:53:29 UTC (rev 781)
@@ -18,14 +18,11 @@
* ##%*/
package org.nuiton.eugene.plugin;
-import java.io.IOException;
-import java.io.File;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.nuiton.plugin.PluginIOContext;
import org.nuiton.plugin.PluginHelper;
+import org.nuiton.plugin.PluginIOContext;
+import java.io.File;
+
/**
* Extract zipped XMI files from zargo archive.
*
@@ -81,22 +78,23 @@
protected PluginIOContext zargoResources;
@Override
- public void doAction() throws MojoExecutionException, MojoFailureException {
+ public void doAction() throws Exception {
+// public void doAction() throws MojoExecutionException, MojoFailureException {
getLog().info("Extract zipped XMI files from zargo archive and copy resources");
getLog().info("Extract zipped XMI files");
- try {
+// try {
PluginHelper.expandFiles(zargoResources, ZARGO_FILE_FILTER, null, XMI_FILE_FILTER, overwrite);
- } catch (IOException ex) {
- throw new MojoExecutionException("could not expand files for reason " + ex.getMessage(), ex);
- }
+// } catch (IOException ex) {
+// throw new MojoExecutionException("could not expand files for reason " + ex.getMessage(), ex);
+// }
getLog().info("Copy resources");
- try {
+// try {
PluginHelper.copyFiles(zargoResources, null, ZARGO_FILE_FILTER, overwrite);
- } catch (IOException ex) {
- throw new MojoExecutionException("could not copy some files for reason " + ex.getMessage(), ex);
- }
+// } catch (IOException ex) {
+// throw new MojoExecutionException("could not copy some files for reason " + ex.getMessage(), ex);
+// }
}
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-12-20 16:49:46 UTC (rev 780)
+++ trunk/pom.xml 2010-01-01 16:53:29 UTC (rev 781)
@@ -9,7 +9,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom</artifactId>
- <version>1.1.3</version>
+ <version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>eugene</artifactId>
1
0
r780 - in trunk: . ant-eugene-task eugene maven-eugene-plugin
by tchemit@users.nuiton.org 20 Dec '09
by tchemit@users.nuiton.org 20 Dec '09
20 Dec '09
Author: tchemit
Date: 2009-12-20 17:49:46 +0100 (Sun, 20 Dec 2009)
New Revision: 780
Modified:
trunk/ant-eugene-task/pom.xml
trunk/eugene/pom.xml
trunk/maven-eugene-plugin/pom.xml
trunk/pom.xml
Log:
[maven-release-plugin] prepare for next development iteration
Modified: trunk/ant-eugene-task/pom.xml
===================================================================
--- trunk/ant-eugene-task/pom.xml 2009-12-20 16:49:41 UTC (rev 779)
+++ trunk/ant-eugene-task/pom.xml 2009-12-20 16:49:46 UTC (rev 780)
@@ -9,7 +9,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.0.0-beta-2</version>
+ <version>2.0.0-beta-3-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/eugene/pom.xml
===================================================================
--- trunk/eugene/pom.xml 2009-12-20 16:49:41 UTC (rev 779)
+++ trunk/eugene/pom.xml 2009-12-20 16:49:46 UTC (rev 780)
@@ -9,7 +9,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.0.0-beta-2</version>
+ <version>2.0.0-beta-3-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/maven-eugene-plugin/pom.xml
===================================================================
--- trunk/maven-eugene-plugin/pom.xml 2009-12-20 16:49:41 UTC (rev 779)
+++ trunk/maven-eugene-plugin/pom.xml 2009-12-20 16:49:46 UTC (rev 780)
@@ -9,7 +9,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.0.0-beta-2</version>
+ <version>2.0.0-beta-3-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-12-20 16:49:41 UTC (rev 779)
+++ trunk/pom.xml 2009-12-20 16:49:46 UTC (rev 780)
@@ -13,7 +13,7 @@
</parent>
<artifactId>eugene</artifactId>
- <version>2.0.0-beta-2</version>
+ <version>2.0.0-beta-3-SNAPSHOT</version>
<modules>
<module>eugene</module>
@@ -687,9 +687,9 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/eugene/tags/eugene-2.0.0-beta-2</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/eugene/tags/eugene-2.0.0-beta-2</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/eugene/tags/eugene-2.0.0-beta-2</url>
+ <connection>scm:svn:http://svn.nuiton.org/svn/eugene/trunk</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/eugene/trunk</developerConnection>
+ <url>http://www.nuiton.org/repositories/browse/eugene/trunk</url>
</scm>
</project>
1
0
Author: tchemit
Date: 2009-12-20 17:49:41 +0100 (Sun, 20 Dec 2009)
New Revision: 779
Added:
tags/eugene-2.0.0-beta-2/
Log:
[maven-scm] copy for tag eugene-2.0.0-beta-2
Property changes on: tags/eugene-2.0.0-beta-2
___________________________________________________________________
Added: svn:ignore
+ target
.settings
bin
.classpath
.project
*.iml
*.ipr
*.iws
Added: svn:mergeinfo
+ /branches/1.0.1-Javabuilder:641-651
/branches/1.1.0-Javabuilder:652-681
/branches/eugene-2.0:682-754
1
0
r778 - in trunk: . ant-eugene-task eugene maven-eugene-plugin
by tchemit@users.nuiton.org 20 Dec '09
by tchemit@users.nuiton.org 20 Dec '09
20 Dec '09
Author: tchemit
Date: 2009-12-20 17:49:37 +0100 (Sun, 20 Dec 2009)
New Revision: 778
Modified:
trunk/ant-eugene-task/pom.xml
trunk/eugene/pom.xml
trunk/maven-eugene-plugin/pom.xml
trunk/pom.xml
Log:
[maven-release-plugin] prepare release eugene-2.0.0-beta-2
Modified: trunk/ant-eugene-task/pom.xml
===================================================================
--- trunk/ant-eugene-task/pom.xml 2009-12-20 16:27:20 UTC (rev 777)
+++ trunk/ant-eugene-task/pom.xml 2009-12-20 16:49:37 UTC (rev 778)
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -10,7 +9,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.0.0-beta-2-SNAPSHOT</version>
+ <version>2.0.0-beta-2</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/eugene/pom.xml
===================================================================
--- trunk/eugene/pom.xml 2009-12-20 16:27:20 UTC (rev 777)
+++ trunk/eugene/pom.xml 2009-12-20 16:49:37 UTC (rev 778)
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -10,7 +9,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.0.0-beta-2-SNAPSHOT</version>
+ <version>2.0.0-beta-2</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/maven-eugene-plugin/pom.xml
===================================================================
--- trunk/maven-eugene-plugin/pom.xml 2009-12-20 16:27:20 UTC (rev 777)
+++ trunk/maven-eugene-plugin/pom.xml 2009-12-20 16:49:37 UTC (rev 778)
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -10,7 +9,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.0.0-beta-2-SNAPSHOT</version>
+ <version>2.0.0-beta-2</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-12-20 16:27:20 UTC (rev 777)
+++ trunk/pom.xml 2009-12-20 16:49:37 UTC (rev 778)
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -14,7 +13,7 @@
</parent>
<artifactId>eugene</artifactId>
- <version>2.0.0-beta-2-SNAPSHOT</version>
+ <version>2.0.0-beta-2</version>
<modules>
<module>eugene</module>
@@ -688,9 +687,9 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/eugene/trunk</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/eugene/trunk</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/eugene/trunk</url>
+ <connection>scm:svn:http://svn.nuiton.org/svn/eugene/tags/eugene-2.0.0-beta-2</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/eugene/tags/eugene-2.0.0-beta-2</developerConnection>
+ <url>http://www.nuiton.org/repositories/browse/eugene/tags/eugene-2.0.0-beta-2</url>
</scm>
</project>
1
0
Author: tchemit
Date: 2009-12-20 17:27:20 +0100 (Sun, 20 Dec 2009)
New Revision: 777
Added:
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelBuilder.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelGenerator.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelTransformer.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelType.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelGenerator.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelReader.java
trunk/eugene/src/test/java/org/nuiton/eugene/models/object/ModelMergeTest.java
trunk/eugene/src/test/java/org/nuiton/eugene/models/object/ObjectModelGeneratorTest.java
trunk/eugene/src/test/java/org/nuiton/eugene/models/object/XMI12ToObjectModelTest.java
trunk/eugene/src/test/java/org/nuiton/eugene/models/object/XMI21ToObjectModelTest.java
Removed:
trunk/eugene/src/main/assembly/
trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java
trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelTransformer.java
trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelType.java
trunk/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java
trunk/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelBuilder.java
trunk/eugene/src/test/java/org/nuiton/eugene/ModelFileWriterUtilTest.java
trunk/eugene/src/test/java/org/nuiton/eugene/ObjectModelGeneratorTest.java
trunk/eugene/src/test/java/org/nuiton/eugene/models/ui/
trunk/eugene/src/test/java/org/nuiton/eugene/models/xml/
trunk/eugene/src/test/java/org/nuiton/eugene/xmi/
trunk/maven-eugene-plugin/src/it/smart-generate/generators/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java
Modified:
trunk/ant-eugene-task/src/test/java/org/nuiton/eugene/GeneratorTaskTest.java
trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaBuilder.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGenerator.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelAttributeImpl.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelEnumerationImpl.java
trunk/eugene/src/site/fr/rst/index.rst
trunk/eugene/src/test/java/org/nuiton/eugene/models/object/xml/ObjectModelBuilderTest.java
trunk/eugene/src/test/java/org/nuiton/eugene/models/state/StateModelTest.java
trunk/maven-eugene-plugin/src/it/smart-generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java
trunk/maven-eugene-plugin/src/it/smart-generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java
Log:
- clean api : everything which is not neutral can not be under org.nuiton.eugene package (go to models.object or models.state)
- clean tests and improve a first one (ModelMergeTest)
- remove unucessary assembly descriptors (use the one from maven-helper-plugin)
Modified: trunk/ant-eugene-task/src/test/java/org/nuiton/eugene/GeneratorTaskTest.java
===================================================================
--- trunk/ant-eugene-task/src/test/java/org/nuiton/eugene/GeneratorTaskTest.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/ant-eugene-task/src/test/java/org/nuiton/eugene/GeneratorTaskTest.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -27,6 +27,7 @@
import org.apache.tools.ant.Project;
import org.junit.Assert;
import org.junit.Test;
+import org.nuiton.eugene.models.object.ObjectModelGenerator;
import org.nuiton.util.FileUtil;
import org.nuiton.util.ResourceResolver;
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -8,7 +8,7 @@
import java.util.List;
/**
- * Abstract meta transformer which contains some templates to apply to incoming model.
+ * Abstract meta transformer which contains some templates to apply to an incoming model.
*
* Using the {@link #getExcludeTemplates()} to restrict use of some templates.
*
@@ -78,6 +78,9 @@
if (generator instanceof Transformer) {
generator.setProperties(properties);
}
+
+ // will use it
+ result.add(generator);
} catch (Exception e) {
// should never happens
if (log.isErrorEnabled()) {
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -1,346 +0,0 @@
-/* *##%
- * EUGene :: 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.Collection;
-
-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.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;
-
-/**
- * Pour utiliser ce type de générateur il faut implanter au moins une des trois
- * méthodes generateFrom... et le getFilenameFor... associé si l'on souhaite un
- * nom de fichier convenable. Si dans une méthode generateFrom... on utilise pas
- * le Writer alors aucun fichier n'est généré.
- *
- * <pre>
- * public String getFilenameForClass(ObjectModelClass clazz){
- * return super.getFilenameForClass(Clazz) + "Service.java";
- * }
- *
- * public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException{
- * if(clazz.getType().equals("service")){
- * / *{
- * public class .... {
- *
- * }
- * }* /
- * }
- * }
- * </pre>
- *
- * Le nom de l'argument writer doit absolument etre output et pas autre chose si
- * vous souhaitez utiliser le processeur
- * org.codelutin.processor.filters.GeneratorTemplatesFilter pour vous
- * s'implifier l'écriture des templates.
- *
- * Created: 14 mars 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com> Copyright Code Lutin
- *
- * @version $Revision$
- *
- * Mise a jour: $Date$ par : $Author$
- */
-public class ObjectModelGenerator extends AbstractGenerator<ObjectModel> {
-
- /** Logger for this class. */
- private static Log log = LogFactory.getLog(ObjectModelGenerator.class);
-
- public ObjectModelGenerator() {
- super();
- }
-
- public ObjectModelGenerator(AbstractGenerator<ObjectModel> parent) {
- super(parent);
- }
-
- @Override
- @Deprecated
- public void generate(File[] files, File destDir) {
- ObjectModelReader reader = new ObjectModelReader();
- ObjectModel objectModel = reader.read(files);
- setLastModifiedSource(reader.getLastModifiedSource());
- try {
- applyTemplate(objectModel, destDir);
- } catch (IOException eee) {
- if (log.isWarnEnabled()) {
- log.warn("Unable to generate for file", eee);
- }
- }
- }
-
- /**
- * Par defaut la methode appelle la methode
- * {@link #generateFromModel(Writer, ObjectModel)} puis boucle sur chaque
- * class en appelant la m?thode
- * {@link #generateFromClass(Writer, ObjectModelClass)} puis boucle sur chaque
- * interface en appelant a méthode
- * {@link #generateFromInterface(Writer, ObjectModelInterface)} et enfin sur chaque
- * énumération en appelant la méthode
- * {@link #generateFromEnumeration(Writer, ObjectModelEnumeration)}
- * Le nom de fichier est récupérer pour chacun d'eux en appelant la méthode
- * getFilenameFor.... La methode generateFrom... n'utilise pas le Writer
- * alors le fichier n'est pas généré, si on l'utilise m?me pour ne rien
- * écrire alors le fichier sera généré.
- * @param model le modele memoire a utiliser
- * @param destDir le repertoire ou generer
- * @throws IOException pour tout pb
- */
- @Override
- public void applyTemplate(ObjectModel model, File destDir) throws IOException {
-
- // generateFromModel
- this.model = model;
-
- String filename = getFilenameForModel(model);
-
- // generateFromModel
- generateFromElement(model, destDir, filename, ObjectModelType.OBJECT_MODEL);
-
- // generateFromClassifier
- generateFromElements(model.getClassifiers(), destDir, ObjectModelType.OBJECT_MODEL_CLASSIFIER);
-
- // generateFromInterface
- generateFromElements(model.getInterfaces(), destDir, ObjectModelType.OBJECT_MODEL_INTERFACE);
-
- // generateFromClass
- generateFromElements(model.getClasses(), destDir, ObjectModelType.OBJECT_MODEL_CLASS);
-
- // generateFromEnumeration
- generateFromElements(model.getEnumerations(), destDir, ObjectModelType.OBJECT_MODEL_ENUMERATION);
-
- }
-
- /**
- * Parcours une collection d'éléments pour la génération suivant un type d'éléments.
- * Types possibles : ObjectModelClassifier, ObjectModelClass, ObjectModelInterface et
- * ObjectModelEnumeration.
- * Deux méthodes dépendent du type et peuvent être surchargées :
- * getFilenameForXXX et generateFromXXX (XXX étant un type prédéfini pour une méthode existante).
- *
- * @see ObjectModelType
- *
- * @param elements Collection d'éléments d'un des types ci-dessus
- * @param destDir dossier de destination pour le fichier généré
- * @param type type explicite d'ObjectModel
- */
- private void generateFromElements(Collection<? extends ObjectModelElement> elements, File destDir,
- ObjectModelType type) {
-
- for (ObjectModelElement element : elements) {
- String filename = "";
- // Filename depends on type of element (Classifier, Class, Interface or Enumeration)
- switch (type) {
- case OBJECT_MODEL_CLASSIFIER:
- filename = getFilenameForClassifier((ObjectModelClassifier)element);
- break;
- case OBJECT_MODEL_INTERFACE:
- filename = getFilenameForInterface((ObjectModelInterface)element);
- break;
- case OBJECT_MODEL_CLASS:
- filename = getFilenameForClass((ObjectModelClass)element);
- break;
- case OBJECT_MODEL_ENUMERATION:
- filename = getFilenameForEnumeration((ObjectModelEnumeration)element);
- }
-
- generateFromElement(element, destDir, filename, type);
- }
- }
-
- /**
- * Génération pour un élément du modèle (ou le modèle lui-même).
- * Types possibles : ObjectModel, ObjectModelClassifier, ObjectModelClass,
- * ObjectModelInterface et ObjectModelEnumeration.
- * La méthode generateFromXXX dépend du type d'élément et peut être surchargée.
- *
- * @see ObjectModelType
- *
- * @param element element à généré
- * @param destDir dossier de destination
- * @param filename nom du fichier de sortie
- * @param type type d'ObjectModel
- */
- protected void generateFromElement(Object element, File destDir, String filename,
- ObjectModelType type) {
-
- // on a maintenant une restriction des elements a generer
- // c'est à dire un filtrage par package
- // effectue un appel pour savoir si on a le droit de generer l'element
- // courant
- if (canGenerateElement(element)) {
-
- File outputFile = getDestinationFile(destDir, filename);
- if (!getOverwrite() && isNewerThanSource(outputFile)) {
- if (log.isTraceEnabled()) {
- log.trace("file " + outputFile + " is up-to-date");
- }
- return;
- }
- if (!outputFile.exists() && log.isTraceEnabled()) {
- log.trace("not up-to-date " + outputFile.lastModified()
- + " <" + outputFile + ">");
- }
- try {
- StringWriter out = new StringWriter();
- MonitorWriter monitorOut = new MonitorWriter(out);
-
- switch (type) {
- case OBJECT_MODEL:
- generateFromModel(monitorOut,(ObjectModel)element);
- break;
- case OBJECT_MODEL_CLASSIFIER:
- generateFromClassifier(monitorOut, (ObjectModelClassifier)element);
- break;
- case OBJECT_MODEL_INTERFACE:
- generateFromInterface(monitorOut, (ObjectModelInterface)element);
- break;
- case OBJECT_MODEL_CLASS:
- generateFromClass(monitorOut, (ObjectModelClass)element);
- break;
- case OBJECT_MODEL_ENUMERATION:
- generateFromEnumeration(monitorOut, (ObjectModelEnumeration)element);
- break;
- }
-
- write(outputFile, monitorOut);
- } catch (Exception eee) {
- log.warn("Erreur lors de la génération du fichier "
- + outputFile);
- throw new RuntimeException(
- "Erreur lors de la génération du fichier "
- + outputFile, eee);
- }
- }
- }
-
- /**
- * Test if given element can be generated.
- *
- * An element can be generated if his package is in the {@link #generatedPackages} list
- * or if {@link #generatedPackages} is null or empty.
- *
- * @param element element to test
- * @return generation allowed
- */
- protected boolean canGenerateElement(Object element) {
-
- boolean canGenerate = true;
-
- // can get package only for Classifiers
- if (element instanceof ObjectModelClassifier) {
- ObjectModelClassifier classifier = (ObjectModelClassifier)element;
- String classifierPackage = classifier.getPackageName();
-
- canGenerate = super.canGeneratePackage(classifierPackage);
- }
-
- return canGenerate;
- }
-
- /**
- * Par defaut cette methode retourne le getName du model. Si l'on souhaite
- * utiliser la methode generateFromModel il vaut mieux surcharger cette
- * methode
- * @param model le modele utilise
- * @return le nom du fichier a generer
- */
- public String getFilenameForModel(ObjectModel model) {
- // TODO throw exception when model.getName() == null or empty
- return model.getName();
- }
-
- /**
- * Par defaut cette methode retourne le QualifiedName convertie en chemin
- * par exemple pour org.codelutin.Toto on aurait org/codelutin/Toto
- * @param model le modele utilise
- * @param packageName le nom du paquetage
- * @return le repertoire correspondant au paquetage
- */
- public String getFilenameForPackage(ObjectModel model, String packageName) {
- return packageName.replace('.', File.separatorChar);
- }
-
- /**
- * Par defaut cette methode retourne le QualifiedName convertie en chemin
- * par exemple pour org.codelutin.Toto on aurait org/codelutin/Toto
- * @param interfacez l'interface utilisee
- * @return le nom du l'interface a generer
- */
- public String getFilenameForInterface(ObjectModelInterface interfacez) {
- return getFilenameForClassifier(interfacez);
-// return interfacez.getQualifiedName().replace('.', File.separatorChar);
- }
-
- /**
- * Par defaut cette methode retourne le QualifiedName convertie en chemin
- * par exemple pour org.codelutin.Toto on aurait org/codelutin/Toto
- * @param clazz la classe utilisee
- * @return le nom de la classe a generer
- */
- public String getFilenameForClass(ObjectModelClass clazz) {
- return getFilenameForClassifier(clazz);
-// return clazz.getQualifiedName().replace('.', File.separatorChar);
- }
-
- /**
- * Par defaut cette methode retourne le QualifiedName convertie en chemin
- * par exemple pour org.codelutin.Toto on aurait org/codelutin/Toto
- * @param classifier le classifier utilisee
- * @return le nom du classifier a generer
- */
- public String getFilenameForClassifier(ObjectModelClassifier classifier) {
- return classifier.getQualifiedName().replace('.', File.separatorChar);
- }
-
- public String getFilenameForEnumeration(ObjectModelEnumeration enumeration) {
- return getFilenameForClassifier(enumeration);
-// return enumeration.getQualifiedName().replace('.', File.separatorChar);
- }
-
- public void generateFromModel(Writer output, ObjectModel model) throws IOException {
- }
-
- public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException {
- }
-
- public void generateFromEnum(Writer output, ObjectModelEnumeration interfacez) throws IOException {
- }
-
- public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
- }
-
- public void generateFromClassifier(Writer output, ObjectModelClassifier clazz) throws IOException {
- }
-
- public void generateFromEnumeration(Writer output, ObjectModelEnumeration enumeration) throws IOException {
- }
-}
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -1,244 +0,0 @@
-/*
- * *##%
- * EUGene :: 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.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.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;
-
-/**
- * To read object model files into an memory object model.
- *
- * Created: 26 oct. 2009
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- *
- * @plexus.component role="org.nuiton.eugene.ModelReader" role-hint="objectmodel"
- */
-public class ObjectModelReader extends ModelReader<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
- */
- @Override
- public ObjectModel read(File[] files) {
- 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);
- }
- }*/
- }
-}
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelTransformer.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelTransformer.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelTransformer.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -1,148 +0,0 @@
-/*
- * *##%
- * EUGene :: 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.Model;
-import org.nuiton.eugene.models.object.*;
-
-import java.util.Collection;
-
-/**
- * ObjectModelTransformer
- * <p/>
- * Created: 28 oct. 2009
- *
- *
- * L'initialisation du modèle de sortie et du générateur de sortie associée,
- * se fait dans la superclass grâce à la méthode init.
- *
- * @author fdesbois
- * @version $Revision$
- * <p/>
- * Mise a jour: $Date$
- * par : $Author$
- * @param <O>
- */
-public abstract class ObjectModelTransformer<O extends Model> extends Transformer<ObjectModel, O> {
-
- /**
- * Le model associé au transformer est le model d'entree. Le modele de sortie
- * peut etre initialiser via la methode {@link org.nuiton.eugene.Transformer#initOutputModel()}.
- * Il est également possible de surcharger la methode {@link #debugOutputModel()}
- * pour verifier le resultat de la transformation.
- * Par defaut la methode appelle la methode
- * {@link #transformFromModel(ObjectModel)} puis boucle sur chaque
- * class en appelant la methode
- * {@link #transformFromClass(ObjectModelClass)} puis boucle sur chaque
- * interface en appelant a methode
- * {@link #transformFromInterface(ObjectModelInterface)} et enfin sur chaque
- * enumeration en appelant la methode
- * {@link #transformFromEnumeration(ObjectModelEnumeration)}
- */
- @Override
- public void transform() {
-
- // transformFromModel
- transformFromElement(getModel(), ObjectModelType.OBJECT_MODEL);
-
- // transformFromClassifier
- transformFromElements(getModel().getClassifiers(), ObjectModelType.OBJECT_MODEL_CLASSIFIER);
-
- // transformFromInterface
- transformFromElements(getModel().getInterfaces(), ObjectModelType.OBJECT_MODEL_INTERFACE);
-
- // transformFromClass
- transformFromElements(getModel().getClasses(), ObjectModelType.OBJECT_MODEL_CLASS);
-
- // transformFromEnumeration
- transformFromElements(getModel().getEnumerations(), ObjectModelType.OBJECT_MODEL_ENUMERATION);
-
- debugOutputModel();
- }
-
- protected abstract void debugOutputModel();
-
- /**
- * Parcours une collection d'éléments pour la transformation suivant un type d'éléments.
- * Types possibles : ObjectModelClassifier, ObjectModelClass, ObjectModelInterface et
- * ObjectModelEnumeration.
- * Une méthode dépend du type et peut être surchargée :
- * transformFromXXX (XXX étant un type prédéfini pour une méthode existante).
- *
- * @param elements Collection d'éléments d'un des types ci-dessus
- * @param type type explicite d'ObjectModel
- * @see ObjectModelType
- */
- private void transformFromElements(Collection<? extends ObjectModelElement> elements,
- ObjectModelType type) {
-
- for (ObjectModelElement element : elements) {
- transformFromElement(element, type);
- }
- }
-
- /**
- * Génération pour un élément du modèle (ou le modèle lui-même).
- * Types possibles : ObjectModel, ObjectModelClassifier, ObjectModelClass,
- * ObjectModelInterface et ObjectModelEnumeration.
- * La méthode transformFromXXX dépend du type d'élément et peut être surchargée.
- *
- * @param element element à généré
- * @param type type d'ObjectModel
- * @see ObjectModelType
- */
- protected void transformFromElement(Object element, ObjectModelType type) {
-
- switch (type) {
- case OBJECT_MODEL:
- transformFromModel((ObjectModel) element);
- break;
- case OBJECT_MODEL_CLASSIFIER:
- transformFromClassifier((ObjectModelClassifier) element);
- break;
- case OBJECT_MODEL_INTERFACE:
- transformFromInterface((ObjectModelInterface) element);
- break;
- case OBJECT_MODEL_CLASS:
- transformFromClass((ObjectModelClass) element);
- break;
- case OBJECT_MODEL_ENUMERATION:
- transformFromEnumeration((ObjectModelEnumeration) element);
- break;
- }
- }
-
- public void transformFromModel(ObjectModel model) {
- }
-
- public void transformFromInterface(ObjectModelInterface interfacez) {
- }
-
- public void transformFromClass(ObjectModelClass clazz) {
- }
-
- public void transformFromClassifier(ObjectModelClassifier clazz) {
- }
-
- public void transformFromEnumeration(ObjectModelEnumeration enumeration) {
- }
-
-}
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelType.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelType.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelType.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -1,54 +0,0 @@
-/* *##%
- * EUGene :: 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;
-
-/**
- * Enumeration for ObjectModelGenerator.
- * Contains all types available for generating specific ObjectModelElement file.
- * Needed because of inheritance between class, interface and classifier.
- * Method instanceof (previously used) is inadequat so expliciting the ObjectModel type is much better.
- * <p/>
- * Created: may 4th 2009
- *
- * @author Florian DESBOIS <fdesbois(a)codelutin.com>
- * @version $Revision: 496 $
- */
-public enum ObjectModelType {
- /**
- * a model
- */
- OBJECT_MODEL,
- /**
- * an enumration
- */
- OBJECT_MODEL_ENUMERATION,
- /**
- * a generic classifier
- */
- OBJECT_MODEL_CLASSIFIER,
- /**
- * a class
- */
- OBJECT_MODEL_CLASS,
- /**
- * an interface
- */
- OBJECT_MODEL_INTERFACE
-}
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -1,214 +0,0 @@
-/* *##%
- * EUGene :: 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.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.models.state.StateModel;
-import org.nuiton.eugene.models.state.StateModelState;
-import org.nuiton.eugene.models.state.StateModelStateChart;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-
-/**
- * StateModelGenerator.
- * <p/>
- * Pour utiliser ce type de générateur, il faut implanter au moins une des
- * méthodes generateFrom... et le getFilenameFor... associé si l'on souhaite un
- * nom de fichier convenable. Si dans une méthode generateFrom... on utilise pas
- * le writer (output) alors aucun fichier n'est généré.
- * <p/>
- * Le nom de l'argument writer doit absolument etre output et pas autre chose si
- * vous souhaitez utiliser le processeur
- * {@code org.nuiton.processor.filters.GeneratorTemplatesFilter} pour vous
- * s'implifier l'écriture des templates.
- *
- * @author chatellier
- * @version $Revision$
- * <p/>
- * Last update : $Date$ By : $Author$
- */
-public class StateModelGenerator extends AbstractGenerator<StateModel> {
-
- /**
- * Logger for this class
- */
- private static Log log = LogFactory.getLog(StateModelGenerator.class);
-
- /**
- * Empty constructor
- */
- public StateModelGenerator() {
- super();
- }
-
- /**
- * Constructor with parent generator.
- *
- * @param parent parent generator
- */
- public StateModelGenerator(AbstractGenerator<StateModel> parent) {
- super(parent);
- }
-
- /*
- * @see org.nuiton.eugene.Generator#generate(java.io.File[], java.io.File)
- */
- @Override
- @Deprecated
- public void generate(File[] files, File destDir) {
-
- StateModelReader reader = new StateModelReader();
- StateModel stateModel = reader.read(files);
- setLastModifiedSource(reader.getLastModifiedSource());
-
- // generate code
- try {
- applyTemplate(stateModel, destDir);
- } catch (IOException e) {
- log.warn("Can't generate code for files", e);
- }
- }
-
-
- /**
- * Par défaut, appel {@link #generateFromModel(MonitorWriter, org.nuiton.eugene.models.state.StateModel)} pour le
- * model et {@link #generateFromState(Writer,StateModelState)} pour tous les
- * etats du modele.
- *
- * @param stateModel Le modele d'état
- * @param destDir le dossier de destination
- * @throws IOException
- */
- @Override
- public void applyTemplate(StateModel stateModel, File destDir) throws IOException {
-
- model = stateModel;
-
- String filename = getFilenameFromModel(stateModel);
- File outputFile = getDestinationFile(destDir, filename);
- if (getOverwrite() || !isNewerThanSource(outputFile)) {
- try {
- StringWriter out = new StringWriter();
- MonitorWriter monitorOut = new MonitorWriter(out);
- generateFromModel(monitorOut, stateModel);
- write(outputFile, monitorOut);
- } catch (Exception eee) {
- log.warn("Erreur lors de la génération du fichier "
- + outputFile);
- throw new RuntimeException(
- "Erreur lors de la génération du fichier " + outputFile,
- eee);
- }
- }
-
- // pour tous les diagrammes du modele
- for (StateModelStateChart chart : stateModel.getStateCharts()) {
-
- // elements can be restricted in package
- if (canGenerateElement(chart)) {
-
- // et tous les états de ces diagrammes
- for (Object oState : chart.getStates().toArray()) {
- StateModelState state = (StateModelState) oState;
- String filenameState = getFilenameFromState(state, chart
- .getName());
- File outputFiletate = getDestinationFile(destDir, filenameState);
- if (getOverwrite() || !isNewerThanSource(outputFiletate)) {
- try {
- StringWriter out = new StringWriter();
- MonitorWriter monitorOut = new MonitorWriter(out);
- generateFromState(monitorOut, state);
- write(outputFiletate, monitorOut);
- } catch (Exception eee) {
- log.warn("Erreur lors de la génération du fichier "
- + outputFiletate);
- throw new RuntimeException(
- "Erreur lors de la génération du fichier "
- + outputFiletate, eee);
- }
- }
- }
- }
- }
- }
-
- /**
- * Test if given element can be generated.
- *
- * @param chart chart to test
- * @return generation allowed
- */
- protected boolean canGenerateElement(StateModelStateChart chart) {
-
- boolean canGenerate = true;
-
- // disabled until tested
- //String chartPackage = chart.getPackageName();
- //canGenerate = super.canGeneratePackage(chartPackage);
-
- return canGenerate;
- }
-
- /**
- * Generate model code
- *
- * @param monitorOut
- * @param stateModel
- */
- protected void generateFromModel(MonitorWriter monitorOut, StateModel stateModel) {
-
- }
-
- /**
- * Return filename from model
- *
- * @param stateModel
- * @return model file name
- */
- protected String getFilenameFromModel(StateModel stateModel) {
- return stateModel.getName();
- }
-
- /**
- * Return filename from state
- *
- * @param state the state
- * @param packageName
- * @return the filename
- */
- public String getFilenameFromState(StateModelState state, String packageName) {
- return (packageName + '.' + state.getName()).replace('.', File.separatorChar);
- }
-
- /**
- * Generate a state code
- *
- * @param monitorOut the output writer
- * @param state the state
- * @throws IOException
- */
- public void generateFromState(Writer monitorOut, StateModelState state) throws IOException {
-
- }
-}
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -1,124 +0,0 @@
-/*
- * *##%
- * EUGene :: 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.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;
-
-/**
- * To read state model files into a memory state model.
- *
- * Created: 26 oct. 2009
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- *
- * @plexus.component role="org.nuiton.eugene.ModelReader" role-hint="statemodel"
- */
-public class StateModelReader extends ModelReader<StateModel> {
-
- private static final Log log = LogFactory.getLog(StateModelReader.class);
-
- @Override
- public StateModel read(File[] files) {
- 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);
- }
- }
- }
- }
-}
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaBuilder.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaBuilder.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaBuilder.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -28,7 +28,7 @@
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.GeneratorUtil;
import org.nuiton.eugene.ImportsManager;
-import org.nuiton.eugene.ObjectModelType;
+import org.nuiton.eugene.models.object.ObjectModelType;
import org.nuiton.eugene.models.object.*;
import org.nuiton.eugene.models.object.ObjectModelModifier;
import org.nuiton.eugene.models.object.xml.*;
@@ -148,7 +148,7 @@
* @param name
* @param packageName package's name of the class to create
* @return a new ObjectModelClass
- * @see org.nuiton.eugene.models.object.xml.ObjectModelBuilder#createClass(java.lang.String, java.lang.String,org.nuiton.eugene.models.object.ObjectModelModifier...)
+ * @see org.nuiton.eugene.models.object.ObjectModelBuilder#createClass(java.lang.String, java.lang.String,org.nuiton.eugene.models.object.ObjectModelModifier...)
*/
public ObjectModelClass createClass(String name, String packageName) {
return modelBuilder.createClass(name, packageName);
@@ -160,7 +160,7 @@
* @param name
* @param packageName package's name of the class to create
* @return a new ObjectModelClass
- * @see org.nuiton.eugene.models.object.xml.ObjectModelBuilder#createClass(java.lang.String,java.lang.String, org.nuiton.eugene.models.object.ObjectModelModifier...)
+ * @see org.nuiton.eugene.models.object.ObjectModelBuilder#createClass(java.lang.String,java.lang.String, org.nuiton.eugene.models.object.ObjectModelModifier...)
*/
public ObjectModelClass createAbstractClass(String name, String packageName) {
return modelBuilder.createClass(name, packageName, ObjectModelModifier.ABSTRACT);
@@ -172,7 +172,7 @@
* @param name
* @param packageName package's name of the interface to create
* @return a new ObjectModelInterface
- * @see org.nuiton.eugene.models.object.xml.ObjectModelBuilder#createInterface(java.lang.String, java.lang.String)
+ * @see org.nuiton.eugene.models.object.ObjectModelBuilder#createInterface(java.lang.String, java.lang.String)
*/
public ObjectModelInterface createInterface(String name, String packageName) {
return modelBuilder.createInterface(name, packageName);
@@ -195,7 +195,7 @@
*
* @param classifier
* @param superclassQualifiedName
- * @see org.nuiton.eugene.models.object.xml.ObjectModelBuilder#addInterface(
+ * @see org.nuiton.eugene.models.object.ObjectModelBuilder#addInterface(
*org.nuiton.eugene.models.object.ObjectModelClassifier, java.lang.String)
*/
public void setSuperClass(ObjectModelClass classifier, String superclassQualifiedName) {
@@ -211,7 +211,7 @@
*
* @param classifier
* @param interfaceQualifiedName
- * @see org.nuiton.eugene.models.object.xml.ObjectModelBuilder#addInterface(
+ * @see org.nuiton.eugene.models.object.ObjectModelBuilder#addInterface(
*org.nuiton.eugene.models.object.ObjectModelClassifier, java.lang.String)
*/
public void addInterface(ObjectModelClassifier classifier, String interfaceQualifiedName) {
@@ -229,7 +229,7 @@
* @param value
* @param modifiers
* @return a new ObjectModelAttribute
- * @see org.nuiton.eugene.models.object.xml.ObjectModelBuilder#addAttribute(org.nuiton.eugene.models.object.ObjectModelClassifier, java.lang.String,java.lang.String, java.lang.String, org.nuiton.eugene.models.object.ObjectModelModifier...)
+ * @see org.nuiton.eugene.models.object.ObjectModelBuilder#addAttribute(org.nuiton.eugene.models.object.ObjectModelClassifier, java.lang.String,java.lang.String, java.lang.String, org.nuiton.eugene.models.object.ObjectModelModifier...)
*/
public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, String name, String type, String value,
ObjectModelModifier... modifiers) {
@@ -314,7 +314,7 @@
* @param type
* @param modifiers
* @return a new ObjectModelOperation
- * @see org.nuiton.eugene.models.object.xml.ObjectModelBuilder#addOperation(org.nuiton.eugene.models.object.ObjectModelClassifier, java.lang.String,java.lang.String, org.nuiton.eugene.models.object.ObjectModelModifier...)
+ * @see org.nuiton.eugene.models.object.ObjectModelBuilder#addOperation(org.nuiton.eugene.models.object.ObjectModelClassifier, java.lang.String,java.lang.String, org.nuiton.eugene.models.object.ObjectModelModifier...)
*/
public ObjectModelOperation addOperation(ObjectModelClassifier classifier, String name, String type,
ObjectModelModifier... modifiers) {
@@ -328,7 +328,7 @@
* @param classifier
* @param modifiers
* @return a new ObjectModelOperation
- * @see org.nuiton.eugene.models.object.xml.ObjectModelBuilder#addOperation(org.nuiton.eugene.models.object.ObjectModelClassifier, java.lang.String,java.lang.String, org.nuiton.eugene.models.object.ObjectModelModifier...)
+ * @see org.nuiton.eugene.models.object.ObjectModelBuilder#addOperation(org.nuiton.eugene.models.object.ObjectModelClassifier, java.lang.String,java.lang.String, org.nuiton.eugene.models.object.ObjectModelModifier...)
*/
public ObjectModelOperation addBlock(ObjectModelClassifier classifier,
ObjectModelModifier... modifiers) {
@@ -364,7 +364,7 @@
* @param type
* @param name
* @return a new ObjectModelParameter
- * @see org.nuiton.eugene.models.object.xml.ObjectModelBuilder#addParameter(
+ * @see org.nuiton.eugene.models.object.ObjectModelBuilder#addParameter(
*org.nuiton.eugene.models.object.ObjectModelOperation, java.lang.String, java.lang.String)
*/
public ObjectModelParameter addParameter(ObjectModelOperation operation, String type, String name) {
@@ -377,7 +377,7 @@
*
* @param operation
* @param exception
- * @see org.nuiton.eugene.models.object.xml.ObjectModelBuilder#addException(
+ * @see org.nuiton.eugene.models.object.ObjectModelBuilder#addException(
*org.nuiton.eugene.models.object.ObjectModelOperation, java.lang.String)
*/
public void addException(ObjectModelOperation operation, String exception) {
@@ -391,7 +391,7 @@
* @param operation
* @param body
* @throws IllegalArgumentException if operation is abstract
- * @see org.nuiton.eugene.models.object.xml.ObjectModelBuilder#setOperationBody(
+ * @see org.nuiton.eugene.models.object.ObjectModelBuilder#setOperationBody(
*org.nuiton.eugene.models.object.ObjectModelOperation, java.lang.String)
*/
public void setOperationBody(ObjectModelOperation operation, String body)
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGenerator.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGenerator.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGenerator.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -31,7 +31,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.GeneratorUtil;
-import org.nuiton.eugene.ObjectModelGenerator;
+import org.nuiton.eugene.models.object.ObjectModelGenerator;
import org.nuiton.eugene.models.object.*;
/**
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -22,10 +22,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.ObjectModelType;
+import org.nuiton.eugene.models.object.ObjectModelType;
import org.nuiton.eugene.Template;
import org.nuiton.eugene.ImportsManager;
-import org.nuiton.eugene.ObjectModelTransformer;
+import org.nuiton.eugene.models.object.ObjectModelTransformer;
import org.nuiton.eugene.models.object.*;
/**
@@ -42,11 +42,14 @@
public abstract class ObjectModelTransformerToJava extends ObjectModelTransformer<ObjectModel> {
private static final Log log = LogFactory.getLog(ObjectModelTransformerToJava.class);
-
+ /**
+ * internal builder
+ */
protected JavaBuilder builder;
@Override
protected Template<ObjectModel> initOutputTemplate() {
+ // by default, use a stupid java generator
return new JavaGenerator();
}
Copied: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelBuilder.java (from rev 776, trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelBuilder.java)
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelBuilder.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelBuilder.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -0,0 +1,544 @@
+/*
+ * *##%
+ * EUGene :: 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.object;
+
+import org.nuiton.eugene.models.object.xml.*;
+
+/**
+ * ObjectModelBuilder
+ * <p/>
+ * Created: 3 nov. 2009
+ *
+ * @author fdesbois
+ * @version $Revision$
+ * <p/>
+ * Builder to fill an empty ObjectModel. The object model name is important if you want to use the model
+ * in generators.
+ * <p/>
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class ObjectModelBuilder {
+
+ protected ObjectModelImpl model;
+
+ /**
+ * Constructor. Must have a name for the new model created.
+ *
+ * @param name model name
+ */
+ public ObjectModelBuilder(String name) {
+ this.model = new ObjectModelImpl();
+ this.model.setName(name);
+ }
+
+ /**
+ * Get the building model
+ *
+ * @return the ObjectModel which is currently built
+ */
+ public ObjectModel getModel() {
+ return this.model;
+ }
+
+ /**
+ * Add a tagValue to the model.
+ *
+ * @param name tagValue name
+ * @param value tagValue value
+ */
+ public void addTagValue(String name, String value) {
+ ObjectModelImplTagValue tagValue = new ObjectModelImplTagValue();
+ tagValue.setName(name);
+ tagValue.setValue(value);
+ model.addTagValue(tagValue);
+ }
+
+ /**
+ * Add a tagValue to an element
+ *
+ * @param element where the tag value will be added
+ * @param name tagValue name
+ * @param value tagValue value
+ */
+ public void addTagValue(ObjectModelElement element, String name, String value) {
+ ObjectModelElementImpl impl = (ObjectModelElementImpl) element;
+
+ ObjectModelImplTagValue tagValue = new ObjectModelImplTagValue();
+ tagValue.setName(name);
+ tagValue.setValue(value);
+ impl.addTagValue(tagValue);
+ }
+
+ /**
+ * Create a new class in the model.
+ * Modifiers allowed : ABSTRACT, STATIC.
+ *
+ * @param name class name
+ * @param packageName class package
+ * @param modifiers class modifiers
+ * @return the new ObjectModelClass added to the model
+ */
+ public ObjectModelClass createClass(String name, String packageName, ObjectModelModifier... modifiers) {
+ ObjectModelClassImpl result = new ObjectModelClassImpl();
+ return createClass(result, name, packageName, modifiers);
+ }
+
+ protected ObjectModelClass createClass(ObjectModelClassImpl clazz, String name, String packageName, ObjectModelModifier... modifiers)
+ throws IllegalArgumentException {
+ clazz.setName(name);
+ clazz.setPackage(packageName);
+ for (ObjectModelModifier modifier : modifiers) {
+ switch (modifier) {
+ case ABSTRACT:
+ clazz.setAbstract(true);
+ break;
+ case STATIC:
+ clazz.setStatic(true);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported modifier type '" + modifier.name() + "'");
+ }
+ }
+ model.addClass(clazz);
+ return clazz;
+ }
+
+ /**
+ * Create a new interface in the model.
+ *
+ * @param name interface name
+ * @param packageName interface package
+ * @return the new ObjectModelInterface added to the model
+ */
+ public ObjectModelInterface createInterface(String name, String packageName) {
+ ObjectModelInterfaceImpl result = new ObjectModelInterfaceImpl();
+ result.setName(name);
+ result.setPackage(packageName);
+ model.addInterface(result);
+ return result;
+ }
+
+ /**
+ * Create a new interface in the model.
+ *
+ * @param name interface name
+ * @param packageName interface package
+ * @return the new ObjectModelInterface added to the model
+ */
+ public ObjectModelEnumeration createEnumeration(String name, String packageName) {
+ ObjectModelEnumerationImpl result = new ObjectModelEnumerationImpl();
+ result.setName(name);
+ result.setPackage(packageName);
+ model.addEnumeration(result);
+ return result;
+ }
+
+
+ /**
+ * Add an attribute to a classifier (interface, class, enum) without default value.
+ * Default visibility is set to PUBLIC.
+ *
+ * @param classifier where the attribute will be added
+ * @param name attribute name
+ * @param type attribute type (full qualified name)
+ * @return the new ObjectModelAttribute added
+ */
+ public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, String name, String type) {
+ return addAttribute(classifier, name, type, "");
+ }
+
+ /**
+ * Add an attribute to a classifier (interface, class, enum).
+ * Modifiers allowed : STATIC, FINAL, PUBLIC, PRIVATE, PROTECTED, PACKAGE, ORDERED, UNIQUE.
+ * The last visibility set will be keeped.
+ *
+ * @param classifier where the attribute will be added
+ * @param name attribute name
+ * @param type attribute type (full qualified name)
+ * @param value default value for the attribute
+ * @param modifiers attribute modifiers
+ * @return the new ObjectModelAttribute added
+ * @throws IllegalArgumentException illegal Modifier
+ * @see org.nuiton.eugene.models.object.ObjectModelModifier#isVisibility()
+ */
+ public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, String name, String type, String value,
+ ObjectModelModifier... modifiers) throws IllegalArgumentException {
+ ObjectModelAttributeImpl attribute = new ObjectModelAttributeImpl();
+ attribute.setName(name);
+ attribute.setType(type);
+ attribute.setDefaultValue(value);
+
+ for (ObjectModelModifier modifier : modifiers) {
+ if (modifier.isVisibility()) {
+ attribute.setVisibility(modifier.toString());
+ } else {
+ switch (modifier) {
+ case STATIC:
+ attribute.setStatic(true);
+ break;
+ case FINAL:
+ attribute.setFinal(true);
+ break;
+ case ORDERED:
+ attribute.setOrdering(modifier.toString());
+ break;
+ case UNIQUE:
+ attribute.setUnique(true);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported modifier type '" + modifier.name() + "'");
+ }
+ }
+ }
+
+ ObjectModelClassifierImpl classifierImpl = (ObjectModelClassifierImpl) classifier;
+ classifierImpl.addAttribute(attribute);
+ return attribute;
+ }
+
+ /**
+ * Add an association A to B. Create only attribute association for classifierA.
+ * MODIFIERS allowed : PUBLIC, PRIVATE, PACKAGE, PROTECTED, AGGREGATE, COMPOSITE, ORDERED, UNIQUE
+ * STATIC, NAVIGABLE.
+ * You have to use method {@link #addReverseAssociation(org.nuiton.eugene.models.object.ObjectModelAttribute,java.lang.String, int, int, org.nuiton.eugene.models.object.ObjectModelModifier...)}
+ * to create attribute association for classifierB.
+ *
+ * @param classifierA classifier from
+ * @param classifierB classifier to
+ * @param roleName role of A in association
+ * @param minMultiplicity minimum multiplicity of A in association
+ * @param maxMultiplicity maximum multiplicity of A in association
+ * @param modifiers for the association
+ * @return the attribute corresponding to the association for classifierA
+ * @throws IllegalArgumentException illegal modifier
+ */
+ public ObjectModelAttribute addAssociation(ObjectModelClassifier classifierA, ObjectModelClassifier classifierB, String roleName,
+ int minMultiplicity, int maxMultiplicity, ObjectModelModifier... modifiers)
+ throws IllegalArgumentException {
+
+ ObjectModelAttributeImpl attribute = new ObjectModelAttributeImpl();
+
+ attribute.setName(roleName);
+ attribute.setMinMultiplicity(minMultiplicity);
+ attribute.setMaxMultiplicity(maxMultiplicity);
+ attribute.setType(classifierB.getQualifiedName());
+
+ for (ObjectModelModifier modifier : modifiers) {
+
+ if (modifier.isVisibility()) {
+ attribute.setVisibility(modifier.toString());
+ } else if (modifier.isAssociationType()) {
+ attribute.setAssociationType(modifier.toString());
+ } else {
+ switch (modifier) {
+ case ORDERED:
+ attribute.setOrdering(modifier.toString());
+ break;
+ case UNIQUE:
+ attribute.setUnique(true);
+ break;
+ case STATIC:
+ attribute.setStatic(true);
+ break;
+ case NAVIGABLE:
+ attribute.setNavigable(true);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported modifier type '" + modifier.name() + "'");
+ }
+ }
+ }
+ ObjectModelClassifierImpl impl = (ObjectModelClassifierImpl) classifierA;
+ impl.addAttribute(attribute);
+ return attribute;
+ }
+
+ /**
+ * Create reverse association from an other association.
+ * MODIFIERS allowed : PUBLIC, PRIVATE, PACKAGE, PROTECTED, AGGREGATE, COMPOSITE, ORDERED, UNIQUE
+ * STATIC, NAVIGABLE.
+ *
+ * @param attrAssociation other association A to B
+ * @param roleName role of B in association
+ * @param minMultiplicity minimum multiplicity of B in association
+ * @param maxMultiplicity maximum multiplicity of B in association
+ * @param modifiers for the association
+ * @return the attribute corresponding to the association for classifierB
+ * @see #addAssociation(org.nuiton.eugene.models.object.ObjectModelClassifier, org.nuiton.eugene.models.object.ObjectModelClassifier,java.lang.String, int, int, org.nuiton.eugene.models.object.ObjectModelModifier...)
+ */
+ public ObjectModelAttribute addReverseAssociation(ObjectModelAttribute attrAssociation, String roleName,
+ int minMultiplicity, int maxMultiplicity, ObjectModelModifier... modifiers) {
+
+ ObjectModelAttributeImpl associationA = (ObjectModelAttributeImpl) attrAssociation;
+ // Add reverse parameters
+ associationA.setReverseAttributeName(roleName);
+ associationA.setReverseMaxMultiplicity(maxMultiplicity);
+
+ ObjectModelClassifierImpl classifierA =
+ (ObjectModelClassifierImpl) associationA.getDeclaringElement();
+
+ String typeB = associationA.getType();
+ // Get classifierB from model
+ ObjectModelClassifierImpl classifierB = (ObjectModelClassifierImpl) model.getClassifier(typeB);
+
+ // Create reverse association
+ ObjectModelAttributeImpl associationB =
+ (ObjectModelAttributeImpl) addAssociation(classifierB, classifierA, roleName,
+ minMultiplicity, maxMultiplicity, modifiers);
+
+ associationB.setReverseAttributeName(associationA.getName());
+ associationB.setReverseMaxMultiplicity(associationA.getMaxMultiplicity());
+
+ return associationB;
+ }
+
+ /**
+ * Create association class. The two extremities of the association must be existing before creating
+ * the association class.
+ * Modifiers allowed : ABSTRACT, STATIC.
+ *
+ * @param name association class name
+ * @param packageName association package name
+ * @param attrAssociationA attribute association for classifierA involved in association class
+ * @param attrAssociationB attribute association for classifierB involved in association class
+ * @param modifiers for the association class
+ * @return the new association class created with participants A and B
+ */
+ public ObjectModelAssociationClass createAssociationClass(String name, String packageName, ObjectModelAttribute attrAssociationA,
+ ObjectModelAttribute attrAssociationB, ObjectModelModifier... modifiers) {
+
+ ObjectModelAssociationClassImpl associationClass = new ObjectModelAssociationClassImpl();
+ createClass(associationClass, name, packageName, modifiers);
+
+ // Add associationClass in attrAssociationA
+ ObjectModelAttributeImpl attrA = (ObjectModelAttributeImpl) attrAssociationA;
+ attrA.setAssociationClassName(associationClass.getQualifiedName());
+
+ // Add associationClass in attrAssociationB
+ ObjectModelAttributeImpl attrB = (ObjectModelAttributeImpl) attrAssociationB;
+ attrB.setAssociationClassName(associationClass.getQualifiedName());
+
+ // Create participantA
+ ObjectModeImplAssociationClassParticipant participantA =
+ new ObjectModeImplAssociationClassParticipant();
+
+ participantA.setAttribute(attrA.getName());
+ ObjectModelClassifier classifierA = (ObjectModelClassifier) attrA.getDeclaringElement();
+ participantA.setName(classifierA.getQualifiedName());
+
+ associationClass.addParticipant(participantA);
+
+ // Create participantB
+ ObjectModeImplAssociationClassParticipant participantB =
+ new ObjectModeImplAssociationClassParticipant();
+
+ participantB.setAttribute(attrB.getName());
+ ObjectModelClassifier classifierB = (ObjectModelClassifier) attrB.getDeclaringElement();
+ participantB.setName(classifierB.getQualifiedName());
+
+ associationClass.addParticipant(participantB);
+
+ return associationClass;
+ }
+
+ /**
+ * Add an operation to a classifier.
+ * Modifiers allowed : STATIC, ABSTRACT, PUBLIC, PRIVATE, PROTECTED, PACKAGE.
+ * The last visibility set will be keeped.
+ *
+ * @param classifier where the operation will be added
+ * @param name operation name
+ * @param returnType operation type (full qualified name)
+ * @param modifiers operation modifiers
+ * @return the new ObjectModelOperation added
+ * @throws IllegalArgumentException illegal Modifier
+ */
+ public ObjectModelOperation addOperation(ObjectModelClassifier classifier,
+ String name, String returnType, ObjectModelModifier... modifiers)
+ throws IllegalArgumentException {
+ ObjectModelOperationImpl result = new ObjectModelOperationImpl();
+ result.setName(name);
+
+ if (returnType != null) {
+ ObjectModelParameterImpl returnParameter = new ObjectModelParameterImpl();
+ returnParameter.setType(returnType);
+ result.setReturnParameter(returnParameter);
+ }
+
+ for (ObjectModelModifier modifier : modifiers) {
+ if (modifier.isVisibility()) {
+ result.setVisibility(modifier.toString());
+ } else {
+ switch (modifier) {
+ case STATIC:
+ result.setStatic(true);
+ break;
+ case ABSTRACT:
+ result.setAbstract(true);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported modifier type '" + modifier.name() + "'");
+ }
+ }
+ }
+
+ ((ObjectModelClassifierImpl) classifier).addOperation(result);
+ return result;
+ }
+
+ /**
+ * Set the body code for an Operation.
+ *
+ * @param operation where the code will be added
+ * @param body code to add to the operation
+ */
+ public void setOperationBody(ObjectModelOperation operation, String body) {
+ ObjectModelOperationImpl operationImpl = (ObjectModelOperationImpl) operation;
+ operationImpl.setBodyCode(body);
+ }
+
+ /**
+ * Add an interface to a classifier. The interface may not exist in model.
+ *
+ * @param classifier where the interface will be added
+ * @param interfaceQualifiedName interface qualified name
+ */
+ public void addInterface(ObjectModelClassifier classifier, String interfaceQualifiedName) {
+ ObjectModelClassifierImpl impl = (ObjectModelClassifierImpl) classifier;
+
+ ObjectModelImplRef interfacez = new ObjectModelImplRef();
+ interfacez.setName(interfaceQualifiedName);
+
+ impl.addInterface(interfacez);
+ }
+
+ /**
+ * Add a superclass to an other class. The superclass may not exist in model.
+ *
+ * @param clazz where the superclass will be added
+ * @param superclassQualifiedName superclass qualified name
+ */
+ public void addSuperclass(ObjectModelClass clazz, String superclassQualifiedName) {
+ ObjectModelClassImpl impl = (ObjectModelClassImpl) clazz;
+
+ ObjectModelImplSuperClassRef superclass = new ObjectModelImplSuperClassRef();
+ superclass.setName(superclassQualifiedName);
+
+ impl.addSuperclass(superclass);
+ }
+
+ /**
+ * Add a superclass to an other class. The superclass may not exist in model.
+ *
+ * @param clazz where the superclass will be added
+ * @param type type of inner classifier to create
+ * @param name superclass qualified name
+ * @return the new instanciated inner classifier
+ * @throws IllegalArgumentException if given {@code type} is not a concrete classifier type
+ */
+ public ObjectModelClassifier addInnerClassifier(ObjectModelClass clazz, ObjectModelType type, String name) throws IllegalArgumentException {
+ ObjectModelClassImpl impl = (ObjectModelClassImpl) clazz;
+ ObjectModelClassifierImpl inner;
+ switch (type) {
+
+ case OBJECT_MODEL_ENUMERATION:
+ inner = new ObjectModelEnumerationImpl();
+ break;
+ case OBJECT_MODEL_CLASS:
+ inner = new ObjectModelClassImpl();
+ break;
+ case OBJECT_MODEL_INTERFACE:
+ inner = new ObjectModelInterfaceImpl();
+ break;
+ default:
+ throw new IllegalArgumentException("can not add a none classifier type " + type);
+ }
+ inner.setName(name);
+ inner.setPackage(clazz.getPackageName() + "." + clazz.getName());
+ inner.postInit();
+ impl.addInnerClassifier(inner);
+ inner.setObjectModelImpl(impl.getModel());
+ return inner;
+ }
+
+ /**
+ * Add a parameter to an operation.
+ *
+ * @param operation where the parameter will be added
+ * @param type paremeter type (full qualified name)
+ * @param name parameter name
+ * @return the new ObjectModelParameter added
+ */
+ public ObjectModelParameter addParameter(ObjectModelOperation operation, String type, String name) {
+ ObjectModelOperationImpl impl = (ObjectModelOperationImpl) operation;
+ ObjectModelParameterImpl param = new ObjectModelParameterImpl();
+ param.setType(type);
+ param.setName(name);
+ impl.addParameter(param);
+ return param;
+ }
+
+ /**
+ * Add an exception to an operation.
+ *
+ * @param operation where the exception will be added
+ * @param exception name of the exception (full qualified name)
+ */
+ public void addException(ObjectModelOperation operation, String exception) {
+ ObjectModelOperationImpl impl = (ObjectModelOperationImpl) operation;
+ ObjectModelParameterImpl param = new ObjectModelParameterImpl();
+ param.setType(exception);
+ impl.addExceptionParameter(param);
+ }
+
+ /**
+ * Set the documentation of an element in the model.
+ *
+ * @param element where the documentation will be setted
+ * @param documentation String documentation for the element
+ */
+ public void setDocumentation(ObjectModelElement element, String documentation) {
+ ObjectModelElementImpl impl = (ObjectModelElementImpl) element;
+ impl.setDocumentation(documentation);
+ }
+
+ /**
+ * Add a stereotype to an element.
+ *
+ * @param element where the stereotype will be added
+ * @param stereotype name
+ */
+ public void addStereotype(ObjectModelElement element, String stereotype) {
+ ObjectModelElementImpl impl = (ObjectModelElementImpl) element;
+ ObjectModelImplRef ref = new ObjectModelImplRef();
+ ref.setName(stereotype);
+ impl.addStereotype(ref);
+ }
+
+ public void addLiteral(ObjectModelEnumeration enumz, String name) {
+ ObjectModelEnumerationImpl impl = (ObjectModelEnumerationImpl) enumz;
+ ObjectModelImplRef ref = new ObjectModelImplRef();
+ ref.setName(name);
+ impl.addLiteral(ref);
+ }
+}
Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelBuilder.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision
Copied: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelGenerator.java (from rev 769, trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelGenerator.java)
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelGenerator.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelGenerator.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -0,0 +1,348 @@
+/* *##%
+ * EUGene :: 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.object;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.AbstractGenerator;
+import org.nuiton.eugene.MonitorWriter;
+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;
+
+/**
+ * Pour utiliser ce type de générateur il faut implanter au moins une des trois
+ * méthodes generateFrom... et le getFilenameFor... associé si l'on souhaite un
+ * nom de fichier convenable. Si dans une méthode generateFrom... on utilise pas
+ * le Writer alors aucun fichier n'est généré.
+ *
+ * <pre>
+ * public String getFilenameForClass(ObjectModelClass clazz){
+ * return super.getFilenameForClass(Clazz) + "Service.java";
+ * }
+ *
+ * public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException{
+ * if(clazz.getType().equals("service")){
+ * / *{
+ * public class .... {
+ *
+ * }
+ * }* /
+ * }
+ * }
+ * </pre>
+ *
+ * Le nom de l'argument writer doit absolument etre output et pas autre chose si
+ * vous souhaitez utiliser le processeur
+ * org.codelutin.processor.filters.GeneratorTemplatesFilter pour vous
+ * s'implifier l'écriture des templates.
+ *
+ * Created: 14 mars 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com> Copyright Code Lutin
+ *
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$ par : $Author$
+ */
+public class ObjectModelGenerator extends AbstractGenerator<ObjectModel> {
+
+ /** Logger for this class. */
+ private static Log log = LogFactory.getLog(ObjectModelGenerator.class);
+
+ public ObjectModelGenerator() {
+ super();
+ }
+
+ public ObjectModelGenerator(AbstractGenerator<ObjectModel> parent) {
+ super(parent);
+ }
+
+ @Override
+ @Deprecated
+ public void generate(File[] files, File destDir) {
+ ObjectModelReader reader = new ObjectModelReader();
+ ObjectModel objectModel = reader.read(files);
+ setLastModifiedSource(reader.getLastModifiedSource());
+ try {
+ applyTemplate(objectModel, destDir);
+ } catch (IOException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Unable to generate for file", eee);
+ }
+ }
+ }
+
+ /**
+ * Par defaut la methode appelle la methode
+ * {@link #generateFromModel(Writer, ObjectModel)} puis boucle sur chaque
+ * class en appelant la m?thode
+ * {@link #generateFromClass(Writer, ObjectModelClass)} puis boucle sur chaque
+ * interface en appelant a méthode
+ * {@link #generateFromInterface(Writer, ObjectModelInterface)} et enfin sur chaque
+ * énumération en appelant la méthode
+ * {@link #generateFromEnumeration(Writer, ObjectModelEnumeration)}
+ * Le nom de fichier est récupérer pour chacun d'eux en appelant la méthode
+ * getFilenameFor.... La methode generateFrom... n'utilise pas le Writer
+ * alors le fichier n'est pas généré, si on l'utilise m?me pour ne rien
+ * écrire alors le fichier sera généré.
+ * @param model le modele memoire a utiliser
+ * @param destDir le repertoire ou generer
+ * @throws IOException pour tout pb
+ */
+ @Override
+ public void applyTemplate(ObjectModel model, File destDir) throws IOException {
+
+ // generateFromModel
+ this.model = model;
+
+ String filename = getFilenameForModel(model);
+
+ // generateFromModel
+ generateFromElement(model, destDir, filename, ObjectModelType.OBJECT_MODEL);
+
+ // generateFromClassifier
+ generateFromElements(model.getClassifiers(), destDir, ObjectModelType.OBJECT_MODEL_CLASSIFIER);
+
+ // generateFromInterface
+ generateFromElements(model.getInterfaces(), destDir, ObjectModelType.OBJECT_MODEL_INTERFACE);
+
+ // generateFromClass
+ generateFromElements(model.getClasses(), destDir, ObjectModelType.OBJECT_MODEL_CLASS);
+
+ // generateFromEnumeration
+ generateFromElements(model.getEnumerations(), destDir, ObjectModelType.OBJECT_MODEL_ENUMERATION);
+
+ }
+
+ /**
+ * Parcours une collection d'éléments pour la génération suivant un type d'éléments.
+ * Types possibles : ObjectModelClassifier, ObjectModelClass, ObjectModelInterface et
+ * ObjectModelEnumeration.
+ * Deux méthodes dépendent du type et peuvent être surchargées :
+ * getFilenameForXXX et generateFromXXX (XXX étant un type prédéfini pour une méthode existante).
+ *
+ * @see ObjectModelType
+ *
+ * @param elements Collection d'éléments d'un des types ci-dessus
+ * @param destDir dossier de destination pour le fichier généré
+ * @param type type explicite d'ObjectModel
+ */
+ private void generateFromElements(Collection<? extends ObjectModelElement> elements, File destDir,
+ ObjectModelType type) {
+
+ for (ObjectModelElement element : elements) {
+ String filename = "";
+ // Filename depends on type of element (Classifier, Class, Interface or Enumeration)
+ switch (type) {
+ case OBJECT_MODEL_CLASSIFIER:
+ filename = getFilenameForClassifier((ObjectModelClassifier)element);
+ break;
+ case OBJECT_MODEL_INTERFACE:
+ filename = getFilenameForInterface((ObjectModelInterface)element);
+ break;
+ case OBJECT_MODEL_CLASS:
+ filename = getFilenameForClass((ObjectModelClass)element);
+ break;
+ case OBJECT_MODEL_ENUMERATION:
+ filename = getFilenameForEnumeration((ObjectModelEnumeration)element);
+ }
+
+ generateFromElement(element, destDir, filename, type);
+ }
+ }
+
+ /**
+ * Génération pour un élément du modèle (ou le modèle lui-même).
+ * Types possibles : ObjectModel, ObjectModelClassifier, ObjectModelClass,
+ * ObjectModelInterface et ObjectModelEnumeration.
+ * La méthode generateFromXXX dépend du type d'élément et peut être surchargée.
+ *
+ * @see ObjectModelType
+ *
+ * @param element element à généré
+ * @param destDir dossier de destination
+ * @param filename nom du fichier de sortie
+ * @param type type d'ObjectModel
+ */
+ protected void generateFromElement(Object element, File destDir, String filename,
+ ObjectModelType type) {
+
+ // on a maintenant une restriction des elements a generer
+ // c'est à dire un filtrage par package
+ // effectue un appel pour savoir si on a le droit de generer l'element
+ // courant
+ if (canGenerateElement(element)) {
+
+ File outputFile = getDestinationFile(destDir, filename);
+ if (!getOverwrite() && isNewerThanSource(outputFile)) {
+ if (log.isTraceEnabled()) {
+ log.trace("file " + outputFile + " is up-to-date");
+ }
+ return;
+ }
+ if (!outputFile.exists() && log.isTraceEnabled()) {
+ log.trace("not up-to-date " + outputFile.lastModified()
+ + " <" + outputFile + ">");
+ }
+ try {
+ StringWriter out = new StringWriter();
+ MonitorWriter monitorOut = new MonitorWriter(out);
+
+ switch (type) {
+ case OBJECT_MODEL:
+ generateFromModel(monitorOut,(ObjectModel)element);
+ break;
+ case OBJECT_MODEL_CLASSIFIER:
+ generateFromClassifier(monitorOut, (ObjectModelClassifier)element);
+ break;
+ case OBJECT_MODEL_INTERFACE:
+ generateFromInterface(monitorOut, (ObjectModelInterface)element);
+ break;
+ case OBJECT_MODEL_CLASS:
+ generateFromClass(monitorOut, (ObjectModelClass)element);
+ break;
+ case OBJECT_MODEL_ENUMERATION:
+ generateFromEnumeration(monitorOut, (ObjectModelEnumeration)element);
+ break;
+ }
+
+ write(outputFile, monitorOut);
+ } catch (Exception eee) {
+ log.warn("Erreur lors de la génération du fichier "
+ + outputFile);
+ throw new RuntimeException(
+ "Erreur lors de la génération du fichier "
+ + outputFile, eee);
+ }
+ }
+ }
+
+ /**
+ * Test if given element can be generated.
+ *
+ * An element can be generated if his package is in the {@link #generatedPackages} list
+ * or if {@link #generatedPackages} is null or empty.
+ *
+ * @param element element to test
+ * @return generation allowed
+ */
+ protected boolean canGenerateElement(Object element) {
+
+ boolean canGenerate = true;
+
+ // can get package only for Classifiers
+ if (element instanceof ObjectModelClassifier) {
+ ObjectModelClassifier classifier = (ObjectModelClassifier)element;
+ String classifierPackage = classifier.getPackageName();
+
+ canGenerate = super.canGeneratePackage(classifierPackage);
+ }
+
+ return canGenerate;
+ }
+
+ /**
+ * Par defaut cette methode retourne le getName du model. Si l'on souhaite
+ * utiliser la methode generateFromModel il vaut mieux surcharger cette
+ * methode
+ * @param model le modele utilise
+ * @return le nom du fichier a generer
+ */
+ public String getFilenameForModel(ObjectModel model) {
+ // TODO throw exception when model.getName() == null or empty
+ return model.getName();
+ }
+
+ /**
+ * Par defaut cette methode retourne le QualifiedName convertie en chemin
+ * par exemple pour org.codelutin.Toto on aurait org/codelutin/Toto
+ * @param model le modele utilise
+ * @param packageName le nom du paquetage
+ * @return le repertoire correspondant au paquetage
+ */
+ public String getFilenameForPackage(ObjectModel model, String packageName) {
+ return packageName.replace('.', File.separatorChar);
+ }
+
+ /**
+ * Par defaut cette methode retourne le QualifiedName convertie en chemin
+ * par exemple pour org.codelutin.Toto on aurait org/codelutin/Toto
+ * @param interfacez l'interface utilisee
+ * @return le nom du l'interface a generer
+ */
+ public String getFilenameForInterface(ObjectModelInterface interfacez) {
+ return getFilenameForClassifier(interfacez);
+// return interfacez.getQualifiedName().replace('.', File.separatorChar);
+ }
+
+ /**
+ * Par defaut cette methode retourne le QualifiedName convertie en chemin
+ * par exemple pour org.codelutin.Toto on aurait org/codelutin/Toto
+ * @param clazz la classe utilisee
+ * @return le nom de la classe a generer
+ */
+ public String getFilenameForClass(ObjectModelClass clazz) {
+ return getFilenameForClassifier(clazz);
+// return clazz.getQualifiedName().replace('.', File.separatorChar);
+ }
+
+ /**
+ * Par defaut cette methode retourne le QualifiedName convertie en chemin
+ * par exemple pour org.codelutin.Toto on aurait org/codelutin/Toto
+ * @param classifier le classifier utilisee
+ * @return le nom du classifier a generer
+ */
+ public String getFilenameForClassifier(ObjectModelClassifier classifier) {
+ return classifier.getQualifiedName().replace('.', File.separatorChar);
+ }
+
+ public String getFilenameForEnumeration(ObjectModelEnumeration enumeration) {
+ return getFilenameForClassifier(enumeration);
+// return enumeration.getQualifiedName().replace('.', File.separatorChar);
+ }
+
+ public void generateFromModel(Writer output, ObjectModel model) throws IOException {
+ }
+
+ public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException {
+ }
+
+ public void generateFromEnum(Writer output, ObjectModelEnumeration interfacez) throws IOException {
+ }
+
+ public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
+ }
+
+ public void generateFromClassifier(Writer output, ObjectModelClassifier clazz) throws IOException {
+ }
+
+ public void generateFromEnumeration(Writer output, ObjectModelEnumeration enumeration) throws IOException {
+ }
+}
Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelGenerator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java (from rev 769, trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelReader.java)
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -0,0 +1,245 @@
+/*
+ * *##%
+ * EUGene :: 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.object;
+
+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.ModelReader;
+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;
+
+/**
+ * To read object model files into an memory object model.
+ *
+ * Created: 26 oct. 2009
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ *
+ * @plexus.component role="org.nuiton.eugene.ModelReader" role-hint="objectmodel"
+ */
+public class ObjectModelReader extends ModelReader<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
+ */
+ @Override
+ public ObjectModel read(File[] files) {
+ 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);
+ }
+ }*/
+ }
+}
Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision
Copied: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelTransformer.java (from rev 769, trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelTransformer.java)
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelTransformer.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelTransformer.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -0,0 +1,148 @@
+/*
+ * *##%
+ * EUGene :: 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.object;
+
+import org.nuiton.eugene.Transformer;
+import org.nuiton.eugene.models.Model;
+
+import java.util.Collection;
+
+/**
+ * ObjectModelTransformer
+ * <p/>
+ * Created: 28 oct. 2009
+ *
+ *
+ * L'initialisation du modèle de sortie et du générateur de sortie associée,
+ * se fait dans la superclass grâce à la méthode init.
+ *
+ * @author fdesbois
+ * @version $Revision$
+ * <p/>
+ * Mise a jour: $Date$
+ * par : $Author$
+ * @param <O>
+ */
+public abstract class ObjectModelTransformer<O extends Model> extends Transformer<ObjectModel, O> {
+
+ /**
+ * Le model associé au transformer est le model d'entree. Le modele de sortie
+ * peut etre initialiser via la methode {@link org.nuiton.eugene.Transformer#initOutputModel()}.
+ * Il est également possible de surcharger la methode {@link #debugOutputModel()}
+ * pour verifier le resultat de la transformation.
+ * Par defaut la methode appelle la methode
+ * {@link #transformFromModel(ObjectModel)} puis boucle sur chaque
+ * class en appelant la methode
+ * {@link #transformFromClass(ObjectModelClass)} puis boucle sur chaque
+ * interface en appelant a methode
+ * {@link #transformFromInterface(ObjectModelInterface)} et enfin sur chaque
+ * enumeration en appelant la methode
+ * {@link #transformFromEnumeration(ObjectModelEnumeration)}
+ */
+ @Override
+ public void transform() {
+
+ // transformFromModel
+ transformFromElement(getModel(), ObjectModelType.OBJECT_MODEL);
+
+ // transformFromClassifier
+ transformFromElements(getModel().getClassifiers(), ObjectModelType.OBJECT_MODEL_CLASSIFIER);
+
+ // transformFromInterface
+ transformFromElements(getModel().getInterfaces(), ObjectModelType.OBJECT_MODEL_INTERFACE);
+
+ // transformFromClass
+ transformFromElements(getModel().getClasses(), ObjectModelType.OBJECT_MODEL_CLASS);
+
+ // transformFromEnumeration
+ transformFromElements(getModel().getEnumerations(), ObjectModelType.OBJECT_MODEL_ENUMERATION);
+
+ debugOutputModel();
+ }
+
+ protected abstract void debugOutputModel();
+
+ /**
+ * Parcours une collection d'éléments pour la transformation suivant un type d'éléments.
+ * Types possibles : ObjectModelClassifier, ObjectModelClass, ObjectModelInterface et
+ * ObjectModelEnumeration.
+ * Une méthode dépend du type et peut être surchargée :
+ * transformFromXXX (XXX étant un type prédéfini pour une méthode existante).
+ *
+ * @param elements Collection d'éléments d'un des types ci-dessus
+ * @param type type explicite d'ObjectModel
+ * @see ObjectModelType
+ */
+ private void transformFromElements(Collection<? extends ObjectModelElement> elements,
+ ObjectModelType type) {
+
+ for (ObjectModelElement element : elements) {
+ transformFromElement(element, type);
+ }
+ }
+
+ /**
+ * Génération pour un élément du modèle (ou le modèle lui-même).
+ * Types possibles : ObjectModel, ObjectModelClassifier, ObjectModelClass,
+ * ObjectModelInterface et ObjectModelEnumeration.
+ * La méthode transformFromXXX dépend du type d'élément et peut être surchargée.
+ *
+ * @param element element à généré
+ * @param type type d'ObjectModel
+ * @see ObjectModelType
+ */
+ protected void transformFromElement(Object element, ObjectModelType type) {
+
+ switch (type) {
+ case OBJECT_MODEL:
+ transformFromModel((ObjectModel) element);
+ break;
+ case OBJECT_MODEL_CLASSIFIER:
+ transformFromClassifier((ObjectModelClassifier) element);
+ break;
+ case OBJECT_MODEL_INTERFACE:
+ transformFromInterface((ObjectModelInterface) element);
+ break;
+ case OBJECT_MODEL_CLASS:
+ transformFromClass((ObjectModelClass) element);
+ break;
+ case OBJECT_MODEL_ENUMERATION:
+ transformFromEnumeration((ObjectModelEnumeration) element);
+ break;
+ }
+ }
+
+ public void transformFromModel(ObjectModel model) {
+ }
+
+ public void transformFromInterface(ObjectModelInterface interfacez) {
+ }
+
+ public void transformFromClass(ObjectModelClass clazz) {
+ }
+
+ public void transformFromClassifier(ObjectModelClassifier clazz) {
+ }
+
+ public void transformFromEnumeration(ObjectModelEnumeration enumeration) {
+ }
+
+}
Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelTransformer.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision
Copied: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelType.java (from rev 769, trunk/eugene/src/main/java/org/nuiton/eugene/ObjectModelType.java)
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelType.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelType.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -0,0 +1,54 @@
+/* *##%
+ * EUGene :: 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.object;
+
+/**
+ * Enumeration for ObjectModelGenerator.
+ * Contains all types available for generating specific ObjectModelElement file.
+ * Needed because of inheritance between class, interface and classifier.
+ * Method instanceof (previously used) is inadequat so expliciting the ObjectModel type is much better.
+ * <p/>
+ * Created: may 4th 2009
+ *
+ * @author Florian DESBOIS <fdesbois(a)codelutin.com>
+ * @version $Revision: 496 $
+ */
+public enum ObjectModelType {
+ /**
+ * a model
+ */
+ OBJECT_MODEL,
+ /**
+ * an enumration
+ */
+ OBJECT_MODEL_ENUMERATION,
+ /**
+ * a generic classifier
+ */
+ OBJECT_MODEL_CLASSIFIER,
+ /**
+ * a class
+ */
+ OBJECT_MODEL_CLASS,
+ /**
+ * an interface
+ */
+ OBJECT_MODEL_INTERFACE
+}
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelAttributeImpl.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelAttributeImpl.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelAttributeImpl.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -150,8 +150,7 @@
ObjectModelAttribute reverseAttribute = null;
ObjectModelClassifier classifier = getClassifier();
if (classifier instanceof ObjectModelClass) {
- reverseAttribute = ((ObjectModelClass) classifier)
- .getAttribute(getReverseAttributeName());
+ reverseAttribute = classifier.getAttribute(getReverseAttributeName());
}
return reverseAttribute;
}
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelBuilder.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelBuilder.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelBuilder.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -1,545 +0,0 @@
-/*
- * *##%
- * EUGene :: 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.object.xml;
-
-import org.nuiton.eugene.ObjectModelType;
-import org.nuiton.eugene.models.object.*;
-
-/**
- * ObjectModelBuilder
- * <p/>
- * Created: 3 nov. 2009
- *
- * @author fdesbois
- * @version $Revision$
- * <p/>
- * Builder to fill an empty ObjectModel. The object model name is important if you want to use the model
- * in generators.
- * <p/>
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class ObjectModelBuilder {
-
- protected ObjectModelImpl model;
-
- /**
- * Constructor. Must have a name for the new model created.
- *
- * @param name model name
- */
- public ObjectModelBuilder(String name) {
- this.model = new ObjectModelImpl();
- this.model.setName(name);
- }
-
- /**
- * Get the building model
- *
- * @return the ObjectModel which is currently built
- */
- public ObjectModel getModel() {
- return this.model;
- }
-
- /**
- * Add a tagValue to the model.
- *
- * @param name tagValue name
- * @param value tagValue value
- */
- public void addTagValue(String name, String value) {
- ObjectModelImplTagValue tagValue = new ObjectModelImplTagValue();
- tagValue.setName(name);
- tagValue.setValue(value);
- model.addTagValue(tagValue);
- }
-
- /**
- * Add a tagValue to an element
- *
- * @param element where the tag value will be added
- * @param name tagValue name
- * @param value tagValue value
- */
- public void addTagValue(ObjectModelElement element, String name, String value) {
- ObjectModelElementImpl impl = (ObjectModelElementImpl) element;
-
- ObjectModelImplTagValue tagValue = new ObjectModelImplTagValue();
- tagValue.setName(name);
- tagValue.setValue(value);
- impl.addTagValue(tagValue);
- }
-
- /**
- * Create a new class in the model.
- * Modifiers allowed : ABSTRACT, STATIC.
- *
- * @param name class name
- * @param packageName class package
- * @param modifiers class modifiers
- * @return the new ObjectModelClass added to the model
- */
- public ObjectModelClass createClass(String name, String packageName, ObjectModelModifier... modifiers) {
- ObjectModelClassImpl result = new ObjectModelClassImpl();
- return createClass(result, name, packageName, modifiers);
- }
-
- protected ObjectModelClass createClass(ObjectModelClassImpl clazz, String name, String packageName, ObjectModelModifier... modifiers)
- throws IllegalArgumentException {
- clazz.setName(name);
- clazz.setPackage(packageName);
- for (ObjectModelModifier modifier : modifiers) {
- switch (modifier) {
- case ABSTRACT:
- clazz.setAbstract(true);
- break;
- case STATIC:
- clazz.setStatic(true);
- break;
- default:
- throw new IllegalArgumentException("Unsupported modifier type '" + modifier.name() + "'");
- }
- }
- model.addClass(clazz);
- return clazz;
- }
-
- /**
- * Create a new interface in the model.
- *
- * @param name interface name
- * @param packageName interface package
- * @return the new ObjectModelInterface added to the model
- */
- public ObjectModelInterface createInterface(String name, String packageName) {
- ObjectModelInterfaceImpl result = new ObjectModelInterfaceImpl();
- result.setName(name);
- result.setPackage(packageName);
- model.addInterface(result);
- return result;
- }
-
- /**
- * Create a new interface in the model.
- *
- * @param name interface name
- * @param packageName interface package
- * @return the new ObjectModelInterface added to the model
- */
- public ObjectModelEnumeration createEnumeration(String name, String packageName) {
- ObjectModelEnumerationImpl result = new ObjectModelEnumerationImpl();
- result.setName(name);
- result.setPackage(packageName);
- model.addEnumeration(result);
- return result;
- }
-
-
- /**
- * Add an attribute to a classifier (interface, class, enum) without default value.
- * Default visibility is set to PUBLIC.
- *
- * @param classifier where the attribute will be added
- * @param name attribute name
- * @param type attribute type (full qualified name)
- * @return the new ObjectModelAttribute added
- */
- public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, String name, String type) {
- return addAttribute(classifier, name, type, "");
- }
-
- /**
- * Add an attribute to a classifier (interface, class, enum).
- * Modifiers allowed : STATIC, FINAL, PUBLIC, PRIVATE, PROTECTED, PACKAGE, ORDERED, UNIQUE.
- * The last visibility set will be keeped.
- *
- * @param classifier where the attribute will be added
- * @param name attribute name
- * @param type attribute type (full qualified name)
- * @param value default value for the attribute
- * @param modifiers attribute modifiers
- * @return the new ObjectModelAttribute added
- * @throws IllegalArgumentException illegal Modifier
- * @see org.nuiton.eugene.models.object.ObjectModelModifier#isVisibility()
- */
- public ObjectModelAttribute addAttribute(ObjectModelClassifier classifier, String name, String type, String value,
- ObjectModelModifier... modifiers) throws IllegalArgumentException {
- ObjectModelAttributeImpl attribute = new ObjectModelAttributeImpl();
- attribute.setName(name);
- attribute.setType(type);
- attribute.setDefaultValue(value);
-
- for (ObjectModelModifier modifier : modifiers) {
- if (modifier.isVisibility()) {
- attribute.setVisibility(modifier.toString());
- } else {
- switch (modifier) {
- case STATIC:
- attribute.setStatic(true);
- break;
- case FINAL:
- attribute.setFinal(true);
- break;
- case ORDERED:
- attribute.setOrdering(modifier.toString());
- break;
- case UNIQUE:
- attribute.setUnique(true);
- break;
- default:
- throw new IllegalArgumentException("Unsupported modifier type '" + modifier.name() + "'");
- }
- }
- }
-
- ObjectModelClassifierImpl classifierImpl = (ObjectModelClassifierImpl) classifier;
- classifierImpl.addAttribute(attribute);
- return attribute;
- }
-
- /**
- * Add an association A to B. Create only attribute association for classifierA.
- * MODIFIERS allowed : PUBLIC, PRIVATE, PACKAGE, PROTECTED, AGGREGATE, COMPOSITE, ORDERED, UNIQUE
- * STATIC, NAVIGABLE.
- * You have to use method {@link #addReverseAssociation(org.nuiton.eugene.models.object.ObjectModelAttribute,java.lang.String, int, int, org.nuiton.eugene.models.object.ObjectModelModifier...)}
- * to create attribute association for classifierB.
- *
- * @param classifierA classifier from
- * @param classifierB classifier to
- * @param roleName role of A in association
- * @param minMultiplicity minimum multiplicity of A in association
- * @param maxMultiplicity maximum multiplicity of A in association
- * @param modifiers for the association
- * @return the attribute corresponding to the association for classifierA
- * @throws IllegalArgumentException illegal modifier
- */
- public ObjectModelAttribute addAssociation(ObjectModelClassifier classifierA, ObjectModelClassifier classifierB, String roleName,
- int minMultiplicity, int maxMultiplicity, ObjectModelModifier... modifiers)
- throws IllegalArgumentException {
-
- ObjectModelAttributeImpl attribute = new ObjectModelAttributeImpl();
-
- attribute.setName(roleName);
- attribute.setMinMultiplicity(minMultiplicity);
- attribute.setMaxMultiplicity(maxMultiplicity);
- attribute.setType(classifierB.getQualifiedName());
-
- for (ObjectModelModifier modifier : modifiers) {
-
- if (modifier.isVisibility()) {
- attribute.setVisibility(modifier.toString());
- } else if (modifier.isAssociationType()) {
- attribute.setAssociationType(modifier.toString());
- } else {
- switch (modifier) {
- case ORDERED:
- attribute.setOrdering(modifier.toString());
- break;
- case UNIQUE:
- attribute.setUnique(true);
- break;
- case STATIC:
- attribute.setStatic(true);
- break;
- case NAVIGABLE:
- attribute.setNavigable(true);
- break;
- default:
- throw new IllegalArgumentException("Unsupported modifier type '" + modifier.name() + "'");
- }
- }
- }
- ObjectModelClassifierImpl impl = (ObjectModelClassifierImpl) classifierA;
- impl.addAttribute(attribute);
- return attribute;
- }
-
- /**
- * Create reverse association from an other association.
- * MODIFIERS allowed : PUBLIC, PRIVATE, PACKAGE, PROTECTED, AGGREGATE, COMPOSITE, ORDERED, UNIQUE
- * STATIC, NAVIGABLE.
- *
- * @param attrAssociation other association A to B
- * @param roleName role of B in association
- * @param minMultiplicity minimum multiplicity of B in association
- * @param maxMultiplicity maximum multiplicity of B in association
- * @param modifiers for the association
- * @return the attribute corresponding to the association for classifierB
- * @see #addAssociation(org.nuiton.eugene.models.object.ObjectModelClassifier, org.nuiton.eugene.models.object.ObjectModelClassifier,java.lang.String, int, int, org.nuiton.eugene.models.object.ObjectModelModifier...)
- */
- public ObjectModelAttribute addReverseAssociation(ObjectModelAttribute attrAssociation, String roleName,
- int minMultiplicity, int maxMultiplicity, ObjectModelModifier... modifiers) {
-
- ObjectModelAttributeImpl associationA = (ObjectModelAttributeImpl) attrAssociation;
- // Add reverse parameters
- associationA.setReverseAttributeName(roleName);
- associationA.setReverseMaxMultiplicity(maxMultiplicity);
-
- ObjectModelClassifierImpl classifierA =
- (ObjectModelClassifierImpl) associationA.getDeclaringElement();
-
- String typeB = associationA.getType();
- // Get classifierB from model
- ObjectModelClassifierImpl classifierB = (ObjectModelClassifierImpl) model.getClassifier(typeB);
-
- // Create reverse association
- ObjectModelAttributeImpl associationB =
- (ObjectModelAttributeImpl) addAssociation(classifierB, classifierA, roleName,
- minMultiplicity, maxMultiplicity, modifiers);
-
- associationB.setReverseAttributeName(associationA.getName());
- associationB.setReverseMaxMultiplicity(associationA.getMaxMultiplicity());
-
- return associationB;
- }
-
- /**
- * Create association class. The two extremities of the association must be existing before creating
- * the association class.
- * Modifiers allowed : ABSTRACT, STATIC.
- *
- * @param name association class name
- * @param packageName association package name
- * @param attrAssociationA attribute association for classifierA involved in association class
- * @param attrAssociationB attribute association for classifierB involved in association class
- * @param modifiers for the association class
- * @return the new association class created with participants A and B
- */
- public ObjectModelAssociationClass createAssociationClass(String name, String packageName, ObjectModelAttribute attrAssociationA,
- ObjectModelAttribute attrAssociationB, ObjectModelModifier... modifiers) {
-
- ObjectModelAssociationClassImpl associationClass = new ObjectModelAssociationClassImpl();
- createClass(associationClass, name, packageName, modifiers);
-
- // Add associationClass in attrAssociationA
- ObjectModelAttributeImpl attrA = (ObjectModelAttributeImpl) attrAssociationA;
- attrA.setAssociationClassName(associationClass.getQualifiedName());
-
- // Add associationClass in attrAssociationB
- ObjectModelAttributeImpl attrB = (ObjectModelAttributeImpl) attrAssociationB;
- attrB.setAssociationClassName(associationClass.getQualifiedName());
-
- // Create participantA
- ObjectModeImplAssociationClassParticipant participantA =
- new ObjectModeImplAssociationClassParticipant();
-
- participantA.setAttribute(attrA.getName());
- ObjectModelClassifier classifierA = (ObjectModelClassifier) attrA.getDeclaringElement();
- participantA.setName(classifierA.getQualifiedName());
-
- associationClass.addParticipant(participantA);
-
- // Create participantB
- ObjectModeImplAssociationClassParticipant participantB =
- new ObjectModeImplAssociationClassParticipant();
-
- participantB.setAttribute(attrB.getName());
- ObjectModelClassifier classifierB = (ObjectModelClassifier) attrB.getDeclaringElement();
- participantB.setName(classifierB.getQualifiedName());
-
- associationClass.addParticipant(participantB);
-
- return associationClass;
- }
-
- /**
- * Add an operation to a classifier.
- * Modifiers allowed : STATIC, ABSTRACT, PUBLIC, PRIVATE, PROTECTED, PACKAGE.
- * The last visibility set will be keeped.
- *
- * @param classifier where the operation will be added
- * @param name operation name
- * @param returnType operation type (full qualified name)
- * @param modifiers operation modifiers
- * @return the new ObjectModelOperation added
- * @throws IllegalArgumentException illegal Modifier
- */
- public ObjectModelOperation addOperation(ObjectModelClassifier classifier,
- String name, String returnType, ObjectModelModifier... modifiers)
- throws IllegalArgumentException {
- ObjectModelOperationImpl result = new ObjectModelOperationImpl();
- result.setName(name);
-
- if (returnType != null) {
- ObjectModelParameterImpl returnParameter = new ObjectModelParameterImpl();
- returnParameter.setType(returnType);
- result.setReturnParameter(returnParameter);
- }
-
- for (ObjectModelModifier modifier : modifiers) {
- if (modifier.isVisibility()) {
- result.setVisibility(modifier.toString());
- } else {
- switch (modifier) {
- case STATIC:
- result.setStatic(true);
- break;
- case ABSTRACT:
- result.setAbstract(true);
- break;
- default:
- throw new IllegalArgumentException("Unsupported modifier type '" + modifier.name() + "'");
- }
- }
- }
-
- ((ObjectModelClassifierImpl) classifier).addOperation(result);
- return result;
- }
-
- /**
- * Set the body code for an Operation.
- *
- * @param operation where the code will be added
- * @param body code to add to the operation
- */
- public void setOperationBody(ObjectModelOperation operation, String body) {
- ObjectModelOperationImpl operationImpl = (ObjectModelOperationImpl) operation;
- operationImpl.setBodyCode(body);
- }
-
- /**
- * Add an interface to a classifier. The interface may not exist in model.
- *
- * @param classifier where the interface will be added
- * @param interfaceQualifiedName interface qualified name
- */
- public void addInterface(ObjectModelClassifier classifier, String interfaceQualifiedName) {
- ObjectModelClassifierImpl impl = (ObjectModelClassifierImpl) classifier;
-
- ObjectModelImplRef interfacez = new ObjectModelImplRef();
- interfacez.setName(interfaceQualifiedName);
-
- impl.addInterface(interfacez);
- }
-
- /**
- * Add a superclass to an other class. The superclass may not exist in model.
- *
- * @param clazz where the superclass will be added
- * @param superclassQualifiedName superclass qualified name
- */
- public void addSuperclass(ObjectModelClass clazz, String superclassQualifiedName) {
- ObjectModelClassImpl impl = (ObjectModelClassImpl) clazz;
-
- ObjectModelImplSuperClassRef superclass = new ObjectModelImplSuperClassRef();
- superclass.setName(superclassQualifiedName);
-
- impl.addSuperclass(superclass);
- }
-
- /**
- * Add a superclass to an other class. The superclass may not exist in model.
- *
- * @param clazz where the superclass will be added
- * @param type type of inner classifier to create
- * @param name superclass qualified name
- * @return the new instanciated inner classifier
- * @throws IllegalArgumentException if given {@code type} is not a concrete classifier type
- */
- public ObjectModelClassifier addInnerClassifier(ObjectModelClass clazz, ObjectModelType type, String name) throws IllegalArgumentException {
- ObjectModelClassImpl impl = (ObjectModelClassImpl) clazz;
- ObjectModelClassifierImpl inner;
- switch (type) {
-
- case OBJECT_MODEL_ENUMERATION:
- inner = new ObjectModelEnumerationImpl();
- break;
- case OBJECT_MODEL_CLASS:
- inner = new ObjectModelClassImpl();
- break;
- case OBJECT_MODEL_INTERFACE:
- inner = new ObjectModelInterfaceImpl();
- break;
- default:
- throw new IllegalArgumentException("can not add a none classifier type " + type);
- }
- inner.setName(name);
- inner.setPackage(clazz.getPackageName() + "." + clazz.getName());
- inner.postInit();
- impl.addInnerClassifier(inner);
- inner.setObjectModelImpl(impl.getModel());
- return inner;
- }
-
- /**
- * Add a parameter to an operation.
- *
- * @param operation where the parameter will be added
- * @param type paremeter type (full qualified name)
- * @param name parameter name
- * @return the new ObjectModelParameter added
- */
- public ObjectModelParameter addParameter(ObjectModelOperation operation, String type, String name) {
- ObjectModelOperationImpl impl = (ObjectModelOperationImpl) operation;
- ObjectModelParameterImpl param = new ObjectModelParameterImpl();
- param.setType(type);
- param.setName(name);
- impl.addParameter(param);
- return param;
- }
-
- /**
- * Add an exception to an operation.
- *
- * @param operation where the exception will be added
- * @param exception name of the exception (full qualified name)
- */
- public void addException(ObjectModelOperation operation, String exception) {
- ObjectModelOperationImpl impl = (ObjectModelOperationImpl) operation;
- ObjectModelParameterImpl param = new ObjectModelParameterImpl();
- param.setType(exception);
- impl.addExceptionParameter(param);
- }
-
- /**
- * Set the documentation of an element in the model.
- *
- * @param element where the documentation will be setted
- * @param documentation String documentation for the element
- */
- public void setDocumentation(ObjectModelElement element, String documentation) {
- ObjectModelElementImpl impl = (ObjectModelElementImpl) element;
- impl.setDocumentation(documentation);
- }
-
- /**
- * Add a stereotype to an element.
- *
- * @param element where the stereotype will be added
- * @param stereotype name
- */
- public void addStereotype(ObjectModelElement element, String stereotype) {
- ObjectModelElementImpl impl = (ObjectModelElementImpl) element;
- ObjectModelImplRef ref = new ObjectModelImplRef();
- ref.setName(stereotype);
- impl.addStereotype(ref);
- }
-
- public void addLiteral(ObjectModelEnumeration enumz, String name) {
- ObjectModelEnumerationImpl impl = (ObjectModelEnumerationImpl) enumz;
- ObjectModelImplRef ref = new ObjectModelImplRef();
- ref.setName(name);
- impl.addLiteral(ref);
- }
-}
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelElementImpl.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -73,7 +73,7 @@
* TODO a tester
* @return the objectModel
*/
- protected ObjectModelImpl getModel() {
+ public ObjectModelImpl getModel() {
if (objectModelImpl != null) {
return objectModelImpl;
} else if (declaringElement != null) {
@@ -203,7 +203,7 @@
*/
@Override
public String getTagValue(String tagValue) {
- return (tagValue == null ? null : (String) tagValues.get(tagValue));
+ return (tagValue == null ? null : tagValues.get(tagValue));
}
/**
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelEnumerationImpl.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelEnumerationImpl.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelEnumerationImpl.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -23,7 +23,6 @@
import java.util.Collection;
import org.nuiton.eugene.models.object.ObjectModelEnumeration;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
/**
* ObjectModelEnumerationImpl.
Copied: trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelGenerator.java (from rev 769, trunk/eugene/src/main/java/org/nuiton/eugene/StateModelGenerator.java)
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelGenerator.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelGenerator.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -0,0 +1,216 @@
+/* *##%
+ * EUGene :: 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.state;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.AbstractGenerator;
+import org.nuiton.eugene.MonitorWriter;
+import org.nuiton.eugene.models.state.StateModel;
+import org.nuiton.eugene.models.state.StateModelState;
+import org.nuiton.eugene.models.state.StateModelStateChart;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+/**
+ * StateModelGenerator.
+ * <p/>
+ * Pour utiliser ce type de générateur, il faut implanter au moins une des
+ * méthodes generateFrom... et le getFilenameFor... associé si l'on souhaite un
+ * nom de fichier convenable. Si dans une méthode generateFrom... on utilise pas
+ * le writer (output) alors aucun fichier n'est généré.
+ * <p/>
+ * Le nom de l'argument writer doit absolument etre output et pas autre chose si
+ * vous souhaitez utiliser le processeur
+ * {@code org.nuiton.processor.filters.GeneratorTemplatesFilter} pour vous
+ * s'implifier l'écriture des templates.
+ *
+ * @author chatellier
+ * @version $Revision$
+ * <p/>
+ * Last update : $Date$ By : $Author$
+ */
+public class StateModelGenerator extends AbstractGenerator<StateModel> {
+
+ /**
+ * Logger for this class
+ */
+ private static Log log = LogFactory.getLog(StateModelGenerator.class);
+
+ /**
+ * Empty constructor
+ */
+ public StateModelGenerator() {
+ super();
+ }
+
+ /**
+ * Constructor with parent generator.
+ *
+ * @param parent parent generator
+ */
+ public StateModelGenerator(AbstractGenerator<StateModel> parent) {
+ super(parent);
+ }
+
+ /*
+ * @see org.nuiton.eugene.Generator#generate(java.io.File[], java.io.File)
+ */
+ @Override
+ @Deprecated
+ public void generate(File[] files, File destDir) {
+
+ StateModelReader reader = new StateModelReader();
+ StateModel stateModel = reader.read(files);
+ setLastModifiedSource(reader.getLastModifiedSource());
+
+ // generate code
+ try {
+ applyTemplate(stateModel, destDir);
+ } catch (IOException e) {
+ log.warn("Can't generate code for files", e);
+ }
+ }
+
+
+ /**
+ * Par défaut, appel {@link #generateFromModel(org.nuiton.eugene.MonitorWriter , org.nuiton.eugene.models.state.StateModel)} pour le
+ * model et {@link #generateFromState(Writer,StateModelState)} pour tous les
+ * etats du modele.
+ *
+ * @param stateModel Le modele d'état
+ * @param destDir le dossier de destination
+ * @throws IOException
+ */
+ @Override
+ public void applyTemplate(StateModel stateModel, File destDir) throws IOException {
+
+ model = stateModel;
+
+ String filename = getFilenameFromModel(stateModel);
+ File outputFile = getDestinationFile(destDir, filename);
+ if (getOverwrite() || !isNewerThanSource(outputFile)) {
+ try {
+ StringWriter out = new StringWriter();
+ MonitorWriter monitorOut = new MonitorWriter(out);
+ generateFromModel(monitorOut, stateModel);
+ write(outputFile, monitorOut);
+ } catch (Exception eee) {
+ log.warn("Erreur lors de la génération du fichier "
+ + outputFile);
+ throw new RuntimeException(
+ "Erreur lors de la génération du fichier " + outputFile,
+ eee);
+ }
+ }
+
+ // pour tous les diagrammes du modele
+ for (StateModelStateChart chart : stateModel.getStateCharts()) {
+
+ // elements can be restricted in package
+ if (canGenerateElement(chart)) {
+
+ // et tous les états de ces diagrammes
+ for (Object oState : chart.getStates().toArray()) {
+ StateModelState state = (StateModelState) oState;
+ String filenameState = getFilenameFromState(state, chart
+ .getName());
+ File outputFiletate = getDestinationFile(destDir, filenameState);
+ if (getOverwrite() || !isNewerThanSource(outputFiletate)) {
+ try {
+ StringWriter out = new StringWriter();
+ MonitorWriter monitorOut = new MonitorWriter(out);
+ generateFromState(monitorOut, state);
+ write(outputFiletate, monitorOut);
+ } catch (Exception eee) {
+ log.warn("Erreur lors de la génération du fichier "
+ + outputFiletate);
+ throw new RuntimeException(
+ "Erreur lors de la génération du fichier "
+ + outputFiletate, eee);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Test if given element can be generated.
+ *
+ * @param chart chart to test
+ * @return generation allowed
+ */
+ protected boolean canGenerateElement(StateModelStateChart chart) {
+
+ boolean canGenerate = true;
+
+ // disabled until tested
+ //String chartPackage = chart.getPackageName();
+ //canGenerate = super.canGeneratePackage(chartPackage);
+
+ return canGenerate;
+ }
+
+ /**
+ * Generate model code
+ *
+ * @param monitorOut
+ * @param stateModel
+ */
+ protected void generateFromModel(MonitorWriter monitorOut, StateModel stateModel) {
+
+ }
+
+ /**
+ * Return filename from model
+ *
+ * @param stateModel
+ * @return model file name
+ */
+ protected String getFilenameFromModel(StateModel stateModel) {
+ return stateModel.getName();
+ }
+
+ /**
+ * Return filename from state
+ *
+ * @param state the state
+ * @param packageName
+ * @return the filename
+ */
+ public String getFilenameFromState(StateModelState state, String packageName) {
+ return (packageName + '.' + state.getName()).replace('.', File.separatorChar);
+ }
+
+ /**
+ * Generate a state code
+ *
+ * @param monitorOut the output writer
+ * @param state the state
+ * @throws IOException
+ */
+ public void generateFromState(Writer monitorOut, StateModelState state) throws IOException {
+
+ }
+}
Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelGenerator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelReader.java (from rev 769, trunk/eugene/src/main/java/org/nuiton/eugene/StateModelReader.java)
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelReader.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelReader.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -0,0 +1,125 @@
+/*
+ * *##%
+ * EUGene :: 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.state;
+
+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.ModelReader;
+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;
+
+/**
+ * To read state model files into a memory state model.
+ *
+ * Created: 26 oct. 2009
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ *
+ * @plexus.component role="org.nuiton.eugene.ModelReader" role-hint="statemodel"
+ */
+public class StateModelReader extends ModelReader<StateModel> {
+
+ private static final Log log = LogFactory.getLog(StateModelReader.class);
+
+ @Override
+ public StateModel read(File[] files) {
+ 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);
+ }
+ }
+ }
+ }
+}
Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelReader.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Revision
Modified: trunk/eugene/src/site/fr/rst/index.rst
===================================================================
--- trunk/eugene/src/site/fr/rst/index.rst 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/site/fr/rst/index.rst 2009-12-20 16:27:20 UTC (rev 777)
@@ -54,24 +54,11 @@
Règle ant
---------
-Voici un exemple d'utilisation de la règle ant.
+Une tâche ant est disponible à l'adresse suivante
+http://maven-site.nuiton.org/eugene/ant-eugene-task. Il permet l'utilisation
+depuis Ant de Eugene.
-::
- <taskdef name="generator" classname="org.nuiton.eugene.GeneratorTask"
- classpath="${compile.classpath}:${targetbuild}:${resources}" />
-
- <target name="generate" description="generate">
- <generator srcdir="${modelDir}" destdir="${targetgen}"
- resolver="org.nuiton.exemple.ResourceResolver"
- templates="org.nuiton.example.JavaBeanGenerator"
- properties="defaultPackage=org.nuiton,fullPackagePath=org.nuiton,extraPackages=org.nuiton"
- classpath="${compile.classpath}:${targetbuild}:${resources}" />
- </target>
-
-Dans cette exemple, un template de génération sera apliqué sur tous les
-fichiers.
-
Plugin maven
------------
Deleted: trunk/eugene/src/test/java/org/nuiton/eugene/ModelFileWriterUtilTest.java
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/ModelFileWriterUtilTest.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/ModelFileWriterUtilTest.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -1,117 +0,0 @@
-/*
- * *##%
- * EUGene :: 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.junit.Assert;
-
-/**
- * User: chemit
- * Date: 25 nov. 2009
- * Time: 18:38:01
- */
-
-public abstract class ModelFileWriterUtilTest extends Assert {
-// /**
-// * Les writers disponibles pour le test
-// */
-// static Map<String, ToModelWriter> writers;
-//
-// @BeforeClass
-// public static void beforeClass() throws Exception {
-// writers = new HashMap<String, ToModelWriter>();
-// writers.put("test1", new ToModelWriter1());
-// writers.put("test2", new ToModelWriter2());
-// }
-//
-// @Before
-// public void setUp() throws Exception {
-// }
-//
-// @After
-// public void tearDown() throws Exception {
-// }
-//
-// @Test
-// public void testConstructor() throws Exception {
-// String pattern;
-// ToModelWriterContext writerContext;
-// ToModelWriter writer;
-// writer = writers.get("test1");
-//
-// pattern = "test1:";
-// writerContext = new ToModelWriterContext(basedir, pattern, ObjectModel.class, overwrite, writers);
-// assertEquals(writerContext, pattern, "test1", writer.getDefaultInputDirectory(), writer.getDefaultIncludes());
-//
-// pattern = "src/main/test1:**/*.test1";
-// writerContext = new ToModelWriterContext(basedir, pattern, ObjectModel.class, overwrite, writers);
-// assertEquals(writerContext, pattern, "test1", "src/main/test1", "**/*.test1");
-//
-// pattern = "test2:src/main/test1:**/*.test1";
-// writerContext = new ToModelWriterContext(basedir, pattern, ObjectModel.class, overwrite, writers);
-// assertEquals(writerContext, pattern, "test2", "src/main/test1", "**/*.test1");
-// }
-//
-// @Test(expected = IllegalArgumentException.class)
-// public void testConstructorUnknownInclude0() throws Exception {
-//
-// new ToModelWriterContext(basedir, ":", ObjectModel.class, overwrite, writers);
-// }
-//
-// @Test(expected = IllegalArgumentException.class)
-// public void testConstructorUnknownInclude1() throws Exception {
-//
-// new ToModelWriterContext(basedir, "test3:", ObjectModel.class, overwrite, writers);
-// }
-//
-// @Test(expected = IllegalArgumentException.class)
-// public void testConstructorUnknownInclude2() throws Exception {
-//
-// new ToModelWriterContext(basedir, "test1$", ObjectModel.class, overwrite, writers);
-// }
-//
-// @Test(expected = IllegalArgumentException.class)
-// public void testConstructorUnknownInclude3() throws Exception {
-//
-// new ToModelWriterContext(basedir, "test1$YO:", ObjectModel.class, overwrite, writers);
-// }
-//
-// @Test(expected = IllegalArgumentException.class)
-// public void testConstructorUnknownInclude4() throws Exception {
-//
-// new ToModelWriterContext(basedir, "test1$YO:yo", ObjectModel.class, overwrite, writers);
-// }
-//
-// @Test(expected = IllegalArgumentException.class)
-// public void testConstructorUnknownInclude5() throws Exception {
-//
-// new ToModelWriterContext(basedir, "test1$YO:yo:", ObjectModel.class, overwrite, writers);
-// }
-
-
-// protected void assertEquals(ToModelWriterContext writerContext, String pattern, String protocol, String inputDirectory, String includes) {
-// assertNotNull(writerContext);
-// assertEquals(pattern, writerContext.getPattern());
-// assertEquals(protocol, writerContext.getProtocol());
-// assertEquals(includes, writerContext.getIncludes());
-// assertEquals(inputDirectory, writerContext.getInputPath());
-// }
-
-}
Deleted: trunk/eugene/src/test/java/org/nuiton/eugene/ObjectModelGeneratorTest.java
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/ObjectModelGeneratorTest.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/ObjectModelGeneratorTest.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -1,97 +0,0 @@
-/* *##%
- * EUGene :: 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.util.ArrayList;
-import java.util.List;
-
-import junit.framework.Assert;
-
-import org.junit.Test;
-import org.nuiton.eugene.models.object.xml.ObjectModelClassImpl;
-import org.nuiton.eugene.models.object.xml.ObjectModelElementImpl;
-
-/**
- * Test des fonctions de ObjectModelGenerator.
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class ObjectModelGeneratorTest {
-
- @Test
- public void testCanGenerate() {
-
- ObjectModelGenerator generator = new ObjectModelGenerator();
-
- // test with null generated list
- Assert.assertTrue(generator.canGenerateElement(new ObjectModelElementImpl()));
- Assert.assertTrue(generator.canGenerateElement(new ObjectModelClassImpl()));
-
- List<String> generatedPackages = new ArrayList<String>();
- generatedPackages.add("org.nuiton.eugene");
-
- generator.setGeneratedPackages(generatedPackages);
-
- // Still true
- Assert.assertTrue(generator.canGenerateElement(new ObjectModelElementImpl()));
- // become false
- Assert.assertFalse(generator.canGenerateElement(new ObjectModelClassImpl()));
-
- ObjectModelClassImpl testClass = new ObjectModelClassImpl();
- testClass.setPackage("org.nuiton.eugene");
- Assert.assertTrue(generator.canGenerateElement(testClass));
-
- testClass.setPackage("org.nuiton");
- Assert.assertFalse(generator.canGenerateElement(testClass));
-
- testClass.setPackage("org.nuiton.eugene.entities");
- Assert.assertTrue(generator.canGenerateElement(testClass));
-
- testClass.setPackage("org.nuiton.eugene2");
- Assert.assertFalse(generator.canGenerateElement(testClass));
-
- testClass.setPackage("org.nuiton.eugene2.entities");
- Assert.assertFalse(generator.canGenerateElement(testClass));
-
- // test avec les generators recursifs
- // sans faire de set sur le fils
- ObjectModelGenerator childGenerator = new ObjectModelGenerator(generator);
-
- testClass.setPackage("org.nuiton.eugene");
- Assert.assertTrue(childGenerator.canGenerateElement(testClass));
-
- testClass.setPackage("org.nuiton");
- Assert.assertFalse(childGenerator.canGenerateElement(testClass));
-
- testClass.setPackage("org.nuiton.eugene.entities");
- Assert.assertTrue(childGenerator.canGenerateElement(testClass));
-
- testClass.setPackage("org.nuiton.eugene2");
- Assert.assertFalse(childGenerator.canGenerateElement(testClass));
-
- testClass.setPackage("org.nuiton.eugene2.entities");
- Assert.assertFalse(childGenerator.canGenerateElement(testClass));
-
- }
-}
Copied: trunk/eugene/src/test/java/org/nuiton/eugene/models/object/ModelMergeTest.java (from rev 769, trunk/eugene/src/test/java/org/nuiton/eugene/models/xml/ModelMergeTest.java)
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/models/object/ModelMergeTest.java (rev 0)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/models/object/ModelMergeTest.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -0,0 +1,127 @@
+/* *##%
+ * EUGene :: 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.object;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.util.Resource;
+
+/**
+ * ModelMergeTest.
+ * <p/>
+ * Created: 18 mai 2005
+ *
+ * @author Arnaud Thimel <thimel(a)codelutin.com>
+ * @version $Revision$
+ */
+public class ModelMergeTest {
+
+ /**
+ * Logger
+ */
+ private static final Log log = LogFactory.getLog(ModelMergeTest.class);
+
+ @Test
+ public void testMerge1() throws URISyntaxException {
+ parcourirModel(genModel(1), 4);
+ }
+
+ @Test
+ public void testMerge2() throws URISyntaxException {
+ parcourirModel(genModel(2), 4);
+ }
+
+ @Test
+ public void testMerge3() throws URISyntaxException {
+ parcourirModel(genModel(3), 4);
+ }
+
+ @Test
+ public void testMerge4() throws URISyntaxException {
+ parcourirModel(genModel(4), 4);
+ }
+
+ @Test
+ public void testMerge5() throws URISyntaxException {
+ parcourirModel(genModel(5), 4);
+ }
+
+ @Test
+ public void testMerge6() throws URISyntaxException {
+ parcourirModel(genModel(6), 4);
+ }
+
+ protected ObjectModel genModel(int num) throws URISyntaxException {
+ if (log.isDebugEnabled()) {
+ log.debug("\n\n============================================\n\t\ttestMerge" + num + "\n============================================");
+ }
+// ObjectModelGenerator generator = new ObjectModelGenerator();
+ File[] files = new File[num];
+ for (int j = 1; j < (num + 1); j++) {
+ URL url = Resource.getURL("models/objectmodel/security" + j + ".objectmodel");
+ files[j - 1] = new File(url.toURI());
+ }
+
+ ObjectModelReader reader = new ObjectModelReader();
+ ObjectModel objectModel = reader.read(files);
+ return objectModel;
+
+// generator.generate(files, new File("target"));
+// return generator.getModel();
+ }
+
+ protected void parcourirModel(ObjectModel model, int expectedSize) {
+ Collection<ObjectModelClass> classes = model.getClasses();
+ Assert.assertEquals(expectedSize, classes.size());
+ if (!log.isDebugEnabled()) {
+ return;
+ }
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("\n:::: model tag: ").append(model.getTagValues());
+ for (Object o3 : classes) {
+ ObjectModelClass clazz = (ObjectModelClass) o3;
+ buffer.append("\n********* Class : ").append(clazz.getQualifiedName());
+ buffer.append("\n--- Attributs :");
+ for (Object o2 : clazz.getAttributes()) {
+ buffer.append("\n\t").append(o2);
+ }
+ buffer.append("\n--- Operations :");
+ for (Object o1 : clazz.getOperations()) {
+ buffer.append("\n\t").append(o1);
+ }
+ buffer.append("\n--- Interfaces :");
+ for (Object o : clazz.getInterfaces()) {
+ buffer.append("\n\t").append(o);
+ }
+ buffer.append("\n--- Superclasses :");
+ for (Object o : clazz.getSuperclasses()) {
+ buffer.append("\n\t").append(o);
+ }
+ }
+ log.debug(buffer.toString());
+ }
+}
Property changes on: trunk/eugene/src/test/java/org/nuiton/eugene/models/object/ModelMergeTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/eugene/src/test/java/org/nuiton/eugene/models/object/ObjectModelGeneratorTest.java (from rev 769, trunk/eugene/src/test/java/org/nuiton/eugene/ObjectModelGeneratorTest.java)
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/models/object/ObjectModelGeneratorTest.java (rev 0)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/models/object/ObjectModelGeneratorTest.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -0,0 +1,98 @@
+/* *##%
+ * EUGene :: 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.object;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.nuiton.eugene.models.object.ObjectModelGenerator;
+import org.nuiton.eugene.models.object.xml.ObjectModelClassImpl;
+import org.nuiton.eugene.models.object.xml.ObjectModelElementImpl;
+
+/**
+ * Test des fonctions de ObjectModelGenerator.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class ObjectModelGeneratorTest {
+
+ @Test
+ public void testCanGenerate() {
+
+ ObjectModelGenerator generator = new ObjectModelGenerator();
+
+ // test with null generated list
+ Assert.assertTrue(generator.canGenerateElement(new ObjectModelElementImpl()));
+ Assert.assertTrue(generator.canGenerateElement(new ObjectModelClassImpl()));
+
+ List<String> generatedPackages = new ArrayList<String>();
+ generatedPackages.add("org.nuiton.eugene");
+
+ generator.setGeneratedPackages(generatedPackages);
+
+ // Still true
+ Assert.assertTrue(generator.canGenerateElement(new ObjectModelElementImpl()));
+ // become false
+ Assert.assertFalse(generator.canGenerateElement(new ObjectModelClassImpl()));
+
+ ObjectModelClassImpl testClass = new ObjectModelClassImpl();
+ testClass.setPackage("org.nuiton.eugene");
+ Assert.assertTrue(generator.canGenerateElement(testClass));
+
+ testClass.setPackage("org.nuiton");
+ Assert.assertFalse(generator.canGenerateElement(testClass));
+
+ testClass.setPackage("org.nuiton.eugene.entities");
+ Assert.assertTrue(generator.canGenerateElement(testClass));
+
+ testClass.setPackage("org.nuiton.eugene2");
+ Assert.assertFalse(generator.canGenerateElement(testClass));
+
+ testClass.setPackage("org.nuiton.eugene2.entities");
+ Assert.assertFalse(generator.canGenerateElement(testClass));
+
+ // test avec les generators recursifs
+ // sans faire de set sur le fils
+ ObjectModelGenerator childGenerator = new ObjectModelGenerator(generator);
+
+ testClass.setPackage("org.nuiton.eugene");
+ Assert.assertTrue(childGenerator.canGenerateElement(testClass));
+
+ testClass.setPackage("org.nuiton");
+ Assert.assertFalse(childGenerator.canGenerateElement(testClass));
+
+ testClass.setPackage("org.nuiton.eugene.entities");
+ Assert.assertTrue(childGenerator.canGenerateElement(testClass));
+
+ testClass.setPackage("org.nuiton.eugene2");
+ Assert.assertFalse(childGenerator.canGenerateElement(testClass));
+
+ testClass.setPackage("org.nuiton.eugene2.entities");
+ Assert.assertFalse(childGenerator.canGenerateElement(testClass));
+
+ }
+}
Property changes on: trunk/eugene/src/test/java/org/nuiton/eugene/models/object/ObjectModelGeneratorTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Copied: trunk/eugene/src/test/java/org/nuiton/eugene/models/object/XMI12ToObjectModelTest.java (from rev 769, trunk/eugene/src/test/java/org/nuiton/eugene/xmi/objectmodel/XMI12ToObjectModelTest.java)
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/models/object/XMI12ToObjectModelTest.java (rev 0)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/models/object/XMI12ToObjectModelTest.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -0,0 +1,236 @@
+/* *##%
+ * EUGene :: 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.object;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import java.util.List;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.nuiton.util.Resource;
+import org.nuiton.util.ResourceResolver;
+
+/**
+ * Test de la feuille de style "xmi1.2ToObjectModel.xsl"
+ * sur l'exemple isis-fish.xmi
+ *
+ * @author chatellier
+ * @version $Revision: 1.0 $
+ *
+ * Last update : $Date: 18 févr. 2009 $
+ * By : $Author: chatellier $
+ */
+public class XMI12ToObjectModelTest {
+
+ protected File destinationDirectory;
+
+ @Before
+ public void setUp() {
+ destinationDirectory = new File("target", "xmi");
+ destinationDirectory.mkdirs();
+ }
+
+ /**
+ * Apply XSLT Transformation.
+ *
+ * @param xmiFile
+ * @param modelFile
+ * @return transformed file
+ * @throws IOException
+ * @throws TransformerException
+ */
+ protected File transformXMI(File xmiFile, String modelFile)
+ throws IOException, TransformerException {
+ TransformerFactory factory = TransformerFactory.newInstance();
+
+ URL xsl = Resource.getURL("xmi1.2ToObjectModel.xsl");
+
+ File result = new File(destinationDirectory, modelFile);
+
+ Transformer transformer = factory.newTransformer(new StreamSource(xsl
+ .openStream()));
+
+ transformer.setURIResolver(new ResourceResolver());
+
+ transformer.transform(new StreamSource(xmiFile), new StreamResult(
+ new FileOutputStream(result)));
+
+ return result;
+ }
+
+ /**
+ * Load model into memory.
+ *
+ * @param modelFile
+ * @return object model
+ */
+ protected ObjectModel loadModel(File modelFile) {
+ ObjectModelGenerator generator = new ObjectModelGenerator();
+ generator.setOverwrite(true);
+ generator.generate(new File[] { modelFile }, new File("output"));
+ ObjectModel objectModel = generator.getModel();
+ return objectModel;
+ }
+
+ /**
+ * Apply XSL stylesheet on a topcased model.
+ * And make test on it.
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ @Test
+ public void testXSLIsis() throws URISyntaxException, IOException,
+ TransformerException {
+
+ File xmiFile = new File(Resource.getURL("xmi/1.2/isis-fish.xmi")
+ .toURI());
+
+ File objectModelFile = transformXMI(xmiFile, "isis-fish.objectmodel");
+
+ ObjectModel model = loadModel(objectModelFile);
+
+ Assert.assertNotNull(model);
+ Assert.assertEquals("IsisFish", model.getName());
+ Assert.assertEquals(62, model.getClassifiers().size());
+ }
+
+ /**
+ * Apply XSL stylesheet on a topcased model.
+ * And make test on it.
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ @Test
+ public void testXSLTopia() throws URISyntaxException, IOException,
+ TransformerException {
+
+ File xmiFile = new File(Resource.getURL("xmi/1.2/topiatest.xmi")
+ .toURI());
+
+ File objectModelFile = transformXMI(xmiFile, "topiatest.objectmodel");
+
+ ObjectModel model = loadModel(objectModelFile);
+
+ // Test for model version
+ Assert.assertEquals("1.2",model.getVersion());
+
+ Assert.assertNotNull(model);
+ Assert.assertEquals("TopiaTest", model.getName());
+ Assert.assertEquals(22, model.getClassifiers().size());
+
+ // Test for aggregation attribute (relation)
+ ObjectModelClass personneClass = model.getClass("org.nuiton.topiatest.Personne");
+ Assert.assertNotNull(personneClass);
+ ObjectModelAttribute addressAttr = personneClass.getAttribute("address");
+ Assert.assertNotNull(addressAttr);
+ Assert.assertTrue(addressAttr.isAggregate());
+
+ // Test for inner class
+ ObjectModelClass storeClass = model.getClass("org.nuiton.topiatest.Store");
+ Assert.assertNotNull(storeClass);
+ List<ObjectModelClassifier> inners = (List<ObjectModelClassifier>) storeClass.getInnerClassifiers();
+ Assert.assertNotNull(inners);
+ Assert.assertEquals(inners.size(), 1);
+ ObjectModelClass rowClass = (ObjectModelClass) inners.get(0);
+ Assert.assertNotNull(rowClass);
+ Assert.assertEquals(rowClass.getDeclaringElement().getName(), "Store");
+ }
+
+ /**
+ * Apply XSL stylesheet on an Argouml model.
+ * And make test on it.
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ @Test
+ public void testXSLDependency() throws URISyntaxException, IOException,
+ TransformerException {
+
+ File xmiFile = new File(Resource.getURL("xmi/1.2/dependency.xmi")
+ .toURI());
+
+ File objectModelFile = transformXMI(xmiFile, "dependency.objectmodel");
+
+ ObjectModel model = loadModel(objectModelFile);
+
+ Assert.assertNotNull(model);
+ Assert.assertEquals("DependencyTest", model.getName());
+ Assert.assertEquals(4, model.getClassifiers().size());
+
+ int nbDependencies = 0;
+ for (ObjectModelClassifier classifier : model.getClassifiers()) {
+ nbDependencies += classifier.getDependencies().size();
+ for (ObjectModelDependency dependency : classifier.getDependencies()) {
+ Assert.assertNotNull(dependency.getSupplier());
+ }
+ }
+
+ Assert.assertEquals(4,nbDependencies);
+ }
+
+ /**
+ * Apply XSL stylesheet on an Argouml model.
+ * And make test on it.
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ @Test
+ public void testXSLEnumeration() throws URISyntaxException, IOException,
+ TransformerException {
+
+ File xmiFile = new File(Resource.getURL("xmi/1.2/enumeration.xmi")
+ .toURI());
+
+ File objectModelFile = transformXMI(xmiFile, "enumeration.objectmodel");
+
+ ObjectModel model = loadModel(objectModelFile);
+
+ Assert.assertNotNull(model);
+ Assert.assertEquals("EnumerationTest", model.getName());
+ Assert.assertEquals(1, model.getEnumerations().size());
+
+ for (ObjectModelEnumeration enumeration : model.getEnumerations()) {
+ // 1 seule énumeration avec 3 literals et 2 opérations
+ Assert.assertNotNull(enumeration.getQualifiedName());
+ Assert.assertEquals(3,enumeration.getLiterals().size());
+ Assert.assertEquals(2, enumeration.getOperations().size());
+ }
+ }
+
+}
Copied: trunk/eugene/src/test/java/org/nuiton/eugene/models/object/XMI21ToObjectModelTest.java (from rev 769, trunk/eugene/src/test/java/org/nuiton/eugene/xmi/objectmodel/XMI21ToObjectModelTest.java)
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/models/object/XMI21ToObjectModelTest.java (rev 0)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/models/object/XMI21ToObjectModelTest.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -0,0 +1,559 @@
+/* *##%
+ * EUGene :: 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.object;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.nuiton.util.Resource;
+import org.nuiton.util.ResourceResolver;
+
+
+/**
+ * Test de la feuille de style "xmi2.1ToObjectModel.xsl"
+ * sur l'exemple TestXMI21.uml
+ *
+ * @author chatellier
+ * @version $Revision: 1.0 $
+ *
+ * Last update : $Date: 18 févr. 2009 $
+ * By : $Author: chatellier $
+ */
+public class XMI21ToObjectModelTest {
+
+ protected File destinationDirectory;
+
+ @Before
+ public void setUp() {
+ destinationDirectory = new File("target", "xmi");
+ destinationDirectory.mkdirs();
+ }
+
+ /**
+ * Apply XSLT Transformation.
+ *
+ * @param xmiFile
+ * @return transformed file
+ * @throws IOException
+ * @throws TransformerException
+ */
+ protected File transformXMI(File xmiFile, String outModel)
+ throws IOException, TransformerException {
+ TransformerFactory factory = TransformerFactory.newInstance();
+
+ URL xsl = Resource.getURL("xmi2.1ToObjectModel.xsl");
+
+ File result = new File(destinationDirectory, outModel);
+
+ Transformer transformer = factory.newTransformer(new StreamSource(xsl
+ .openStream()));
+
+ String basePath = xmiFile.getParent();
+ transformer.setURIResolver(new ResourceResolver(basePath));
+
+ transformer.transform(new StreamSource(xmiFile), new StreamResult(
+ new FileOutputStream(result)));
+
+ return result;
+ }
+
+ /**
+ * Load model into memory.
+ *
+ * @param modelFile
+ * @return object model
+ */
+ protected ObjectModel loadModel(File modelFile) {
+ ObjectModelGenerator generator = new ObjectModelGenerator();
+ generator.setOverwrite(true);
+ generator.generate(new File[] { modelFile }, new File("output"));
+ ObjectModel objectModel = generator.getModel();
+ return objectModel;
+ }
+
+ /**
+ * Apply xslt on xmi model, and load it.
+ *
+ * @param modelName model to load
+ *
+ * @throws URISyntaxException
+ * @throws TransformerException
+ * @throws IOException
+ */
+ protected ObjectModel xmiToObjectModel(String modelName) throws URISyntaxException, IOException, TransformerException {
+ File xmiFile = new File(Resource.getURL("xmi/2.1/" + modelName + ".uml")
+ .toURI());
+
+ File objectModelFile = transformXMI(xmiFile, modelName + ".objectmodel");
+
+ ObjectModel model = loadModel(objectModelFile);
+ return model;
+ }
+
+ /**
+ * Apply XSL stylesheet on a topcased model.
+ * And make test on it.
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ @Test
+ public void testXSLTestXMI21() throws URISyntaxException, IOException,
+ TransformerException {
+
+ ObjectModel model = xmiToObjectModel("TestXMI21");
+
+ assertNotNull(model);
+ assertEquals("XMITest21", model.getName());
+ //FIXME check there is an xmi enumeration since we changed enumeration to classifier
+// assertEquals(15, model.getClassifiers().size());
+ assertEquals(16, model.getClassifiers().size());
+
+ // ClassB
+ ObjectModelClass clazzB = model.getClass("org.nuiton.eugene.test21.ClassB");
+ assertNotNull(clazzB);
+ ObjectModelAttribute attrCost = clazzB.getAttribute("cost");
+ assertNotNull(attrCost);
+ assertEquals("Cost attribute comment", attrCost.getTagValue("documentation"));
+
+ // ClassA
+ ObjectModelClass clazzA = model.getClass("org.nuiton.eugene.test21.ClassA");
+ assertNotNull(clazzA);
+ ObjectModelAttribute attrName = clazzA.getAttribute("name");
+ assertNotNull(attrName);
+ assertEquals(2, attrName.getMinMultiplicity());
+ assertEquals(-1, attrName.getMaxMultiplicity());
+// assertTrue(attrName.isOrdered());
+// assertTrue(attrName.isUnique());
+ }
+
+ /**
+ * Apply XSL stylesheet on a topcased model.
+ * And make test on it.
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ @Test
+ public void testXSLVpod() throws URISyntaxException, IOException,
+ TransformerException {
+
+ ObjectModel model = xmiToObjectModel("vpod");
+
+ assertNotNull(model);
+ assertEquals("org::sharengo::s4a::storage::http::vpod", model.getName());
+ assertEquals(4, model.getClassifiers().size());
+
+ // ClassB
+ ObjectModelClass clazzVpodMappingDao = model.getClass("daos.VpodMappingDao");
+ assertNotNull(clazzVpodMappingDao);
+ assertTrue(clazzVpodMappingDao.hasStereotype("Dao"));
+ List<ObjectModelOperation> opFindByVpodId = new ArrayList<ObjectModelOperation>();
+ opFindByVpodId.addAll(clazzVpodMappingDao.getOperations("findByVpodId"));
+ assertEquals("entities.VpodMapping", opFindByVpodId.get(0).getReturnType());
+ List<ObjectModelParameter> opFindByVpodIdParams = new ArrayList<ObjectModelParameter>();
+ opFindByVpodIdParams.addAll(opFindByVpodId.get(0).getParameters());
+ assertEquals("String", opFindByVpodIdParams.get(0).getType());
+ }
+
+ /**
+ * Apply XSL stylesheet on a topcased model.
+ * And make test on it.
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ @Test
+ public void testXSLWithStereotype() throws URISyntaxException, IOException,
+ TransformerException {
+
+ ObjectModel model = xmiToObjectModel("cmsLink");
+
+ assertNotNull(model);
+ assertEquals("org::sharengo::utils::container::link", model.getName());
+ //FIXME check there is an xmi enumeration since we changed enumeration to classifier
+ assertEquals(9, model.getClassifiers().size());
+// assertEquals(8, model.getClassifiers().size());
+
+ // LinkEntity
+ ObjectModelClass clazzLinkEntity = model.getClass("org.sharengo.utils.container.link.entities.LinkEntity");
+ assertNotNull(clazzLinkEntity);
+ assertTrue(clazzLinkEntity.hasStereotype("Entity"));
+ ObjectModelAttribute attrDefinition = clazzLinkEntity.getAttribute("target");
+ assertNotNull(attrDefinition);
+ assertTrue(attrDefinition.hasStereotype("Embedded"));
+
+ // LinkEntity
+ ObjectModelClass clazzLinkSrv = model.getClass("org.sharengo.utils.container.link.services.LinkSrv");
+ assertNotNull(clazzLinkSrv);
+ assertTrue(clazzLinkSrv.hasStereotype("Service"));
+ List<ObjectModelOperation> opFindAllByContent = new ArrayList<ObjectModelOperation>();
+ opFindAllByContent.addAll(clazzLinkSrv.getOperations("findAllByContent"));
+ assertEquals(1, opFindAllByContent.size());
+ assertTrue(opFindAllByContent.get(0).hasStereotype("Remote"));
+ }
+
+ @Test
+ public void testExtractCmsCore() throws Exception {
+
+ ObjectModel model = xmiToObjectModel("cmsCore");
+ assertNotNull(model);
+
+ // There was a problem with sub package
+ ObjectModelClass clazzFacetViewSrv = model.getClass("org.sharengo.cms.core.services.facet.FacetViewSrv");
+ assertNotNull(clazzFacetViewSrv);
+ assertEquals(11, clazzFacetViewSrv.getOperations().size());
+
+ // Test attribute type FQN
+ ObjectModelClass clazzContentDefSearchDto = model.getClass("org.sharengo.cms.core.dtos.ContentDefSearchDto");
+ assertNotNull(clazzContentDefSearchDto);
+ ObjectModelAttribute attrFromDate = clazzContentDefSearchDto.getAttribute("fromDate");
+ assertNotNull(attrFromDate);
+ assertEquals("Date", attrFromDate.getType());
+ ObjectModelAttribute attrContentDefId = clazzContentDefSearchDto.getAttribute("contentDefId");
+ assertNotNull(attrContentDefId);
+ assertEquals("String", attrContentDefId.getType());
+ ObjectModelAttribute attrAttributes = clazzContentDefSearchDto.getAttribute("attributes");
+ assertNotNull(attrAttributes);
+ assertEquals("org.sharengo.cms.core.dtos.AttributeSearchDto", attrAttributes.getType());
+
+ ObjectModelClass clazzContentDefDto = model.getClass("org.sharengo.cms.core.dtos.AttributeDef");
+ assertNotNull(clazzContentDefDto);
+ ObjectModelAttribute attrIdContentDef = clazzContentDefDto.getAttribute("idContentDef");
+ assertNotNull(attrIdContentDef);
+ assertEquals("String", attrIdContentDef.getType());
+ }
+
+ /**
+ * Apply XSL stylesheet on a topcased model.
+ * And make test on embedded primitive type
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ @Test
+ public void testXSLTestXMI21EmbeddedPrimitiveType() throws URISyntaxException, IOException,
+ TransformerException {
+
+ ObjectModel model = xmiToObjectModel("TestXMI21");
+
+ assertNotNull(model);
+ assertEquals("XMITest21", model.getName());
+
+ // ClassB
+ ObjectModelClass clazzB = model.getClass("org.nuiton.eugene.test21.ClassB");
+ assertNotNull(clazzB);
+
+ //primitiveType double
+ ObjectModelAttribute attrDouble = clazzB.getAttribute("double");
+ assertNotNull(attrDouble);
+ assertEquals("org.nuiton.eugene.test21.double", attrDouble.getType());
+
+ // ClassC
+ ObjectModelClass clazzC = model.getClass("org.nuiton.eugene.test21.ClassC");
+ assertNotNull(clazzC);
+
+ //dataType formula
+ ObjectModelAttribute attrFormula = clazzC.getAttribute("formula");
+ assertNotNull(attrFormula);
+ assertEquals("org.codelutin.types.Formula", attrFormula.getType());
+
+ }
+
+ /**
+ * Apply XSL stylesheet on a topcased model.
+ * And make test on embedded primitive type
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ @Test
+ public void testXSLTestXMI21MultiplicityClass() throws URISyntaxException, IOException,
+ TransformerException {
+
+ ObjectModel model = xmiToObjectModel("TestXMI21");
+
+ // ClassB
+ ObjectModelClass multiClazz = model.getClass("org.nuiton.eugene.test21.MultiplicityClass");
+
+ // strings
+ ObjectModelAttribute strings = multiClazz.getAttribute("strings");
+ assertNotNull(strings);
+ assertEquals("String", strings.getType());
+ assertEquals(1, strings.getMinMultiplicity());
+ assertEquals(-1, strings.getMaxMultiplicity());
+ assertTrue(strings.isUnique());
+ assertFalse(strings.isOrdered());
+
+ // doubles
+ ObjectModelAttribute doubles = multiClazz.getAttribute("doubles");
+ assertNotNull(doubles);
+ assertEquals("org.nuiton.eugene.test21.double", doubles.getType());
+ assertEquals(1, doubles.getMinMultiplicity());
+ assertEquals(5, doubles.getMaxMultiplicity());
+ assertTrue(doubles.isUnique());
+ assertTrue(doubles.isOrdered());
+
+ // dataTypes
+ ObjectModelAttribute dataTypes = multiClazz.getAttribute("dataTypes");
+ assertNotNull(dataTypes);
+ assertEquals("org.nuiton.eugene.test21.DataType1", dataTypes.getType());
+ assertEquals(0, dataTypes.getMinMultiplicity());
+ assertEquals(-1, dataTypes.getMaxMultiplicity());
+ assertFalse(dataTypes.isUnique());
+ assertTrue(dataTypes.isOrdered());
+
+ // getStrings
+ ObjectModelOperation op = multiClazz.getOperations("getStrings").iterator().next();
+ assertNotNull(op);
+ assertEquals("String", op.getReturnType());
+ assertNotNull(op.getReturnParameter());
+ assertEquals("String", op.getReturnParameter().getType());
+ assertEquals(1, op.getReturnParameter().getMinMultiplicity());
+ assertEquals(-1, op.getReturnParameter().getMaxMultiplicity());
+ assertTrue(op.getReturnParameter().isUnique());
+ assertTrue(op.getReturnParameter().isOrdered());
+
+
+ // getDoubles
+ op = multiClazz.getOperations("getDoubles").iterator().next();
+ assertNotNull(op);
+ assertEquals("org.nuiton.eugene.test21.double", op.getReturnType());
+ assertNotNull(op.getReturnParameter());
+ assertEquals("org.nuiton.eugene.test21.double", op.getReturnParameter().getType());
+ assertEquals(2, op.getReturnParameter().getMinMultiplicity());
+ assertEquals(-1, op.getReturnParameter().getMaxMultiplicity());
+ assertFalse(op.getReturnParameter().isUnique());
+ assertTrue(op.getReturnParameter().isOrdered());
+
+ // getDataTypes
+ op = multiClazz.getOperations("getDataTypes").iterator().next();
+ assertNotNull(op);
+ assertEquals("org.nuiton.eugene.test21.DataType1", op.getReturnType());
+ assertNotNull(op.getReturnParameter());
+ assertEquals("org.nuiton.eugene.test21.DataType1", op.getReturnParameter().getType());
+ assertEquals(0, op.getReturnParameter().getMinMultiplicity());
+ assertEquals(-1, op.getReturnParameter().getMaxMultiplicity());
+ assertTrue(op.getReturnParameter().isUnique());
+ assertFalse(op.getReturnParameter().isOrdered());
+
+ // addAndGetAll
+ op = multiClazz.getOperations("addAndGetAll").iterator().next();
+ assertNotNull(op);
+ assertEquals("org.nuiton.eugene.test21.DataType1", op.getReturnType());
+ assertNotNull(op.getReturnParameter());
+ assertEquals("org.nuiton.eugene.test21.DataType1", op.getReturnParameter().getType());
+ assertEquals(3, op.getReturnParameter().getMinMultiplicity());
+ assertEquals(19, op.getReturnParameter().getMaxMultiplicity());
+ assertTrue(op.getReturnParameter().isUnique());
+ assertFalse(op.getReturnParameter().isOrdered());
+
+ // param strings
+ ObjectModelParameter param = findParameter(op, "strings");
+ assertNotNull(param);
+ assertEquals("String", param.getType());
+ assertEquals(1, param.getMinMultiplicity());
+ assertEquals(-1, param.getMaxMultiplicity());
+ assertTrue(param.isUnique());
+ assertFalse(param.isOrdered());
+
+ // param doubles
+ param = findParameter(op, "doubles");
+ assertNotNull(param);
+ assertEquals("org.nuiton.eugene.test21.double", param.getType());
+ assertEquals(5, param.getMinMultiplicity());
+ assertEquals(-1, param.getMaxMultiplicity());
+ assertTrue(param.isUnique());
+ assertTrue(param.isOrdered());
+
+ // param dataTypes
+ param = findParameter(op, "dataTypes");
+ assertNotNull(param);
+ assertEquals("org.nuiton.eugene.test21.DataType1", param.getType());
+ assertEquals(1, param.getMinMultiplicity());
+ assertEquals(18, param.getMaxMultiplicity());
+ assertFalse(param.isUnique());
+ assertTrue(param.isOrdered());
+
+ }
+
+ private ObjectModelParameter findParameter(ObjectModelOperation op, String name) {
+ for (ObjectModelParameter param : op.getParameters()) {
+ if (name.equals(param.getName())) {
+ return param;
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * Apply XSL stylesheet on a topcased model.
+ * And make test on embedded primitive type
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ @Test
+ public void testXSLTestXMI21StaticAndDefaultValueAttribute() throws URISyntaxException, IOException,
+ TransformerException {
+
+ ObjectModel model = xmiToObjectModel("TestXMI21");
+
+ // StaticClass
+ ObjectModelClass multiClazz = model.getClass("org.nuiton.eugene.test21.StaticClass");
+
+ // strings
+ ObjectModelAttribute strings = multiClazz.getAttribute("azerty");
+ assertNotNull(strings);
+ assertEquals("String", strings.getType());
+ assertTrue(strings.isStatic());
+ assertEquals("azerty",strings.getDefaultValue());
+
+ // static operation
+ ObjectModelClass classD = model.getClass("org.nuiton.eugene.test21.ClassD");
+ assertNotNull(classD);
+ List<ObjectModelOperation> operations = (List<ObjectModelOperation>)classD.getOperations("getInstance");
+ assertEquals(operations.size(), 1);
+ assertTrue(operations.get(0).isStatic());
+ }
+
+ /**
+ * Apply XSL stylesheet on a topcased model.
+ * And make test on embedded primitive type
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ @Test
+ public void testTestXMI21SuperClasses() throws URISyntaxException, IOException,
+ TransformerException {
+
+ ObjectModel model = xmiToObjectModel("TestXMI21");
+
+ // StaticClass
+ ObjectModelClass multiClazz = model.getClass("org.nuiton.eugene.test21.StaticClass");
+
+ // SubClass
+ ObjectModelClass subClazz = model.getClass("org.nuiton.eugene.test21.SubClass");
+ assertNotNull(subClazz);
+ assertNotNull(subClazz.getSuperclasses());
+ assertEquals(1, subClazz.getSuperclasses().size());
+ assertEquals(multiClazz, subClazz.getSuperclasses().iterator().next());
+
+ // TODO test attributes
+ }
+
+ /**
+ * Apply XSL stylesheet on a topcased model.
+ * Test for InnerClasses
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ @Test
+ public void testTestXMI21InnerClasses() throws URISyntaxException, IOException,
+ TransformerException {
+
+ ObjectModel model = xmiToObjectModel("TestXMI21");
+
+ // OuterClass
+ ObjectModelClass outer = model.getClass("org.nuiton.eugene.test21.OuterClass");
+
+ List<ObjectModelClassifier> inners = (List<ObjectModelClassifier>)outer.getInnerClassifiers();
+ assertNotNull(inners);
+ assertEquals(inners.size(), 1);
+
+ // InnerClass
+ ObjectModelClass inner = (ObjectModelClass) inners.get(0);
+ assertNotNull(inner);
+ assertNotNull(inner.getDeclaringElement());
+ assertEquals(inner.getDeclaringElement().getName(), "OuterClass");
+ assertTrue(inner.isInner());
+ }
+
+ /**
+ * Apply XSL stylesheet on TestXMI21
+ * Check documentation tags on model, class, attribute, operation and enumerations
+ */
+ @Test
+ public void testTestXMI21Documentation() throws URISyntaxException, IOException,
+ TransformerException {
+
+ ObjectModel model = xmiToObjectModel("TestXMI21");
+
+ assertNotNull(model);
+ assertEquals("XMITest21", model.getName());
+ assertEquals("model doc!", model.getTagValue("documentation"));
+
+ // ClassC
+ ObjectModelClass clazzC = model.getClass("org.nuiton.eugene.test21.ClassC");
+ assertNotNull(clazzC);
+ assertEquals("Class C Comment", clazzC.getDocumentation());
+
+ ObjectModelAttribute attrCost = clazzC.getAttribute("formula");
+ assertNotNull(attrCost);
+ assertEquals("azerty", attrCost.getDocumentation());
+
+ ObjectModelOperation opLaunchExpression = clazzC.getOperations("launchException").iterator().next();
+ assertNotNull(opLaunchExpression);
+ assertEquals("launchExcep comment", opLaunchExpression.getDocumentation());
+
+ assertFalse(model.getEnumerations().isEmpty());
+
+ ObjectModelEnumeration myenum = model.getEnumeration("org.nuiton.eugene.test21.MyEnumeration");
+ assertNotNull(myenum);
+ assertEquals("MyEnumeration is just a simply enumeration in order to test documentation in enumeration.", myenum.getDocumentation());
+
+
+ // ClassB
+ ObjectModelClass clazzB = model.getClass("org.nuiton.eugene.test21.ClassB");
+ assertNotNull(clazzB);
+ assertEquals("This is some documentation\non multiple lines !\n\nVery hard to do !", clazzB.getDocumentation());
+
+ }
+
+}
Modified: trunk/eugene/src/test/java/org/nuiton/eugene/models/object/xml/ObjectModelBuilderTest.java
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/models/object/xml/ObjectModelBuilderTest.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/models/object/xml/ObjectModelBuilderTest.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -29,16 +29,8 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.*;
import static org.junit.Assert.*;
-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.ObjectModelClassifier;
-import org.nuiton.eugene.models.object.ObjectModelElement;
-import org.nuiton.eugene.models.object.ObjectModelModifier;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-import org.nuiton.eugene.models.object.ObjectModelParameter;
/**
* ObjectModelBuilder
Modified: trunk/eugene/src/test/java/org/nuiton/eugene/models/state/StateModelTest.java
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/models/state/StateModelTest.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/models/state/StateModelTest.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -28,7 +28,6 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.nuiton.eugene.StateModelReader;
import org.nuiton.util.Resource;
/**
Modified: trunk/maven-eugene-plugin/src/it/smart-generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java
===================================================================
--- trunk/maven-eugene-plugin/src/it/smart-generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/maven-eugene-plugin/src/it/smart-generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanGenerator.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -33,7 +33,6 @@
package org.nuiton.eugene.test.generator;
import org.apache.commons.lang.StringUtils;
-import static org.nuiton.eugene.test.generator.TopiaGeneratorUtil.TAG_ANNOTATION;
import java.io.File;
import java.io.IOException;
@@ -46,9 +45,11 @@
import java.util.List;
import java.util.Set;
+import java.util.HashSet;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.ObjectModelGenerator;
+import org.nuiton.eugene.models.object.ObjectModelGenerator;
import org.nuiton.eugene.GeneratorUtil;
import org.nuiton.eugene.ImportsManager;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
@@ -58,16 +59,20 @@
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
* @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.test.generator.BeanGenerator"
*/
public class BeanGenerator extends ObjectModelGenerator {
-
+ /** Tag pour ajouter une annotation à un champ */
+ public static final String TAG_ANNOTATION = "annotation";
+ /** 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";
/**
* Logger for this class
*/
@@ -84,18 +89,18 @@
@Override
public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException {
- if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_BEAN) &&
- !clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
+ if (!clazz.hasStereotype(STEREOTYPE_BEAN) &&
+ !clazz.hasStereotype(STEREOTYPE_DTO)) {
return;
}
//
// première phase : calcul des variables
//
- String copyright = TopiaGeneratorUtil.getCopyright(model);
+ String copyright = "";
String clazzName = clazz.getName();
String abstractStr = isAbstract(clazz) ? " abstract " : " ";
boolean needGetEntityMethod = false;
- boolean generateToString = TopiaGeneratorUtil.generateToString(clazz, model);
+ boolean generateToString = true;
ImportsManager imports = new ImportsManager();
@@ -116,14 +121,14 @@
}
}
// Add Serializable implements for DTO generation
- if (clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
+ if (clazz.hasStereotype(STEREOTYPE_DTO)) {
imports.addImport(Serializable.class);
if (!implInterface.isEmpty()) {
implInterface += ", ";
}
implInterface += Serializable.class.getName();
}
- String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", clazz, model);
+ String svUID = "1L";
List<ObjectModelAttribute> attributes = new ArrayList<ObjectModelAttribute>();
List<ObjectModelAttribute> multipleAttr = new ArrayList<ObjectModelAttribute>();
@@ -142,7 +147,7 @@
if (model.hasClass(attr.getType())) {
attrEntity = model.getClass(attr.getType());
}
- boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY));
+ boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(STEREOTYPE_ENTITY));
needGetEntityMethod |= isEntity;
if (attr.isOrdered()) {
needListInImport = true;
@@ -174,7 +179,7 @@
imports.addImport(org.apache.commons.lang.builder.ToStringBuilder.class);
}
- boolean sortAttribute = TopiaGeneratorUtil.sortAttribute(clazz, model);
+ boolean sortAttribute = true;
if (sortAttribute) {
Comparator<ObjectModelAttribute> comp = new Comparator<ObjectModelAttribute>(){
@@ -190,7 +195,7 @@
// seconde phase : génération
//
- if (TopiaGeneratorUtil.notEmpty(copyright)) {
+ if (StringUtils.isNotEmpty(copyright)) {
/*{<%=copyright%>
}*/
}
@@ -323,7 +328,7 @@
continue;
}
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
+ if (GeneratorUtil.hasDocumentation(attr)) {
/*{ /**
* <%=attr.getDocumentation()%>
*)
@@ -338,7 +343,7 @@
String attrVisibility = attr.getVisibility();
String attrType = attr.getType();
if (attr.hasAssociationClass()) {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ String assocAttrName = getAssocAttrName(attr);
attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
attrType = attr.getAssociationClass().getName();
}
@@ -355,6 +360,24 @@
}
}
+ /**
+ * Renvoie le nom de l'attribut de classe d'association en fonction des cas:
+ * Si l'attribut porte le même nom que le type (extrémité inverse de
+ * l'association), on lui ajoute le nom de la classe d'association
+ *
+ * @param attr l'attribut a traiter
+ * @return le nom de l'attribut de classe d'association
+ */
+ public static String getAssocAttrName(ObjectModelAttribute attr) {
+ String typeName = attr.getType().substring(
+ attr.getType().lastIndexOf(".") + 1);
+ String result = attr.getName();
+ if (attr.getName().equalsIgnoreCase(typeName)) {
+ result += StringUtils.capitalize(attr.getAssociationClass().getName());
+ }
+ return result;
+ }
+
protected void generateGetters(Writer output, List<ObjectModelAttribute> attributes) throws IOException {
/*
* Définition des getteurs et setteurs
@@ -368,7 +391,7 @@
String attrName = attr.getName();
String attrType = attr.getType();
if (attr.hasAssociationClass()) {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ String assocAttrName = getAssocAttrName(attr);
attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
attrType = attr.getAssociationClass().getName();
}
@@ -402,7 +425,7 @@
String attrType = attr.getType();
if (attr.hasAssociationClass()) {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ String assocAttrName = getAssocAttrName(attr);
attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
attrType = attr.getAssociationClass().getName();
}
@@ -439,7 +462,7 @@
if (model.hasClass(attr.getType())) {
attrEntity = model.getClass(attr.getType());
}
- boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY));
+ boolean isEntity = (attrEntity != null && attrEntity.hasStereotype("entity"));
/*{ public <%=attrType%> get<%=attrNameCapitalized%>(int index) {
<%=attrType%> o = getChild(<%=attrName%>, index);
return o;
@@ -502,7 +525,7 @@
String opName = op.getName();
/*{ /**
}*/
- if (TopiaGeneratorUtil.hasDocumentation(op)) {
+ if (GeneratorUtil.hasDocumentation(op)) {
String opDocumentation = op.getDocumentation();
/*{ * <%=opName%> : <%=opDocumentation%>
}*/
@@ -591,7 +614,7 @@
private List<ObjectModelAttribute> setAttributesForDTO(ObjectModelClass clazz,
List<ObjectModelAttribute> attributes, ImportsManager imports) {
- if (clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
+ if (clazz.hasStereotype(STEREOTYPE_DTO)) {
if (log.isInfoEnabled()) {
log.info("DTO dependency gestion");
}
@@ -601,7 +624,7 @@
// 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 (supplier.hasStereotype(STEREOTYPE_ENTITY)) {
if (log.isInfoEnabled()) {
log.info("Create primitive and date fields in DTO from Entity : "
+ supplier.getQualifiedName());
@@ -620,4 +643,65 @@
}
return attributes;
}
+
+ 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>();
+
+ 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());
+ }
+
} //BeanGenerator
Modified: trunk/maven-eugene-plugin/src/it/smart-generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java
===================================================================
--- trunk/maven-eugene-plugin/src/it/smart-generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/maven-eugene-plugin/src/it/smart-generate/generators/src/main/java/org/nuiton/eugene/test/generator/BeanTransformer.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -52,8 +52,8 @@
@Override
public void transformFromClass(ObjectModelClass clazz) {
- if (!clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_BEAN) &&
- !clazz.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
+ if (!clazz.hasStereotype(BeanGenerator.STEREOTYPE_BEAN) &&
+ !clazz.hasStereotype(BeanGenerator.STEREOTYPE_DTO)) {
return;
}
@@ -112,7 +112,7 @@
if (getModel().hasClass(attr.getType())) {
attrEntity = getModel().getClass(attr.getType());
}
- boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY));
+ boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(BeanGenerator.STEREOTYPE_ENTITY));
if (isEntity) {
hasEntity = true;
@@ -165,7 +165,7 @@
}
if (attr.hasAssociationClass()) {
- String assocAttrName = TopiaGeneratorUtil.getAssocAttrName(attr);
+ String assocAttrName = BeanGenerator.getAssocAttrName(attr);
attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
attrType = attr.getAssociationClass().getName();
}
@@ -260,11 +260,11 @@
private void createForDTO(ObjectModelClass resultClass, ObjectModelClass inputClass) {
// Add Serializable implements for DTO generation
- if (inputClass.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DTO)) {
+ if (inputClass.hasStereotype(BeanGenerator.STEREOTYPE_DTO)) {
addInterface(resultClass, "java.io.Serializable");
}
- String svUID = TopiaGeneratorUtil.findTagValue("dto-serialVersionUID", inputClass, getModel());
+ String svUID = "1L";
if (svUID != null) {
addConstant(resultClass, "serialVersionUID", "long", svUID, ObjectModelModifier.PUBLIC);
}
Deleted: trunk/maven-eugene-plugin/src/it/smart-generate/generators/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java
===================================================================
--- trunk/maven-eugene-plugin/src/it/smart-generate/generators/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java 2009-12-20 14:45:41 UTC (rev 776)
+++ trunk/maven-eugene-plugin/src/it/smart-generate/generators/src/main/java/org/nuiton/eugene/test/generator/TopiaGeneratorUtil.java 2009-12-20 16:27:20 UTC (rev 777)
@@ -1,948 +0,0 @@
-/* *##%
- * EUGene Test
- * Copyright (C) 2007 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*/
-/*******************************************************************************
- * GeneratorUtil.java
- *
- * Created: 13 déc. 2005
- *
- * @author Arnaud Thimel <thimel(a)codelutin.com>
- *
- * @version $Revision$
- *
- * Mise a jour: $Date$ par : $Author: tchemit $
- */
-package org.nuiton.eugene.test.generator;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.lang.StringUtils;
-import org.nuiton.eugene.Template;
-import org.nuiton.eugene.GeneratorUtil;
-import org.nuiton.eugene.models.Model;
-import org.nuiton.eugene.models.object.ObjectModel;
-import org.nuiton.eugene.models.object.ObjectModelAssociationClass;
-import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelElement;
-import org.nuiton.eugene.models.object.ObjectModelInterface;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-import org.nuiton.eugene.models.object.ObjectModelParameter;
-
-/** Classe regroupant divers méthodes utiles pour la génération des entités */
-public class TopiaGeneratorUtil extends GeneratorUtil {
-
- /** Stéréotype pour les interfaces devant être générées sous forme de facades */
- public final static String STEREOTYPE_FACADE = "facade";
- /** Stéréotype pour les objets devant être générées sous forme d'entités */
- public static final String STEREOTYPE_ENTITY = "entity";
- /** Stéréotype pour les objets devant être générées sous forme de DTO */
- public static final String STEREOTYPE_DTO = "dto";
- /** Stéréotype pour les objets devant être générées sous forme de bean */
- public static final String STEREOTYPE_BEAN = "bean";
- /**
- * Stéréotype pour les interfaces devant être générées sous forme de
- * services
- */
- public static final String STEREOTYPE_SERVICE = "service";
- /** Stéréotype pour les interfaces devant être générées sous forme de DAO */
- public static final String STEREOTYPE_DAO = "dao";
- /** Stéréotype pour les attributs à indexer en base */
- public static final String STEREOTYPE_INDEXED = "indexed";
- /** Stéréotype pour les collections avec unicité */
- public static final String STEREOTYPE_UNIQUE = "unique";
- /** Stéréotype pour les attributs étant des clés primaires */
- public static final String STEREOTYPE_PRIMARYKAY = "primaryKey";
- /** Tag pour le type de persistence */
- public static final String TAG_PERSISTENCE_TYPE = "persistenceType";
- /** Tag pour le nom du champ / entité en BD */
- public static final String TAG_DB_NAME = "dbName";
- /** Tag pour le nom du schema en BD */
- public static final String TAG_SCHEMA_NAME = "dbSchema";
- /** Tag pour la taille du champ en BD */
- public static final String TAG_LENGTH = "length";
- /** Tag pour ajouter une annotation à un champ */
- public static final String TAG_ANNOTATION = "annotation";
- /** Tag pour ajouter specifier le copyright d'un fichier */
- public static final String TAG_COPYRIGHT = "copyright";
- /** Tag pour specfier le type d'acces a un champ */
- public static final String TAG_ACCESS = "access";
- /** Tag pour specfier si on doit générer i18n */
- public static final String TAG_I18N_PREFIX = "i18n";
- /** Tag pour ajouter un attribut dans une clef métier */
- public static final String TAG_NATURAL_ID = "naturalId";
- /** Tag pour specifier si une clef metier est mutable */
- public static final String TAG_NATURAL_ID_MUTABLE = "naturalIdMutable";
- /** Tag pour spécifier la caractèrelazy d'une association multiple */
- public static final String TAG_LAZY = "lazy";
- /** Tag pour spécifier la caractère fetch d'une association multiple */
- public static final String TAG_FETCH = "fetch";
- /** Tag pour spécifier la caractère order-by d'une association multiple */
- public static final String TAG_ORDER_BY = "orderBy";
- /** Tag pour spécifier la caractère not-null d'un attribut */
- public static final String TAG_NOT_NULL = "notNull";
- /** Tag pour spécifier la caractère embed-xml d'une association */
- public static final String TAG_EMBED_XML = "embedXml";
- /**
- * Tag pour configurer l'interface du proxy sur autre chose que l'implementation par defaut.
- *
- * Par defaut :
- * null > generere le proxy sur l'interface de l'implementation
- * Autre valeur :
- * "none" > laisse la configuration par defaut d'hibernate
- */
- public static final String TAG_PROXY_INTERFACE = "hibernateProxyInterface";
- /** Tag pour spécifier le permissions à la création */
- public static final String TAG_SECURITY_CREATE = "securityCreate";
- /** Tag pour spécifier le permissions au chargement */
- public static final String TAG_SECURITY_LOAD = "securityLoad";
- /** Tag pour spécifier le permissions à la mise à jour */
- public static final String TAG_SECURITY_UPDATE = "securityUpdate";
- /** Tag pour spécifier le permissions à la suppression */
- public static final String TAG_SECURITY_DELETE = "securityDelete";
- /** Tag pour specifier de ne pas generer la methode toString */
- public static final String TAG_NOT_GENERATE_TO_STRING = "notGenerateToString";
- /** Tag pour specifier de trier les attributs par nom lors de la generation */
- public static final String TAG_SORT_ATTRIBUTE = "sortAttribute";
- /** Tag pour specfier si on doit générer la methode getOperator dans les daohelpers )*/
- public static final String TAG_GENERATE_OPERATOR_FOR_DAO_HELPER = "generateOperatorForDAOHelper";
- /** Type de persistence Hibernate */
- public static final String PERSISTENCE_TYPE_HIBERNATE = "hibernate";
- /** Type de persistence LDAP */
- public static final String PERSISTENCE_TYPE_LDAP = "ldap";
- /** Type de persistence par défaut (si aucun précisé) */
- public static final String PERSISTENCE_TYPE_DEFAULT = PERSISTENCE_TYPE_HIBERNATE;
- /** Propriété des générateurs indiquant le package par défaut */
- public static final String PROPERTY_DEFAULT_PACKAGE = "defaultPackage";
- /** Le package par défaut si aucun n'est spécifié */
- public static final String DEFAULT_PACKAGE = "org.codelutin.malo";
-
- /**
- * Renvoie le package par défaut pour le générateur donné
- *
- * @param generator le générateur donné
- * @return le package par défaut du générator donné
- */
- public static String getDefaultPackage(Template generator) {
- String packageName = generator.getProperty(PROPERTY_DEFAULT_PACKAGE);
- if (packageName == null || "".equals(packageName)) {
- packageName = DEFAULT_PACKAGE;
- }
- return packageName;
- }
-
-// /**
-// * @see GeneratorUtil#hasDocumentation
-// * @deprecated
-// */
-// @Deprecated
-// public static boolean hasDocumentation(ObjectModelElement element) {
-// return notEmpty(element.getDocumentation());
-// }
-
-// /**
-// * @see GeneratorUtil#notEmpty
-// * @deprecated
-// */
-// @Deprecated
-// public static boolean notEmpty(String s) {
-// return (s != null && !"".equals(s));
-// }
-
- /**
- * Renvoie l'interface DAO associée à la classe passée en paramètre
- *
- * @param clazz la classe à tester
- * @param model le modele utilisé
- * @return l'interface trouvée ou null sinon
- */
- public static ObjectModelInterface getDAOInterface(ObjectModelClass clazz,
- ObjectModel model) {
- for (Object o : model.getInterfaces()) {
- ObjectModelInterface daoInterface = (ObjectModelInterface) o;
- if (daoInterface.getName().equals(clazz.getName() + "DAO")) {
- if (daoInterface.hasStereotype(STEREOTYPE_DAO)) {
- return daoInterface;
- }
- }
- }
- return null;
- }
-
- /**
- * Renvoie le type de persistence pour l'élément donné. Si aucun n'est
- * trouvé, le type par défaut est utilisé
- *
- * @param element l'élément à tester
- * @return le type de persitence pour l'élément donné.
- */
- public static String getPersistenceType(ObjectModelElement element) {
- String tag = element.getTagValue(TAG_PERSISTENCE_TYPE);
- if (tag == null) {
- tag = PERSISTENCE_TYPE_DEFAULT;
- }
- return tag;
- }
-
- public static String getReverseDBName(ObjectModelAttribute attr) {
- if (attr.getReverseAttribute() != null) {
- return getDBName(attr.getReverseAttribute());
- } else {
- return getDBName(attr) + "_id";
- }
- }
-
- /**
- * Renvoie le nom BD de l'élement passé en paramètre. Elle se base sur le
- * tag associé si il existe, sinon sur le nom de l'élément
- *
- * @param element l'élément à tester
- * @return le nom de table
- */
- public static String getDBName(ObjectModelElement element) {
- if (element == null) {
- return null;
- }
- if (notEmpty(element.getTagValue(TAG_DB_NAME))) {
- return element.getTagValue(TAG_DB_NAME);
- }
- return toLowerCaseFirstLetter(element.getName());
- }
-
- /**
- * Cherche et renvoie le schema a utiliser sur cet element, sinon sur le model.
- *
- * @param element l'élément à tester
- * @param model le modele utilisé
- * @return le nom du schema ou null
- */
- public static String getSchemaName(ObjectModelElement element,
- ObjectModel model) {
- return findTagValue(TAG_SCHEMA_NAME, element, model);
- }
-
- /**
- * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model.
- *
- * @param element l'élément à tester
- * @param model le modele utilisé
- * @return le prefix i18n ou <code>null</code> si non spécifié
- */
- public static String getI18nPrefix(ObjectModelElement element,
- ObjectModel model) {
- return GeneratorUtil.findTagValue(TAG_I18N_PREFIX, element, model);
- }
-
- /**
- * Cherche et renvoie le prefixe i18n à utiliser sur cet element, sinon sur le model.
- *
- * @param element l'élément à tester
- * @param model le modele utilisé
- * @return le prefix i18n ou <code>null</code> si non spécifié
- */
- public static boolean shouldgenerateOperatorForDAOHelper(ObjectModelElement element,
- ObjectModel model) {
- String tagValue = GeneratorUtil.findTagValue(TAG_GENERATE_OPERATOR_FOR_DAO_HELPER, element, model);
- boolean generate = GeneratorUtil.notEmpty(tagValue) && Boolean.valueOf(tagValue);
- return generate;
- }
-
- /**
- * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
- *
- * @param clazz la classe à tester
- * @return la liste des attributs de la clef métier ou null si pas de clef métier.
- */
- public static List<String> getNaturalId(ObjectModelClass clazz) {
- String value = clazz.getTagValue(TAG_NATURAL_ID);
- if (value == null || value.trim().isEmpty()) {
- return java.util.Collections.emptyList();
- }
- List<String> result = new ArrayList<String>();
- for (String attribute : value.split(",")) {
- result.add(attribute.trim());
- }
- return result;
- }
-
- /**
- * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
- *
- * @param clazz la classe à tester
- * @param model le modele
- * @return la liste des attributs de la clef métier ou null si pas de clef métier.
- */
- public static boolean generateToString(ObjectModelClass clazz,
- ObjectModel model) {
- String value;
- value = model.getTagValue(TAG_NOT_GENERATE_TO_STRING);
- if (value != null && !value.trim().isEmpty()) {
- return false;
- }
- value = clazz.getTagValue(TAG_NOT_GENERATE_TO_STRING);
- if (value != null && !value.trim().isEmpty()) {
- return false;
- }
- return true;
- }
-
- /**
- * Cherche et renvoie la liste des attributs constituant la clef metier d'une classe.
- *
- * @param clazz la classe à tester
- * @param model le modele
- * @return la liste des attributs de la clef métier ou null si pas de clef métier.
- */
- public static boolean sortAttribute(ObjectModelClass clazz,
- ObjectModel model) {
- String value;
- value = clazz.getTagValue(TAG_SORT_ATTRIBUTE);
- if (value == null || value.trim().isEmpty() || "false".equals(value.trim())) {
- return false;
- }
- if (value != null && "true".equals(value.trim())) {
- return true;
- }
-
- value = model.getTagValue(TAG_SORT_ATTRIBUTE);
- if (value == null || value.trim().isEmpty() || "false".equals(value.trim())) {
- return false;
- }
- if (value != null && "true".equals(value.trim())) {
- return true;
- }
- return true;
- }
-
- /**
- * Detecte si un attribut fait partie d'une clef metier.
- *
- * @param attribute l'attribut à tester
- * @return <code>true</code> si l'attribut fait partie d'une clef metier, <code>false</cdoe> sinon.
- */
- public static boolean isNaturalId(ObjectModelAttribute attribute) {
- String value = attribute.getTagValue(TAG_NATURAL_ID);
- if (!GeneratorUtil.notEmpty(value)) {
- // valeur null, donc pas positionnee
- return false;
- }
- try {
- return Boolean.valueOf(value.trim());
- } catch (Exception e) {
- // on a pas reussi a convertir en boolean.
- //todo peut-être declancher une exception ?
- return false;
- }
- }
-
- /**
- * Cherches et renvoie le copyright a utiliser sur le model.
- *
- * @param model le modele utilisé
- * @return le texte du copyright ou null
- */
- public static String getCopyright(Model model) {
- return findTagValue(TAG_COPYRIGHT, null, model);
- }
-
-// /**
-// * @see GeneratorUtil#findTagValue
-// * @deprecated
-// */
-// @Deprecated
-// public static String findTagValue(String tagName,
-// ObjectModelElement element, Model model) {
-// if (element == null) {
-// if (model != null) {
-// if (notEmpty(model.getTagValue(tagName))) {
-// return model.getTagValue(tagName);
-// }
-// }
-// return null;
-// }
-// if (notEmpty(element.getTagValue(tagName))) {
-// return element.getTagValue(tagName);
-// }
-// //On va chercher sur l'element declarant
-// return findTagValue(tagName, element.getDeclaringElement(), model);
-// }
-
- public static <Type extends ObjectModelElement> Collection<Type> getElementsWithStereotype(
- Collection<Type> elements, String... stereotypes) {
- Collection<Type> result = new ArrayList<Type>();
- for (Type element : elements) {
- if (hasStereotypes(element, stereotypes)) {
- result.add(element);
- }
- }
- return result;
- }
-
- public static boolean hasStereotypes(ObjectModelElement element,
- String... stereotypes) {
- for (String stereotype : stereotypes) {
- if (!element.hasStereotype(stereotype)) {
- return false;
- }
- }
- return true;
- }
-
- public static String getPrimaryKeyAttributesListDeclaration(
- ObjectModelClass clazz, boolean includeName) {
- String attributes = "";
- for (ObjectModelAttribute attr : getElementsWithStereotype(clazz.getAttributes(), STEREOTYPE_PRIMARYKAY)) {
- attributes += attr.getType();
- if (includeName) {
- attributes += " " + attr.getName();
- }
- attributes += ", ";
- }
- if (attributes.length() > 0) {
- attributes = attributes.substring(0, attributes.length() - 2);
- }
- return attributes;
- }
-
-// public static String capitalize(String s) {
-// return StringUtils.capitalize(s);
-// }
-
- public static boolean isAssociationClassDoublon(ObjectModelAttribute attr) {
- return (attr.getReverseAttribute() != null) && (attr.getDeclaringElement().equals(attr.getReverseAttribute().getDeclaringElement())) && (!GeneratorUtil.isFirstAttribute(attr));
- }
-
- /**
- * Renvoie le nom de l'attribut de classe d'association en fonction des cas:
- * Si l'attribut porte le même nom que le type (extrémité inverse de
- * l'association), on lui ajoute le nom de la classe d'association
- *
- * @param attr l'attribut a traiter
- * @return le nom de l'attribut de classe d'association
- */
- public static String getAssocAttrName(ObjectModelAttribute attr) {
- String typeName = attr.getType().substring(
- attr.getType().lastIndexOf(".") + 1);
- String result = attr.getName();
- if (attr.getName().equalsIgnoreCase(typeName)) {
- result += StringUtils.capitalize(attr.getAssociationClass().getName());
- }
- return result;
- }
-
- public static String getDOType(ObjectModelElement elem, ObjectModel model) {
- String type = elem.getName();
- if (elem instanceof ObjectModelAttribute) {
- type = ((ObjectModelAttribute) elem).getType();
- }
- if (elem instanceof ObjectModelClass) {
- type = ((ObjectModelClass) elem).getQualifiedName();
- }
- return getDOType(type, model);
- }
-
- public static String getDOType(String type, ObjectModel model) {
- if (!model.hasClass(type)) {
- return type;
- }
- ObjectModelClass clazz = model.getClass(type);
- if (clazz.hasStereotype(STEREOTYPE_ENTITY)) {
- if (shouldBeAbstract(clazz)) {
- type += "Abstract";
- } else {
- type += "Impl";
- }
- }
- return type;
- }
- private static final Set<String> numberTypes = new HashSet<String>();
- private static final Set<String> textTypes = new HashSet<String>();
- private static final Set<String> booleanTypes = new HashSet<String>();
- private static final Set<String> primitiveTypes = new HashSet<String>();
- private static final String VOID_TYPE = "void";
-
- static {
- numberTypes.add("byte");
- numberTypes.add("java.lang.Byte");
- numberTypes.add("Byte");
- numberTypes.add("short");
- numberTypes.add("java.lang.Short");
- numberTypes.add("Short");
- numberTypes.add("int");
- numberTypes.add("java.lang.Integer");
- numberTypes.add("Integer");
- numberTypes.add("long");
- numberTypes.add("java.lang.Long");
- numberTypes.add("Long");
- numberTypes.add("float");
- numberTypes.add("java.lang.Float");
- numberTypes.add("Float");
- numberTypes.add("double");
- numberTypes.add("java.lang.Double");
- numberTypes.add("Double");
-
- textTypes.add("char");
- textTypes.add("java.lang.Char");
- textTypes.add("Char");
- textTypes.add("java.lang.String");
- textTypes.add("String");
-
- booleanTypes.add("boolean");
- booleanTypes.add("java.lang.Boolean");
- booleanTypes.add("Boolean");
-
- primitiveTypes.addAll(numberTypes);
- primitiveTypes.addAll(textTypes);
- primitiveTypes.addAll(booleanTypes);
- }
-
- public static boolean isNumericType(ObjectModelAttribute attr) {
- return numberTypes.contains(attr.getType());
- }
-
- public static boolean isTextType(ObjectModelAttribute attr) {
- return textTypes.contains(attr.getType());
- }
-
- public static boolean isDateType(ObjectModelAttribute attr) {
- return "java.util.Date".equals(attr.getType());
- }
-
- public static boolean isBooleanType(ObjectModelAttribute attr) {
- return booleanTypes.contains(attr.getType());
- }
-
- public static boolean isPrimitiveType(ObjectModelAttribute attr) {
- return primitiveTypes.contains(attr.getType());
- }
-
- /**
- * Indique si la classe specifiee n'a aucune ou que des methodes abstraites
- *
- * @param clazz l'instance de ObjectModelClass
- * @return true si la classe n'a que des operations abstraite ou aucune
- * operation
- */
- public static boolean hasNothingOrAbstractMethods(ObjectModelClass clazz) {
- boolean result = true;
- Iterator<?> operations = clazz.getOperations().iterator();
- while (result && operations.hasNext()) {
- ObjectModelOperation op = (ObjectModelOperation) operations.next();
- result = op.isAbstract();
- }
- return result;
- }
-
- /**
- * Indique si la classe specifiee devrait etre abstraite
- *
- * @param clazz l'instance de ObjectModelClass
- * @return true dans ce cas, false sinon
- */
- public static boolean shouldBeAbstract(ObjectModelClass clazz) {
- return clazz != null && (clazz.isAbstract() && hasNothingOrAbstractMethods(clazz));
- }
-
- /**
- * <p>
- * Cette méthode permet de détecter si
- * - l'attribut représente une relation 1-n
- * - cette relation est unidirectionnelle
- * - le type de l'attribut représente un entité
- * - cette entité a des sous-classes dans le modèle
- * <p/>
- * Ce cas correspond à une incompatibilité d'Hibernate qui nous oblige a
- * adopter un comportement particulier.
- * </p>
- *
- * @param attr l'attribut a tester
- * @param model le model
- * @return true si et seulement si il s'agit bien de ce type de relation
- */
- public static boolean hasUnidirectionalRelationOnAbstractType(
- ObjectModelAttribute attr, ObjectModel model) {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- //relation 1-n
- if (reverse != null && isNMultiplicity(attr) && !isNMultiplicity(reverse)) {
- //Pas de navigabilité
- if (!reverse.isNavigable()) {
- //Il s'agit d'une entity
- ObjectModelClass clazz = model.getClass(attr.getType());
- if (clazz != null && clazz.hasStereotype(STEREOTYPE_ENTITY)) {
- //Cette classe a des sous-classes dans le modèle
- for (ObjectModelClass subClass : model.getClasses()) {
- if (subClass.getSuperclasses().contains(clazz)) {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
-
- /**
- * Renvoie le nom unique de table pour une relation ManyToMany en fonction
- * de l'attribut <code>attr</code>
- * <p/>
- * Plusieurs cas de figure:
- * <li>
- *
- * @param attr l'attribut servant de base au calcul du nom
- * @return le nom de la table
- */
- public static String getManyToManyTableName(ObjectModelAttribute attr) {
- String result;
-
- if (attr.hasAssociationClass()) {
- result = TopiaGeneratorUtil.getDBName(attr.getAssociationClass());
- } else {
- String name = attr.getName();
- String revers = attr.getReverseAttributeName();
-
- if (name.compareToIgnoreCase(revers) < 0) {
- result = name + "_" + revers;
- } else {
- result = revers + "_" + name;
- }
- }
- // String result;
- // if (!Util.isFirstAttribute(attr)) {
- // result = attr.getDeclaringElement().getName() + "_" + attr.getReverseAttribute().getDeclaringElement().getName();
- // } else {
- // result = attr.getReverseAttribute().getDeclaringElement().getName() + "_" + attr.getDeclaringElement().getName();
- // }
- return result.toLowerCase();
- }
-
- /**
- * Renvoie le type d'interface à utiliser en fonction de l'attribut
- *
- * @param attr l'attribut a traiter
- * @return String
- */
- public static String getNMultiplicityInterfaceType(ObjectModelAttribute attr) {
- if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
- return Set.class.getName();
- } else if (attr.isIndexed() || attr.isOrdered()) {
- return List.class.getName();
- }
- return Collection.class.getName();
- }
-
- /**
- * Renvoie le type d'objet (instance) à utiliser en fonction de l'attribut
- *
- * @param attr l'attribut a traiter
- * @return String
- */
- public static String getNMultiplicityObjectType(ObjectModelAttribute attr) {
- if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
- return HashSet.class.getName();
- } else if (attr.isIndexed() || attr.isOrdered()) {
- //On considère qu'on ne sait pas traiter vraiment l'attribut "ordered"
- // puisqu'on va conserver l'ordre d'insertion, et non un ordre en
- // fonction d'un élément donné. Donc on renvoi une ArrayList
- return ArrayList.class.getName();
- }
- LinkedList.class.getName();
- return ArrayList.class.getName();
- }
-
- /**
- * Renvoie le type d'interface à utiliser en fonction de l'attribut
- *
- * @param attr l'attribut a traiter
- * @return String
- */
- public static String getNMultiplicityHibernateType(ObjectModelAttribute attr) {
- if (attr.hasStereotype(STEREOTYPE_UNIQUE)) {
- return "set";
- } else if (attr.isIndexed()) {
- return "list";
- }
- //attr.isOrdered() - On génère le ordered en bag
- return "bag";
- }
-
- /**
- * Obtain the list of entities classes with the possibility to sort the result.
- *
- * @param model the current model to scan
- * @param sort flag to allow sort the result
- * @return the list of filtred classes by their stereotype
- */
- public static List<ObjectModelClass> getEntityClasses(ObjectModel model,
- boolean sort) {
- return getClassesByStereotype(STEREOTYPE_ENTITY, model, sort);
- }
-
- /**
- * Obtain the list of classes for a given stereotype with the possibility to sort the result.
- *
- * @param stereotype filter stereotype
- * @param model the current model to scan
- * @param sort flag to allow sort the result
- * @return the list of filtred classes by their stereotype
- */
- public static List<ObjectModelClass> getClassesByStereotype(
- String stereotype, ObjectModel model, boolean sort) {
- List<ObjectModelClass> classes = new ArrayList<ObjectModelClass>();
- for (ObjectModelClass clazz : model.getClasses()) {
- if (clazz.hasStereotype(stereotype)) {
- classes.add(clazz);
- }
- }
- if (sort && !classes.isEmpty()) {
- java.util.Collections.sort(classes,
- new java.util.Comparator<ObjectModelClass>() {
-
- @Override
- public int compare(ObjectModelClass o1,
- ObjectModelClass o2) {
- return o1.getQualifiedName().compareTo(
- o2.getQualifiedName());
- }
- });
- }
- return classes;
- }
-
- /**
- * Detecte si la clef metier d'une classe est mutable ou pas.
- * <p/>
- * On respecte la valeur par defaut d'hibernate, à savoir que par default une clef metier est non mutable.
- *
- * @param clazz la classe a tester
- * @return <code>true</code> si le tag value a ete positionne sur la classe via le tag
- * {@link #TAG_NATURAL_ID_MUTABLE}, , <code>false</code> sinon.
- */
- public static boolean isNaturalIdMutable(ObjectModelClass clazz) {
- String value = clazz.getTagValue(TAG_NATURAL_ID_MUTABLE);
- if (!notEmpty(value)) {
- // valeur null, donc par default positionnee
- return false;
- }
- try {
- return Boolean.valueOf(value.trim());
- } catch (Exception e) {
- // on a pas reussi a convertir en boolean.
- //todo peut-être declancher une exception ?
- return false;
- }
- }
-
- /**
- * Obtain the list of fqn of object involed in the given class.
- *
- * @param aClass the clazz to inspect
- * @param incomingFqns incoming fqns
- * @return the list of fqn of attributes
- */
- public static List<String> getImports(ObjectModelClass aClass, String... incomingFqns) {
- Set<String> tmp = new HashSet<String>();
- tmp.addAll(Arrays.asList(incomingFqns));
- getImports(aClass, tmp);
- List<String> result = cleanImports(aClass.getPackageName(), tmp);
- return result;
- }
-
- /**
- * Obtain the list of fqn of object involed in the given interface.
- *
- * @param anInterface the interface to inspect
- * @param incomingFqns incoming fqns
- * @return the list of fqn of attributes
- */
- public static List<String> getImports(ObjectModelInterface anInterface, String... incomingFqns) {
- Set<String> tmp = new HashSet<String>();
- tmp.addAll(Arrays.asList(incomingFqns));
- getImports(anInterface, tmp);
- List<String> result = cleanImports(anInterface.getPackageName(), tmp);
- return result;
- }
-
- public static String getSimpleName(String fqn) {
- int lasIndex = fqn.lastIndexOf(".");
- if (lasIndex == 1) {
- // primitive type
- return fqn;
- }
- return fqn.substring(lasIndex + 1);
- /*if (lasIndex == aClass.getPackageName().length()) {
- // same package
- return fqn.substring(lasIndex + 1);
- }
-
- return fqn;*/
- }
-
- /**
- * Obtain the list of fqn of object involed in the given class.
- *
- * @param aClass the class to inspect
- * @param fqns where to store found fqns
- */
- protected static void getImports(ObjectModelClass aClass, Set<String> fqns) {
- // scan attributes
- for (ObjectModelAttribute attr : aClass.getAttributes()) {
- fqns.add(attr.getType());
- if (isNMultiplicity(attr)) {
- String collectionType = getNMultiplicityInterfaceType(attr);
- fqns.add(collectionType);
- String collectionObject = getNMultiplicityObjectType(attr);
- fqns.add(collectionObject);
- }
- }
- for (ObjectModelAttribute attribute : aClass.getAllOtherAttributes()) {
- fqns.add(attribute.getType());
- }
- // scan associations
- if (aClass instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) aClass;
- for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
- if (attr == null) {
- continue;
- }
- fqns.add(attr.getType());
- if (isNMultiplicity(attr)) {
- String collectionType = getNMultiplicityInterfaceType(attr);
- fqns.add(collectionType);
- String collectionObject = getNMultiplicityObjectType(attr);
- fqns.add(collectionObject);
- }
- }
- }
- // scan operations
- for (ObjectModelOperation operation : aClass.getOperations()) {
- getImports(operation, fqns);
- }
- // scan super interfaces
- for (ObjectModelInterface modelInterface : aClass.getInterfaces()) {
- fqns.add(modelInterface.getQualifiedName());
- getImports(modelInterface, fqns);
- }
- // scan super classes
- for (ObjectModelClass modelClass : aClass.getSuperclasses()) {
- fqns.add(modelClass.getQualifiedName());
- getImports(modelClass);
- }
- }
-
- /**
- * Obtain the list of fqn of object involed in the given interface.
- *
- * @param anInterface the interface to inspect
- * @param fqns where to store found fqns
- */
- protected static void getImports(ObjectModelInterface anInterface, Set<String> fqns) {
- // scan operations
- for (ObjectModelOperation operation : anInterface.getOperations()) {
- getImports(operation, fqns);
- }
- // scan super interfaces
- for (ObjectModelInterface modelInterface : anInterface.getInterfaces()) {
- fqns.add(modelInterface.getQualifiedName());
- getImports(modelInterface, fqns);
- }
- }
-
- /**
- * Obtain the fqn's list of all involed type in a givne operation.
- *
- * @param operation operation to inspect
- * @param fqns where to store found fqns
- */
- protected static void getImports(ObjectModelOperation operation, Set<String> fqns) {
- String fqn = operation.getReturnType();
- fqns.add(fqn);
- for (ObjectModelParameter parameter : operation.getParameters()) {
- fqns.add(parameter.getType());
- }
- }
-
- /**
- * Clean a set of fqns, transform it into a {@link List} and sort it.
- *
- * @param packageName the current package name
- * @param fqns the dirty set of fqns
- * @return the sorted cleaned list of fqns.
- */
- protected static List<String> cleanImports(String packageName, Set<String> fqns) {
- fqns.removeAll(primitiveTypes);
- fqns.remove(VOID_TYPE);
- int packageLength = packageName.length();
- List<String> genericType = new ArrayList<String>();
- for (Iterator<String> it = fqns.iterator(); it.hasNext();) {
- String fqn = it.next();
- int lastIndex = fqn.lastIndexOf(".");
- if (lastIndex == packageLength && fqn.startsWith(packageName)) {
- // same package
- it.remove();
- continue;
- }
- int genericIndex = fqn.indexOf('<');
- if (genericIndex != -1) {
- genericType.add(fqn.substring(0, genericIndex));
- it.remove();
- }
- }
- fqns.addAll(genericType);
-
- ArrayList<String> result = new ArrayList<String>(fqns);
- java.util.Collections.sort(result);
- return result;
- }
-
- /**
- * Convertit un nom de variable en nom de constante.
- *
- * @param variableName le nom de variable a convertir
- * @return le nom de la constante à partir du nom de la variable
- */
- public static String convertVariableNameToConstantName(String variableName) {
- //TODO Faire des tests pour savoir si variableName est non null et valide
- //TODO Ameliorer l'algo pour tenir compte des caractères non alpha
- //TODO pour le moment cela convient, donc...
- StringBuilder buffer = new StringBuilder();
- boolean lastCarIsUp = false;
- for (int i = 0, j = variableName.length(); i < j; i++) {
- char c = variableName.charAt(i);
- boolean carIsUp = Character.isUpperCase(c);
- if (i > 0 && !lastCarIsUp && carIsUp) {
- // ajout d'un _
- buffer.append('_');
- }
- if (carIsUp) {
- buffer.append(c);
- } else {
- buffer.append(Character.toUpperCase(c));
- }
- lastCarIsUp = carIsUp;
- }
- return buffer.toString();
- }
-} // GeneratorUtil
-
1
0
r776 - in trunk: . ant-eugene-task/src ant-eugene-task/src/site ant-eugene-task/src/site/fr ant-eugene-task/src/site/fr/rst ant-eugene-task/src/site/rst eugene/src/main/java/org/nuiton/eugene eugene/src/site maven-eugene-plugin/src/site src/site src/site/fr src/site/fr/rst src/site/rst
by tchemit@users.nuiton.org 20 Dec '09
by tchemit@users.nuiton.org 20 Dec '09
20 Dec '09
Author: tchemit
Date: 2009-12-20 15:45:41 +0100 (Sun, 20 Dec 2009)
New Revision: 776
Added:
trunk/ant-eugene-task/src/site/
trunk/ant-eugene-task/src/site/fr/
trunk/ant-eugene-task/src/site/fr/rst/
trunk/ant-eugene-task/src/site/fr/rst/index.rst
trunk/ant-eugene-task/src/site/rst/
trunk/ant-eugene-task/src/site/rst/index.rst
trunk/ant-eugene-task/src/site/site_en.xml
trunk/ant-eugene-task/src/site/site_fr.xml
trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java
trunk/src/site/fr/
trunk/src/site/fr/rst/
trunk/src/site/fr/rst/index.rst
trunk/src/site/rst/
trunk/src/site/rst/index.rst
Modified:
trunk/eugene/src/site/site_en.xml
trunk/maven-eugene-plugin/src/site/site_en.xml
trunk/pom.xml
trunk/src/site/site_en.xml
trunk/src/site/site_fr.xml
Log:
fix doc language links, go back to processor-1.0.2, add ant module doc
Added: trunk/ant-eugene-task/src/site/fr/rst/index.rst
===================================================================
--- trunk/ant-eugene-task/src/site/fr/rst/index.rst (rev 0)
+++ trunk/ant-eugene-task/src/site/fr/rst/index.rst 2009-12-20 14:45:41 UTC (rev 776)
@@ -0,0 +1,27 @@
+======
+Eugene
+======
+
+.. contents::
+
+
+Règle ant
+---------
+
+Voici un exemple d'utilisation de la règle ant.
+
+::
+
+ <taskdef name="generator" classname="org.nuiton.eugene.GeneratorTask"
+ classpath="${compile.classpath}:${targetbuild}:${resources}" />
+
+ <target name="generate" description="generate">
+ <generator srcdir="${modelDir}" destdir="${targetgen}"
+ resolver="org.nuiton.exemple.ResourceResolver"
+ templates="org.nuiton.example.JavaBeanGenerator"
+ properties="defaultPackage=org.nuiton,fullPackagePath=org.nuiton,extraPackages=org.nuiton"
+ classpath="${compile.classpath}:${targetbuild}:${resources}" />
+ </target>
+
+Dans cette exemple, un template de génération sera apliqué sur tous les
+fichiers.
Added: trunk/ant-eugene-task/src/site/rst/index.rst
===================================================================
--- trunk/ant-eugene-task/src/site/rst/index.rst (rev 0)
+++ trunk/ant-eugene-task/src/site/rst/index.rst 2009-12-20 14:45:41 UTC (rev 776)
@@ -0,0 +1,30 @@
+======
+Eugene
+======
+
+:Authors: Tony CHEMIT
+:Contact: chemit(a)codelutin.com
+
+
+.. contents::
+
+
+Ant Task
+--------
+
+Here is an example of the Ant task.
+
+::
+
+ <taskdef name="generator" classname="org.nuiton.eugene.GeneratorTask"
+ classpath="${compile.classpath}:${targetbuild}:${resources}" />
+
+ <target name="generate" description="generate">
+ <generator srcdir="${modelDir}" destdir="${targetgen}"
+ resolver="org.nuiton.exemple.ResourceResolver"
+ templates="org.nuiton.example.JavaBeanGenerator"
+ properties="defaultPackage=org.nuiton,fullPackagePath=org.nuiton,extraPackages=org.nuiton"
+ classpath="${compile.classpath}:${targetbuild}:${resources}" />
+ </target>
+
+In this example, a generation-template will be applied to all files.
Copied: trunk/ant-eugene-task/src/site/site_en.xml (from rev 769, trunk/eugene/src/site/site_en.xml)
===================================================================
--- trunk/ant-eugene-task/src/site/site_en.xml (rev 0)
+++ trunk/ant-eugene-task/src/site/site_en.xml 2009-12-20 14:45:41 UTC (rev 776)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="${project.name}">
+
+ <bannerLeft>
+ <name>${project.name}</name>
+ </bannerLeft>
+
+ <body>
+
+ <breadcrumbs>
+ <item name="${project.name}" href="index.html" />
+ </breadcrumbs>
+
+ <links>
+ <item name="Libre-Entreprise" href="http://www.libre-entreprise.org/" />
+ <item name="[fr" href="fr/index.html" />
+ <item name="en]" href="index.html" />
+ </links>
+
+ <menu ref="parent"/>
+
+ <menu name="User">
+ <item href="index.html" name="Home"/>
+ </menu>
+
+ <menu name="Downloads">
+ <item href="${repository.home.url}/org/nuiton/eugene/${project.artifactId}/${project.version}/${project.build.finalName}.jar"
+ name="Library (jar)"/>
+ <item href="${repository.home.url}/org/nuiton/eugene/${project.artifactId}/${project.version}/${project.build.finalName}-javadoc.jar"
+ name="Javadoc (jar)"/>
+ <item href="${repository.home.url}/org/nuiton/eugene/${project.artifactId}/${project.version}/${project.build.finalName}-sources.jar"
+ name="Sources (jar)"/>
+ <item href="http://${platform}/projects/list_files/eugene" name="Archives" />
+ </menu>
+
+ <menu name="Trackers">
+ <item name="Bugs" href="${project.issueManagement.url}?query_id=2"/>
+ <item name="Evolutions" href="${project.issueManagement.url}?query_id=1"/>
+ <item name="Help" href="${project.issueManagement.url}?query_id=3"/>
+ </menu>
+
+ <menu name="Links">
+ <item name="Nuiton-processor" href="http://maven-site.nuiton.org/processor"/>
+ <item name="ToPIA" href="http://maven-site.nuiton.org/topia"/>
+ </menu>
+
+ <menu ref="reports"/>
+
+ </body>
+</project>
Copied: trunk/ant-eugene-task/src/site/site_fr.xml (from rev 769, trunk/eugene/src/site/site_fr.xml)
===================================================================
--- trunk/ant-eugene-task/src/site/site_fr.xml (rev 0)
+++ trunk/ant-eugene-task/src/site/site_fr.xml 2009-12-20 14:45:41 UTC (rev 776)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="${project.name}">
+
+ <bannerLeft>
+ <name>${project.name}</name>
+ </bannerLeft>
+
+ <body>
+
+ <breadcrumbs>
+ <item name="${project.name}" href="index.html" />
+ </breadcrumbs>
+
+ <links>
+ <item name="Libre-Entreprise" href="http://www.libre-entreprise.org/" />
+ <item name="[fr" href="index.html" />
+ <item name="en]" href="../index.html" />
+ </links>
+
+ <menu ref="parent"/>
+
+ <menu name="Utilisateur">
+ <item href="index.html" name="Accueil"/>
+ </menu>
+
+ <menu name="Téléchargement">
+ <item href="${repository.home.url}/org/nuiton/eugene/${project.artifactId}/${project.version}/${project.build.finalName}.jar"
+ name="Librairie (jar)"/>
+ <item href="${repository.home.url}/org/nuiton/eugene/${project.artifactId}/${project.version}/${project.build.finalName}-javadoc.jar"
+ name="Javadoc (jar)"/>
+ <item href="${repository.home.url}/org/nuiton/eugene/${project.artifactId}/${project.version}/${project.build.finalName}-sources.jar"
+ name="Sources (jar)"/>
+ <item href="http://${platform}/projects/list_files/eugene" name="Archives" />
+ </menu>
+
+ <menu name="Trackers">
+ <item name="Bugs" href="${project.issueManagement.url}?query_id=2"/>
+ <item name="Améliorations" href="${project.issueManagement.url}?query_id=1"/>
+ <item name="Aide" href="${project.issueManagement.url}?query_id=3"/>
+ </menu>
+
+ <menu name="Liens">
+ <item name="Nuiton-processor" href="http://maven-site.nuiton.org/processor"/>
+ <item name="ToPIA" href="http://maven-site.nuiton.org/topia"/>
+ </menu>
+
+ <menu ref="reports"/>
+
+ </body>
+</project>
Added: trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java 2009-12-20 14:45:41 UTC (rev 776)
@@ -0,0 +1,95 @@
+package org.nuiton.eugene;
+
+import org.nuiton.eugene.models.Model;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract meta transformer which contains some templates to apply to incoming model.
+ *
+ * Using the {@link #getExcludeTemplates()} to restrict use of some templates.
+ *
+ * Created: 20 déc. 2009
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com> Copyright Code Lutin
+ * @version $Revision$
+ * <p/>
+ * Mise a jour: $Date$ par :
+ * $Author: tchemit $
+ * @since 2.0.0
+ */
+public abstract class AbstractMetaTransformer<M extends Model> extends AbstractGenerator<M> {
+
+ private final Class<? extends Template<M>>[] transformers;
+
+ public AbstractMetaTransformer(Class<? extends Template<M>>... transformers) {
+ this.transformers = transformers;
+ }
+
+ protected abstract boolean validateModel(M model);
+
+ @Override
+ public final void generate(File[] file, File destDir) {
+ throw new UnsupportedOperationException("Transformer does not implements any longer this deprecated method");
+ }
+
+ @Override
+ public void applyTemplate(M model, File destDir) throws IOException {
+
+ boolean isValid = validateModel(model);
+ if (!isValid) {
+
+ //On n'empeche pas la génération si le modèle n'est pas valide
+
+ return;
+ }
+
+ List<Template<M>> templates = getTemplates();
+
+ for (Template<M> template : templates) {
+ // log
+ if (log.isDebugEnabled()) {
+ log.debug("call template : " + template.getClass().getSimpleName());
+ }
+ template.applyTemplate(model, destDir);
+ }
+ }
+
+ protected List<Template<M>> getTemplates() {
+ List<Template<M>> result = new ArrayList<Template<M>>();
+ for (Class<? extends Template<M>> generatorClass : getTransformers()) {
+ Template<M> generator;
+ if (getExcludeTemplates().contains(generatorClass.getName())) {
+ // exclude generator
+ log.info("exclude generator " + generatorClass);
+ continue;
+ }
+ try {
+ generator = generatorClass.newInstance();
+
+ // init template
+
+ if (generator instanceof AbstractGenerator) {
+ ((AbstractGenerator<M>) generator).setParent(this);
+ }
+ if (generator instanceof Transformer) {
+ generator.setProperties(properties);
+ }
+ } catch (Exception e) {
+ // should never happens
+ if (log.isErrorEnabled()) {
+ log.error("An error occurs when generating persistence", e);
+ }
+ throw new RuntimeException(e);
+ }
+ }
+ return result;
+ }
+
+ public Class<? extends Template<M>>[] getTransformers() {
+ return transformers;
+ }
+}
Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/AbstractMetaTransformer.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: trunk/eugene/src/site/site_en.xml
===================================================================
--- trunk/eugene/src/site/site_en.xml 2009-12-20 13:06:54 UTC (rev 775)
+++ trunk/eugene/src/site/site_en.xml 2009-12-20 14:45:41 UTC (rev 776)
@@ -13,7 +13,7 @@
<links>
<item name="Libre-Entreprise" href="http://www.libre-entreprise.org/" />
- <item name="[fr" href="../fr/index.html" />
+ <item name="[fr" href="fr/index.html" />
<item name="en]" href="index.html" />
</links>
Modified: trunk/maven-eugene-plugin/src/site/site_en.xml
===================================================================
--- trunk/maven-eugene-plugin/src/site/site_en.xml 2009-12-20 13:06:54 UTC (rev 775)
+++ trunk/maven-eugene-plugin/src/site/site_en.xml 2009-12-20 14:45:41 UTC (rev 776)
@@ -8,7 +8,7 @@
<body>
<links>
<item name="Libre-Entreprise" href="http://www.libre-entreprise.org/" />
- <item name="[fr" href="../fr/index.html" />
+ <item name="[fr" href="fr/index.html" />
<item name="en]" href="index.html" />
</links>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-12-20 13:06:54 UTC (rev 775)
+++ trunk/pom.xml 2009-12-20 14:45:41 UTC (rev 776)
@@ -249,10 +249,11 @@
<!-- pour un muli module on doit fixer le projectId -->
<projectId>eugene</projectId>
- <!-- TODO TC-20090823 remove ant deps -->
<ant.version>1.7.1</ant.version>
- <processor.version>1.0.3-SNAPSHOT</processor.version>
- <nuiton-utils.version>1.1.0</nuiton-utils.version>
+
+ <processor.version>1.0.2</processor.version>
+ <!--<processor.version>1.0.3-SNAPSHOT</processor.version>-->
+ <nuiton-utils.version>1.1.1</nuiton-utils.version>
<!--Multilanguage maven-site -->
<maven.site.locales>en,fr</maven.site.locales>
Added: trunk/src/site/fr/rst/index.rst
===================================================================
--- trunk/src/site/fr/rst/index.rst (rev 0)
+++ trunk/src/site/fr/rst/index.rst 2009-12-20 14:45:41 UTC (rev 776)
@@ -0,0 +1,19 @@
+======
+EUGEne
+======
+
+.. contents::
+
+
+Présentation
+------------
+
+Le projet EUGene est composé de 3 modules :
+
+ * `eugene-api`_
+ * `ant-eugene-task`_
+ * `maven-eugene-plugin`_
+
+.. _eugene-api: eugene/index.html
+.. _ant-eugene-task: ant-eugenet-task/index.html
+.. _maven-eugene-plugin: maven-eugene-plugin/index.html
\ No newline at end of file
Added: trunk/src/site/rst/index.rst
===================================================================
--- trunk/src/site/rst/index.rst (rev 0)
+++ trunk/src/site/rst/index.rst 2009-12-20 14:45:41 UTC (rev 776)
@@ -0,0 +1,19 @@
+======
+EUGEne
+======
+
+.. contents::
+
+
+Home
+----
+
+EUGene's project is distributed in 3 modules :
+
+ * `eugene-api`_
+ * `ant-eugene-task`_
+ * `maven-eugene-plugin`_
+
+.. _eugene-api: eugene/index.html
+.. _ant-eugene-task: ant-eugenet-task/index.html
+.. _maven-eugene-plugin: maven-eugene-plugin/index.html
\ No newline at end of file
Modified: trunk/src/site/site_en.xml
===================================================================
--- trunk/src/site/site_en.xml 2009-12-20 13:06:54 UTC (rev 775)
+++ trunk/src/site/site_en.xml 2009-12-20 14:45:41 UTC (rev 776)
@@ -18,6 +18,10 @@
<item name="${project.name}" href="index.html" />
</breadcrumbs>
+ <menu name="User">
+ <item name="Home" href="index.html" />
+ <item name="French version" href="fr/index.html" />
+ </menu>
<menu ref="modules"/>
<menu ref="reports"/>
Modified: trunk/src/site/site_fr.xml
===================================================================
--- trunk/src/site/site_fr.xml 2009-12-20 13:06:54 UTC (rev 775)
+++ trunk/src/site/site_fr.xml 2009-12-20 14:45:41 UTC (rev 776)
@@ -18,6 +18,11 @@
<item name="${project.name}" href="index.html" />
</breadcrumbs>
+ <menu name="Utilisateur">
+ <item name="Accueil" href="index.html" />
+ <item name="English version" href="../index.html" />
+ </menu>
+
<menu ref="modules"/>
<menu ref="reports"/>
1
0