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
r1245 - in trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader: . yaml
by agiraudet@users.nuiton.org 14 May '13
by agiraudet@users.nuiton.org 14 May '13
14 May '13
Author: agiraudet
Date: 2013-05-14 11:45:39 +0200 (Tue, 14 May 2013)
New Revision: 1245
Url: http://nuiton.org/projects/eugene/repository/revisions/1245
Log:
modification de eugene/models/object/reader/YamlObjectModelReader.java : cr?\195?\169ation d'une seule instance du parseur YAML lors de la g?\195?\169n?\195?\169ration (contre une instance par fichier avant)
modification de eugene/models/object/reader/yaml/YamlToObjectModel.java: gestion des attributs, imports et packages
Modified:
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java 2013-05-13 10:01:52 UTC (rev 1244)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java 2013-05-14 09:45:39 UTC (rev 1245)
@@ -44,8 +44,8 @@
*/
public class YamlObjectModelReader extends AbstractObjectModelReader {
- private static final Log log =
- LogFactory.getLog(YamlObjectModelReader.class);
+ private static final Log log = LogFactory.getLog(YamlObjectModelReader.class);
+ protected YamlToObjectModel yamlToObjectModel;
@Override
public String getInputType() {
@@ -55,7 +55,8 @@
@Override
protected void beforeReadFile(File... files) {
super.beforeReadFile(files);
- //TODO ?
+ //TODO : instancier parser yaml + controler clefs des maps
+ yamlToObjectModel = new YamlToObjectModel();
}
@Override
@@ -64,8 +65,7 @@
//TODO
//test
//NOTE: model deja instance
- YamlToObjectModel tmp = new YamlToObjectModel();
- tmp.test(file, model);
+ yamlToObjectModel.test(file, model);
//test
} catch (YAMLException e) {
throw new IOException("Unable to parse ObjectModel input file : " + file, e);
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java 2013-05-13 10:01:52 UTC (rev 1244)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java 2013-05-14 09:45:39 UTC (rev 1245)
@@ -1,6 +1,6 @@
package org.nuiton.eugene.models.object.reader.yaml;
-import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.*;
import org.nuiton.eugene.models.object.xml.*;
import org.yaml.snakeyaml.Yaml;
@@ -16,15 +16,26 @@
* Note2: surcharger les méthodes ou le langage pour les prochaines syntaxes ?
*/
public class YamlToObjectModel {
- protected Object data;
protected Yaml yaml;
- protected ObjectModelImpl model;
+ protected Object modelYAML;
+ protected ObjectModelImpl modelOM;
+ protected String packageOM;
+ protected Map<String,String> imports;
+
private String _log = "/tmp/log.yaml.txt";
public YamlToObjectModel() {
//TODO : mettre toutes les clefs des Maps en minuscules
//TODO : instancier le parseur YAML (éviter une instance par fichier chargé)
+ //TODO : verifier syntaxe du code -> utiliser convention de Sun
+ //TODO : differencier attributs optionnels/obligatoires :: if null -> valeur par defaut, else -> valeur | valeurs par defaut dans fichier yaml ?
+ //TODO : charger les éléments du même niveau dans la même méthode
+ //TODO : Impl or not Impl ?
+ yaml = new Yaml();
+ modelYAML = null;
+ modelOM = null;
+
this.startLog();
}
@@ -32,7 +43,7 @@
FileWriter log = null;
try {
log = new FileWriter(this._log, false);
- log.write("[LOG] start\n");
+ log.write("[LOG] start v1.0\n");
log.close();
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
@@ -50,63 +61,119 @@
}
}
- public void test(File file, ObjectModel _model) throws IOException {
+ public void test(File file, ObjectModel model) throws IOException {
//load file
InputStream input = new FileInputStream(file);
- this.yaml = new Yaml();
- this.data = this.yaml.load(input);
+ modelYAML = this.yaml.load(input);
input.close();
//file loaded
-
- this.model = (ObjectModelImpl) _model;
-
- this.loadModel();
-
+ modelOM = (ObjectModelImpl) model;
+ loadModel();
}
//TODO : utiliser design pattern
//TODO : utiliser genericite
public void loadModel() {
- if (this.data instanceof ArrayList) {
- this.model.setName(String.valueOf(this.collectElement((List) this.data, "name")));
- this.model.setVersion(String.valueOf(this.collectElement((List) this.data, "version")));
+ if (modelYAML instanceof List) {
+ loadImports();
+ Object nameYAML = collectElement((List) modelYAML, "name");
+ if(nameYAML != null)
+ {
+ modelOM.setName(String.valueOf(nameYAML));
+ }
+ else
+ {
+ ;//TODO : charger valeur par defaut ou lever exception ?
+ }
- List _classesYAML = this.collectAllElement((List) this.data, "class");
- for (Object _classYAML : _classesYAML) {
- this.loadClass(_classYAML);
+ Object versionYAML = collectElement((List) modelYAML, "version");
+ if(versionYAML != null)
+ {
+ modelOM.setVersion(String.valueOf(versionYAML));
}
+ else
+ {
+ ;//TODO : charger valeur par defaut
+ }
+ Object packageYAML = collectElement((List) modelYAML, "package");
+ if(packageYAML != null)
+ {
+ packageOM = String.valueOf(packageYAML);
+ }
+ else
+ {
+ ;//TODO : charger valeur par defaut
+ }
+
+ //modelOM.setName(String.valueOf(this.collectElement((List) modelYAML, "name")));
+ //modelOM.setVersion(String.valueOf(this.collectElement((List) modelYAML, "version")));
+
+ List classesYAML = this.collectAllElement((List) modelYAML, "class");
+ for (Object classYAML : classesYAML) {
+ ObjectModelClassImpl classOM = loadClass(classYAML);
+ //tester null ?
+ modelOM.addClass(classOM);
+ }
} else {
;//TODO : lever exception
}
}
- public void loadClass(Object _classYAML) {
- if (_classYAML instanceof List) {
- ObjectModelClassImpl _classOM = new ObjectModelClassImpl();
+ public ObjectModelClassImpl loadClass(Object classYAML) {
+ if (classYAML instanceof List) {
+ ObjectModelClassImpl classOM = new ObjectModelClassImpl();
- this.loadStereotypes((List) _classYAML, _classOM);
- this.loadTagValues((List) _classYAML, _classOM);
- this.loadComments((List) _classYAML, _classOM);
+ this.loadStereotypes((List) classYAML, classOM);
+ this.loadTagValues((List) classYAML, classOM);
+ this.loadComments((List) classYAML, classOM);
- _classOM.setName(String.valueOf(this.collectElement((List) _classYAML, "name")));
- //Object _final = this.collectElement((List) _classYAML, "final");//final not implemented by ObjectModel
- Object _abstract = this.collectElement((List) _classYAML, "abstract");
+ classOM.setPackage(packageOM);
+
+ Object nameYAML = collectElement((List) classYAML, "name");
+ if(nameYAML != null)
+ {
+ classOM.setName(String.valueOf(nameYAML));
+ }
+ else
+ {
+ //TODO : lever exception ?
+ }
+
+ Object abstractYAML = collectElement((List) classYAML, "abstract");
+ if(abstractYAML != null)
+ {
+ classOM.setAbstract(Boolean.valueOf(String.valueOf(abstractYAML)));//degolass
+ }
+ else
+ {
+ ;//TODO : charger la valeur par defaut
+ }
+
+ /*classOM.setName(String.valueOf(this.collectElement((List) classYAML, "name")));
+ //Object finalYAML = this.collectElement((List) classYAML, "final");//final not implemented by ObjectModel
+ Object abstractYAML = this.collectElement((List) classYAML, "abstract");
//TODO : utiliser operateur ternaire
- if (_abstract instanceof Boolean) {
- _classOM.setAbstract((Boolean) _abstract);
+ if (abstractYAML instanceof Boolean) {
+ classOM.setAbstract((Boolean) abstractYAML);
} else//sale
{
- _classOM.setAbstract(Boolean.valueOf(String.valueOf(_abstract)));
- }
+ classOM.setAbstract(Boolean.valueOf(String.valueOf(abstractYAML)));
+ }*/
//TODO : loadAttributes
+ List attributesYAML = this.collectAllElement((List) classYAML, "attribute");
+ for (Object attributeYAML : attributesYAML) {
+ ObjectModelAttributeImpl attributeOM = loadAttribute(attributeYAML);
+ classOM.addAttribute(attributeOM);
+ }
//TODO : loadOperations
-
- this.model.addClass(_classOM);
+ //this.modelOM.addClass(classOM);
+ return classOM;
} else {
;//TODO : lever exception
+ return null;
}
}
@@ -122,64 +189,204 @@
;//TODO
}
- public void loadAttribute(Object _attribute) {
- ;//TODO
+ public ObjectModelAttributeImpl loadAttribute(Object attributeYAML) {
+ if(attributeYAML instanceof List)
+ {
+ ObjectModelAttributeImpl attributeOM = new ObjectModelAttributeImpl();
+
+ this.loadStereotypes((List) attributeYAML, attributeOM);
+ this.loadTagValues((List) attributeYAML, attributeOM);
+ this.loadComments((List) attributeYAML, attributeOM);
+
+ Object nameYAML = collectElement((List) attributeYAML, "name");
+ if(nameYAML != null)
+ {
+ attributeOM.setName(String.valueOf(nameYAML));
+ }
+ else
+ {
+ //TODO : charger la valeur par defaut
+ }
+
+ Object typeYAML = collectElement((List) attributeYAML, "type");
+ if(typeYAML != null)
+ {
+ //TODO : gerer les imports et detection des types primitifs...
+ String type = String.valueOf(typeYAML);
+ if(imports.containsKey(type))
+ {
+ attributeOM.setType(imports.get(type));
+ }
+ else
+ {
+ attributeOM.setType(type);
+ }
+ }
+ else
+ {
+ ;//TODO : lever exception
+ }
+
+ Object visibilityYAML = collectElement((List) attributeYAML, "visibility");
+ if(visibilityYAML != null)
+ {
+ attributeOM.setVisibility(String.valueOf(visibilityYAML));
+ }
+ else
+ {
+ //TODO : charger valeur par defaut
+ }
+
+ Object staticYAML = collectElement((List) attributeYAML, "static");
+ if(staticYAML != null)
+ {
+ attributeOM.setStatic(Boolean.valueOf(String.valueOf(staticYAML)));//tester boolean ?
+ }
+ else
+ {
+ //TODO : charger valeur par defaut
+ }
+
+ Object finalYAML = collectElement((List) attributeYAML, "final");
+ if(finalYAML != null)
+ {
+ attributeOM.setFinal(Boolean.valueOf(String.valueOf(finalYAML)));
+ }
+ else
+ {
+ //TODO : charger la valeur par defaut
+ }
+
+ Object associationTypeYAML = collectElement((List) attributeYAML, "asociationType");
+ if(associationTypeYAML != null)
+ {
+ attributeOM.setAssociationType(String.valueOf(associationTypeYAML));
+ }
+ else
+ {
+ //TODO : charger la valeur par defaut
+ }
+
+ Object minMultiplicityYAML = collectElement((List) attributeYAML, "minMultiplicity");
+ if(minMultiplicityYAML != null)
+ {
+ attributeOM.setMinMultiplicity(Integer.valueOf(String.valueOf(minMultiplicityYAML)));
+ }
+ else
+ {
+ //TODO : charger la valeur par defaut
+ }
+
+ Object maxMultiplicityYAML = collectElement((List) attributeYAML, "maxMultiplicity");
+ if(maxMultiplicityYAML != null)
+ {
+ attributeOM.setMaxMultiplicity(Integer.valueOf(String.valueOf(maxMultiplicityYAML)));
+ }
+ else
+ {
+ //TODO : charger la valeur par defaut
+ }
+
+ Object navigableYAML = collectElement((List) attributeYAML, "navigable");
+ if(navigableYAML != null)
+ {
+ attributeOM.setNavigable(Boolean.valueOf(String.valueOf(navigableYAML)));
+ }
+ else
+ {
+ //TODO : charger la valeur par defaut
+ }
+
+ Object orderingYAML = collectElement((List) attributeYAML, "ordering");
+ if(orderingYAML != null)
+ {
+ attributeOM.setOrdering(String.valueOf(orderingYAML));
+ }
+ else
+ {
+ //TODO : charger la valeur par defaut
+ }
+
+ Object labelYAML = collectElement((List) attributeYAML, "label");
+ if(labelYAML != null)
+ {
+ //TODO : gestion des labels et operations correspondantes
+ writeLog("label="+String.valueOf(labelYAML));
+ }
+
+ return attributeOM;
+ }
+ return null;
}
- public void loadOperation(Object _operation) {
+ public void loadOperation(Object operationYAML) {
;//TODO
}
- public void loadStereotypes(List _data, ObjectModelElementImpl _element) {
- Object stereotypes = this.collectElement(_data, "stereotype");
+ public void loadImports()
+ { //pour etre sur que les imports seront des <String,String>
+ if(modelYAML instanceof List)//verification inutile ?
+ {
+ Map<Object,Object> tmp = collectMap((List) modelYAML,"imports");
+ imports = new LinkedHashMap();
+ for(Map.Entry<Object,Object> entry : tmp.entrySet())
+ {
+ imports.put(String.valueOf(entry.getKey()),String.valueOf(entry.getValue()));
+ }
+ writeLog("imports="+imports);
+ }
+ }
+
+ public void loadStereotypes(List elementYAML, ObjectModelElementImpl elementOM) {
+ Object stereotypes = this.collectElement(elementYAML, "stereotype");
if (stereotypes instanceof List) {
for (Object stereotype : (List) stereotypes) {
ObjectModelImplRef ref = new ObjectModelImplRef();
ref.setName(String.valueOf(stereotype));
- _element.addStereotype(ref);
+ elementOM.addStereotype(ref);
}
}
}
//TODO : pour model
- public void loadComments(List _data, ObjectModelElementImpl _element) {
- Object comments = this.collectElement(_data, "comments");
+ public void loadComments(List elementYAML, ObjectModelElementImpl elementOM) {
+ Object comments = this.collectElement(elementYAML, "comments");
if (comments instanceof List) {
for (Object comment : (List) comments) {
- _element.addComment(String.valueOf(comment));
+ elementOM.addComment(String.valueOf(comment));
}
}
}
//TODO : pour model
- public void loadTagValues(List _data, ObjectModelElementImpl _element) {
- Object tagValues = this.collectElement(_data, "tagValues");
+ public void loadTagValues(List elementYAML, ObjectModelElementImpl elementOM) {
+ Object tagValues = this.collectElement(elementYAML, "tagValues");
if (tagValues instanceof Map) {
for (Object entry : ((Map) tagValues).entrySet()) {
String key = String.valueOf(((Map.Entry) entry).getKey());
String value = String.valueOf(((Map.Entry) entry).getValue());
- _element.addTagValue(key, value);
+ elementOM.addTagValue(key, value);
}
}
}
- public Object collectElement(List _data, Object _key) {
- for (Object obj : _data) {
+ public Object collectElement(List data, Object key) {
+ for (Object obj : data) {
if (obj instanceof Map) {
- if (((Map) obj).containsKey(_key)) {
- return ((Map) obj).get(_key);
+ if (((Map) obj).containsKey(key)) {
+ return ((Map) obj).get(key);
}
}
}
return null;
}
- public List collectList(List _data, Object _key) {
- for (Object obj : _data) {
+ public List collectList(List data, Object key) {
+ for (Object obj : data) {
if (obj instanceof Map) {
- if (((Map) obj).containsKey(_key)) {
- if (((Map) obj).get(_key) instanceof List) {
- return (List) ((Map) obj).get(_key);
+ if (((Map) obj).containsKey(key)) {
+ if (((Map) obj).get(key) instanceof List) {
+ return (List) ((Map) obj).get(key);
/*List res = new LinkedList();
for(Object tmp : (List) ((Map) obj).get(_key))
{
@@ -193,12 +400,12 @@
return null;
}
- public Map collectMap(List _data, Object _key) {
- for (Object obj : _data) {
+ public Map collectMap(List data, Object key) {
+ for (Object obj : data) {
if (obj instanceof Map) {
- if (((Map) obj).containsKey(_key)) {
- if (((Map) obj).get(_key) instanceof Map) {
- return (Map) ((Map) obj).get(_key);
+ if (((Map) obj).containsKey(key)) {
+ if (((Map) obj).get(key) instanceof Map) {
+ return (Map) ((Map) obj).get(key);
/*Map res = new LinkedHashMap();
for(Object tmp : ((Map) ((Map) obj).get(_key)).entrySet())
{
@@ -215,12 +422,13 @@
return null;
}
- public List collectAllElement(List _data, Object _key) {
+ //collectElements
+ public List collectAllElement(List data, Object key) {
List res = new LinkedList();
- for (Object obj : _data) {
+ for (Object obj : data) {
if (obj instanceof Map) {
- if (((Map) obj).containsKey(_key)) {
- res.add(((Map) obj).get(_key));
+ if (((Map) obj).containsKey(key)) {
+ res.add(((Map) obj).get(key));
}
}
}
1
0
Author: agiraudet
Date: 2013-05-13 12:01:52 +0200 (Mon, 13 May 2013)
New Revision: 1244
Url: http://nuiton.org/projects/eugene/repository/revisions/1244
Log:
ajout du package yaml dans eugene/src/main/java/org/nuiton/eugene/models/object/reader
ajout de la classe YamlToObjectModel au package yaml : classe permettant de charger un ObjectModel en m?\195?\169moire ?\195?\160 partir d'un mod?\195?\168le sous forme de fichier yaml
modification de la classe YamlObjectModelReader dans eugene/src/main/java/org/nuiton/eugene/models/object/reader : modification de la m?\195?\169thode readFileToModel qui appelle une m?\195?\169thode la classe YamlToObjectModel chargeant l'ObjectModel correspondant au fichier yaml pass?\195?\169 en param?\195?\168tre
ajout d'une d?\195?\169pendance vers snakeyaml 1.12 dans eugene/pom.xml
ajout du module eugene-plantuml-templates dans pom.xml
ajout du module eugene-plantuml-templates : module permettant de g?\195?\169n?\195?\169rer un diagramme au format .plantuml puis .png lors de la compilation du projet
Added:
trunk/eugene-plantuml-templates/
trunk/eugene-plantuml-templates/LICENSE.txt
trunk/eugene-plantuml-templates/README.txt
trunk/eugene-plantuml-templates/changelog.txt
trunk/eugene-plantuml-templates/pom.xml
trunk/eugene-plantuml-templates/src/
trunk/eugene-plantuml-templates/src/main/
trunk/eugene-plantuml-templates/src/main/java/
trunk/eugene-plantuml-templates/src/main/java/org/
trunk/eugene-plantuml-templates/src/main/java/org/nuiton/
trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/
trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/
trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/PlantumlTemplatesGenerator.java
trunk/eugene-plantuml-templates/src/main/resources/
trunk/eugene-plantuml-templates/src/test/
trunk/eugene-plantuml-templates/src/test/java/
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java
Modified:
trunk/eugene/pom.xml
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java
trunk/pom.xml
Modified: trunk/eugene/pom.xml
===================================================================
--- trunk/eugene/pom.xml 2013-05-05 08:32:43 UTC (rev 1243)
+++ trunk/eugene/pom.xml 2013-05-13 10:01:52 UTC (rev 1244)
@@ -122,6 +122,12 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>1.12</version>
+ </dependency>
+
</dependencies>
<!-- ************************************************************* -->
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java 2013-05-05 08:32:43 UTC (rev 1243)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java 2013-05-13 10:01:52 UTC (rev 1244)
@@ -1,8 +1,7 @@
-package org.nuiton.eugene.models.object.reader;
-
/*
* #%L
* EUGene :: EUGene
+ *
* $Id$
* $HeadURL$
* %%
@@ -24,10 +23,14 @@
* #L%
*/
+package org.nuiton.eugene.models.object.reader;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.ModelHelper;
import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.reader.yaml.YamlToObjectModel;
+import org.yaml.snakeyaml.error.YAMLException;
import java.io.File;
import java.io.IOException;
@@ -56,9 +59,17 @@
}
@Override
- protected void readFileToModel(File file,
- ObjectModel model) throws IOException {
- //TODO
+ protected void readFileToModel(File file, ObjectModel model) throws IOException {
+ try {
+ //TODO
+ //test
+ //NOTE: model deja instance
+ YamlToObjectModel tmp = new YamlToObjectModel();
+ tmp.test(file, model);
+ //test
+ } catch (YAMLException e) {
+ throw new IOException("Unable to parse ObjectModel input file : " + file, e);
+ }
}
}
Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java 2013-05-13 10:01:52 UTC (rev 1244)
@@ -0,0 +1,229 @@
+package org.nuiton.eugene.models.object.reader.yaml;
+
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.xml.*;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * User: agiraudet
+ * Date: 06/05/13
+ * Time: 12:08
+ * <p/>
+ * Note1: le parsage se base sur la syntaxe 5-1uml.yaml
+ * Note2: surcharger les méthodes ou le langage pour les prochaines syntaxes ?
+ */
+public class YamlToObjectModel {
+ protected Object data;
+ protected Yaml yaml;
+ protected ObjectModelImpl model;
+
+ private String _log = "/tmp/log.yaml.txt";
+
+ public YamlToObjectModel() {
+ //TODO : mettre toutes les clefs des Maps en minuscules
+ //TODO : instancier le parseur YAML (éviter une instance par fichier chargé)
+ this.startLog();
+ }
+
+ private void startLog() {
+ FileWriter log = null;
+ try {
+ log = new FileWriter(this._log, false);
+ log.write("[LOG] start\n");
+ log.close();
+ } catch (IOException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
+ private void writeLog(String str) {
+ FileWriter log = null;
+ try {
+ log = new FileWriter(this._log, true);
+ log.write("[LOG] " + str + "\n");
+ log.close();
+ } catch (IOException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
+ public void test(File file, ObjectModel _model) throws IOException {
+ //load file
+ InputStream input = new FileInputStream(file);
+ this.yaml = new Yaml();
+ this.data = this.yaml.load(input);
+ input.close();
+ //file loaded
+
+ this.model = (ObjectModelImpl) _model;
+
+ this.loadModel();
+
+ }
+
+ //TODO : utiliser design pattern
+ //TODO : utiliser genericite
+ public void loadModel() {
+ if (this.data instanceof ArrayList) {
+ this.model.setName(String.valueOf(this.collectElement((List) this.data, "name")));
+ this.model.setVersion(String.valueOf(this.collectElement((List) this.data, "version")));
+
+ List _classesYAML = this.collectAllElement((List) this.data, "class");
+ for (Object _classYAML : _classesYAML) {
+ this.loadClass(_classYAML);
+ }
+
+ } else {
+ ;//TODO : lever exception
+ }
+ }
+
+ public void loadClass(Object _classYAML) {
+ if (_classYAML instanceof List) {
+ ObjectModelClassImpl _classOM = new ObjectModelClassImpl();
+
+ this.loadStereotypes((List) _classYAML, _classOM);
+ this.loadTagValues((List) _classYAML, _classOM);
+ this.loadComments((List) _classYAML, _classOM);
+
+ _classOM.setName(String.valueOf(this.collectElement((List) _classYAML, "name")));
+ //Object _final = this.collectElement((List) _classYAML, "final");//final not implemented by ObjectModel
+ Object _abstract = this.collectElement((List) _classYAML, "abstract");
+ //TODO : utiliser operateur ternaire
+ if (_abstract instanceof Boolean) {
+ _classOM.setAbstract((Boolean) _abstract);
+ } else//sale
+ {
+ _classOM.setAbstract(Boolean.valueOf(String.valueOf(_abstract)));
+ }
+
+ //TODO : loadAttributes
+ //TODO : loadOperations
+
+
+ this.model.addClass(_classOM);
+ } else {
+ ;//TODO : lever exception
+ }
+ }
+
+ public void loadInterface(Object _interface) {
+ ;//TODO
+ }
+
+ public void loadAssociationClass(Object _associationClass) {
+ ;//TODO
+ }
+
+ public void loadEnumeration(Object _enumeration) {
+ ;//TODO
+ }
+
+ public void loadAttribute(Object _attribute) {
+ ;//TODO
+ }
+
+ public void loadOperation(Object _operation) {
+ ;//TODO
+ }
+
+ public void loadStereotypes(List _data, ObjectModelElementImpl _element) {
+ Object stereotypes = this.collectElement(_data, "stereotype");
+ if (stereotypes instanceof List) {
+ for (Object stereotype : (List) stereotypes) {
+ ObjectModelImplRef ref = new ObjectModelImplRef();
+ ref.setName(String.valueOf(stereotype));
+ _element.addStereotype(ref);
+ }
+ }
+ }
+
+ //TODO : pour model
+ public void loadComments(List _data, ObjectModelElementImpl _element) {
+ Object comments = this.collectElement(_data, "comments");
+ if (comments instanceof List) {
+ for (Object comment : (List) comments) {
+ _element.addComment(String.valueOf(comment));
+ }
+ }
+ }
+
+ //TODO : pour model
+ public void loadTagValues(List _data, ObjectModelElementImpl _element) {
+ Object tagValues = this.collectElement(_data, "tagValues");
+ if (tagValues instanceof Map) {
+ for (Object entry : ((Map) tagValues).entrySet()) {
+ String key = String.valueOf(((Map.Entry) entry).getKey());
+ String value = String.valueOf(((Map.Entry) entry).getValue());
+ _element.addTagValue(key, value);
+ }
+ }
+ }
+
+ public Object collectElement(List _data, Object _key) {
+ for (Object obj : _data) {
+ if (obj instanceof Map) {
+ if (((Map) obj).containsKey(_key)) {
+ return ((Map) obj).get(_key);
+ }
+ }
+ }
+ return null;
+ }
+
+ public List collectList(List _data, Object _key) {
+ for (Object obj : _data) {
+ if (obj instanceof Map) {
+ if (((Map) obj).containsKey(_key)) {
+ if (((Map) obj).get(_key) instanceof List) {
+ return (List) ((Map) obj).get(_key);
+ /*List res = new LinkedList();
+ for(Object tmp : (List) ((Map) obj).get(_key))
+ {
+ res.add(tmp);
+ }
+ return res;*/
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public Map collectMap(List _data, Object _key) {
+ for (Object obj : _data) {
+ if (obj instanceof Map) {
+ if (((Map) obj).containsKey(_key)) {
+ if (((Map) obj).get(_key) instanceof Map) {
+ return (Map) ((Map) obj).get(_key);
+ /*Map res = new LinkedHashMap();
+ for(Object tmp : ((Map) ((Map) obj).get(_key)).entrySet())
+ {
+ if(tmp instanceof Map.Entry)//ou cast
+ {
+ res.put(((Map.Entry) tmp).getKey(),((Map.Entry) tmp).getValue());
+ }
+ }
+ return res;*/
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public List collectAllElement(List _data, Object _key) {
+ List res = new LinkedList();
+ for (Object obj : _data) {
+ if (obj instanceof Map) {
+ if (((Map) obj).containsKey(_key)) {
+ res.add(((Map) obj).get(_key));
+ }
+ }
+ }
+ return res;
+ }
+}
Added: trunk/eugene-plantuml-templates/LICENSE.txt
===================================================================
Added: trunk/eugene-plantuml-templates/README.txt
===================================================================
Added: trunk/eugene-plantuml-templates/changelog.txt
===================================================================
Added: trunk/eugene-plantuml-templates/pom.xml
===================================================================
--- trunk/eugene-plantuml-templates/pom.xml (rev 0)
+++ trunk/eugene-plantuml-templates/pom.xml 2013-05-13 10:01:52 UTC (rev 1244)
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ #%L
+ EUGene :: EUGene
+
+ $HeadURL: http://svn.nuiton.org/svn/eugene/trunk/eugene-java-templates/pom.xml $
+ %%
+ Copyright (C) 2004 - 2010 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ 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>.
+ #L%
+ -->
+<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>
+
+ <parent>
+ <groupId>org.nuiton</groupId>
+ <artifactId>eugene</artifactId>
+ <version>2.6.3-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.nuiton.eugene</groupId>
+ <artifactId>eugene-plantuml-templates</artifactId>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>eugene</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sourceforge.plantuml</groupId>
+ <artifactId>plantuml</artifactId>
+ <version>7962</version>
+ </dependency>
+
+ </dependencies>
+
+ <name>EUGene :: PlantUML templates</name>
+
+ <inceptionYear>2013</inceptionYear>
+
+</project>
+
+
+
Added: trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/PlantumlTemplatesGenerator.java
===================================================================
--- trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/PlantumlTemplatesGenerator.java (rev 0)
+++ trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/PlantumlTemplatesGenerator.java 2013-05-13 10:01:52 UTC (rev 1244)
@@ -0,0 +1,191 @@
+package org.nuiton.eugene.plantuml;
+
+import net.sourceforge.plantuml.GeneratedImage;
+import net.sourceforge.plantuml.SourceFileReader;
+import org.nuiton.eugene.models.object.*;
+
+import java.io.*;
+import java.util.*;
+
+// http://maven-site.nuiton.org/eugene/objectmodel/ObjectModel_Interfaces.png
+//TODO : Plexus ?
+
+public class PlantumlTemplatesGenerator extends ObjectModelGenerator {
+
+ @Override
+ public void generateFromModel(Writer output, ObjectModel input) throws IOException {
+ /*//log
+ FileWriter log = new FileWriter(File.separator+"tmp"+File.separator+"test2.log");
+ log.close();
+ *///log
+
+ // utiliser le systeme de templates a l'avenir
+
+ Map<ObjectModelAttribute,ObjectModelClassifier> linksOME = new LinkedHashMap<ObjectModelAttribute, ObjectModelClassifier>();
+
+ // debut du fichier
+ output.write("@startuml\n\n");
+ // parcours des classes
+ for(ObjectModelClass class_tmp : input.getClasses())
+ {
+ // sale
+ String classStereotype = "";
+ if(class_tmp.getStereotypes().size()>0)
+ {
+ classStereotype = "<<";
+ for(String str : class_tmp.getStereotypes())
+ {
+ classStereotype = classStereotype+","+str;
+ }
+ classStereotype = classStereotype+">>";
+ }
+ /*if(class_tmp.getStereotypes().contains("entity"))
+ {
+ classStereotype = " <<entity>>";
+ }*/
+ String className = class_tmp.getName();
+ // ajout de la classe
+ output.write("class "+className+classStereotype+" {\n");
+ // parcours des attributs de la classe
+ for(ObjectModelAttribute attribute_tmp : class_tmp.getAttributes())
+ {
+ String attributeName = attribute_tmp.getName();
+ //String attributeType = afterLastPoint(attribute_tmp.getType());
+ String attributeType = attribute_tmp.getType();
+ // si l'attribut n'est lie a aucune classe
+ if(attribute_tmp.referenceClassifier())
+ {
+ // ajout du lien
+ linksOME.put(attribute_tmp,class_tmp);
+ }
+ else
+ {
+ // ajout de l'attribut
+ output.write(" -"+attributeName+" : "+attributeType+"\n");
+ }
+ }
+ // parcours des operations
+ for(ObjectModelOperation operation_tmp : class_tmp.getOperations())
+ {
+ String operationName = operation_tmp.getName();
+ //String operationReturnType = afterLastPoint(operation_tmp.getReturnType());
+ String operationReturnType = operation_tmp.getReturnType();
+ // ajout de l'operation
+ output.write(" +"+operationName+"(");
+ // parcours des parametres
+ boolean first = true;
+ for(ObjectModelParameter param : operation_tmp.getParameters())
+ {
+ String parameterName = param.getName();
+ //String parameterType = afterLastPoint(param.getType());
+ String parameterType = param.getType();
+ if(first)
+ {
+ first = false;
+ }
+ else
+ {
+ output.write(", ");
+ }
+ // ajout du parametre
+ output.write(parameterName+" : "+parameterType);
+ }
+ // ajout du type de retour
+ output.write(") : "+operationReturnType+"\n");// attention aux listes !
+ }
+ output.write("}\n\n");
+
+ }
+
+ // parcours des enumerations
+ for(ObjectModelEnumeration enumeration_tmp : input.getEnumerations())
+ {
+ String enumerationName = enumeration_tmp.getName();
+ String enumerationStereotype = "";
+ if(enumeration_tmp.getStereotypes().contains("entity"))
+ {
+ enumerationStereotype = " <<entity>>";
+ }
+ // ajout de l'enumeration
+ output.write("enum "+enumerationName+enumerationStereotype+" {\n");
+ output.write("}\n\n");
+ }
+
+ // parcours des interfaces
+ for(ObjectModelInterface interface_tmp : input.getInterfaces())
+ {
+ String interfaceName = interface_tmp.getName();
+ String interfaceStereotype = "";
+ if(interface_tmp.getStereotypes().contains("entity"))
+ {
+ interfaceStereotype = " <<entity>>";
+ }
+ // ajout de l'interface
+ output.write("interface "+interfaceName+interfaceStereotype+" {\n");
+ // ajout des methodes
+ output.write("}\n\n");
+ }
+
+ //liaisons
+ for(ObjectModelAttribute attribute_tmp : linksOME.keySet())
+ {
+ if(attribute_tmp.isComposite() && attribute_tmp.referenceClassifier())
+ {
+ output.write(linksOME.get(attribute_tmp).getName()+" *-- "+attribute_tmp.getClassifier().getName()+"\n");
+ }
+ else if(attribute_tmp.isAggregate() && attribute_tmp.referenceClassifier())//else if
+ {
+ output.write(linksOME.get(attribute_tmp).getName()+" o-- "+attribute_tmp.getClassifier().getName()+"\n");
+ }
+ else if(!attribute_tmp.isNavigable() && attribute_tmp.referenceClassifier())//probleme avec les compositions et aggregations -> double lien
+ {
+ output.write(attribute_tmp.getClassifier().getName()+" --> "+linksOME.get(attribute_tmp).getName()+"\n");
+ }
+ else if(attribute_tmp.isNavigable() && attribute_tmp.referenceClassifier())
+ {
+ output.write(attribute_tmp.getClassifier().getName()+" -- "+linksOME.get(attribute_tmp).getName()+"\n");
+ }
+ }
+
+ // fin du fichier
+ output.write("\n@enduml");
+ }
+
+ // exemple : afterLastPoint("org.nuiton.testeugene.generator") return "generator"
+ public static String afterLastPoint(String input)
+ {
+ String str = new StringBuffer(input).reverse().toString();
+ String res = "";
+ for(Character car : str.toCharArray())
+ {
+ if(car.equals('.'))
+ {
+ return res;
+ }
+ else
+ {
+ res = car.toString()+res;
+ }
+ }
+ return res;
+ }
+
+ @Override
+ public void applyTemplate(ObjectModel model, File destDir) throws IOException {
+ super.applyTemplate(model, destDir);
+ try {
+ File plantuml = new File(destDir+File.separator+this.getFilenameForModel(model));
+ SourceFileReader reader = new SourceFileReader(plantuml);
+ List<GeneratedImage> lst = reader.getGeneratedImages();
+ File diagram = new File(destDir+File.separator+model.getName()+".png");
+ diagram = lst.get(0).getPngFile();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public String getFilenameForModel(ObjectModel model) {
+ return model.getName()+".plantuml";
+ }
+}
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-05-05 08:32:43 UTC (rev 1243)
+++ trunk/pom.xml 2013-05-13 10:01:52 UTC (rev 1244)
@@ -43,6 +43,7 @@
<module>eugene-java-templates</module>
<!--module>eugene-jpa-templates</module-->
<module>eugene-maven-plugin</module>
+ <module>eugene-plantuml-templates</module>
</modules>
<dependencyManagement>
1
0
Author: tchemit
Date: 2013-05-05 10:32:43 +0200 (Sun, 05 May 2013)
New Revision: 1243
Url: http://nuiton.org/projects/eugene/repository/revisions/1243
Log:
refs #2681: Make possible to apply templates to different inputs (nearly ok, just need to merge now models)
fixes #2682: ITs in eugene-m-p should always be runned
Added:
trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/BaseChainedFileWriterToMemoryModel.java
trunk/eugene/src/main/java/org/nuiton/eugene/ModelHelper.java
Modified:
trunk/eugene-maven-plugin/pom.xml
trunk/eugene-maven-plugin/src/it/evol-879/model/model-api/pom.xml
trunk/eugene-maven-plugin/src/it/evol-879/model/model-impl/pom.xml
trunk/eugene-maven-plugin/src/it/evol-879/model/pom.xml
trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/GenerateMojo.java
trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java
trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmiChainedFileWriter.java
trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmlModelChainedFileWriter.java
trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/YamlModelChainedFileWriter.java
trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java
trunk/eugene/src/main/java/org/nuiton/eugene/ModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/Model.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/XmlObjectModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/state/xml/StateModelImpl.java
trunk/eugene/src/main/java/org/nuiton/eugene/writer/ChainedFileWriterConfiguration.java
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -28,7 +28,6 @@
import org.nuiton.eugene.models.object.ObjectModel;
import org.nuiton.eugene.models.object.ObjectModelClassifier;
import org.nuiton.eugene.models.object.ObjectModelElement;
-import org.nuiton.eugene.models.object.ObjectModelReader;
import static org.nuiton.eugene.ModelPropertiesUtil.TagValueDefinition;
@@ -51,7 +50,6 @@
* used while reading the properties associated with a model and if found is
* directly set to the {@code version} field of the model.
*
- * @see ObjectModelReader#loadModelTagValue(ObjectModel, String, String)
* @since 2.3
*/
@TagValueDefinition(target = {ObjectModel.class},
Added: trunk/eugene/src/main/java/org/nuiton/eugene/ModelHelper.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/ModelHelper.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/ModelHelper.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -0,0 +1,146 @@
+package org.nuiton.eugene;
+
+/*
+ * #%L
+ * EUGene :: EUGene
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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>.
+ * #L%
+ */
+
+import org.nuiton.eugene.models.Model;
+import org.nuiton.eugene.models.object.reader.XmlObjectModelReader;
+import org.nuiton.eugene.models.object.reader.YamlObjectModelReader;
+import org.nuiton.eugene.models.state.StateModelReader;
+
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Help methods around model.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.3
+ */
+public class ModelHelper {
+
+ /**
+ * All available models (obtain by plexus, keys are plexus roles,
+ * values are a instance of corresponding model).
+ */
+ protected Map<String, Model> models;
+
+ /** All available writers introspects via plexus. */
+ protected Map<String, ModelReader<?>> modelReaders;
+
+ public ModelHelper(Map<String, Model> models,
+ Map<String, ModelReader<?>> modelReaders) {
+ this.models = Collections.unmodifiableMap(models);
+ this.modelReaders = Collections.unmodifiableMap(modelReaders);
+ }
+
+ public Model getModel(String modelType) {
+ Model model = models.get(modelType.trim());
+ return model;
+ }
+
+ public ModelReader getModelReader(String modelType, String type) {
+ ModelReader result = null;
+ for (ModelReader<?> modelReader : modelReaders.values()) {
+ if (modelType.equals(modelReader.getModelType()) &&
+ type.equals(modelReader.getInputType())) {
+ result = modelReader;
+ break;
+ }
+ }
+ return result;
+ }
+
+ public Map<String, ModelReader<?>> getModelReaders() {
+ return modelReaders;
+ }
+
+ /**
+ * Define type of model known by eugene
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.3
+ */
+ public static enum ModelType {
+
+ /**
+ * Object model.
+ *
+ * @see org.nuiton.eugene.models.object
+ */
+ OBJECT("objectmodel"),
+
+ /**
+ * Object model.
+ *
+ * @see org.nuiton.eugene.models.state
+ */
+ STATE("statemodel");
+
+ private final String alias;
+
+ private ModelType(String alias) {
+ this.alias = alias;
+ }
+
+ public String getAlias() {
+ return alias;
+ }
+ }
+
+ /**
+ * Define type onf input model known by eugene.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.3
+ */
+ public static enum ModelInputType {
+
+ /**
+ * Read object model from xml files.
+ *
+ * @see XmlObjectModelReader
+ * @see StateModelReader
+ */
+ XML("xml"),
+
+ /**
+ * Read object model from yaml files.
+ *
+ * @see YamlObjectModelReader
+ */
+ YAML("yaml");
+
+ private final String alias;
+
+ private ModelInputType(String alias) {
+ this.alias = alias;
+ }
+
+ public String getAlias() {
+ return alias;
+ }
+
+ }
+}
Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/ModelHelper.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/ModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/ModelReader.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/ModelReader.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -71,6 +71,23 @@
*/
protected ModelPropertiesUtil.ModelPropertiesProvider modelPropertiesProvider;
+ /**
+ * Gets the type of model.
+ *
+ * @return the type of model.
+ * @see ModelHelper.ModelType
+ * @since 2.6.3
+ */
+ public abstract String getModelType();
+
+ /**
+ * Gets the type of input file. For example {@code xml}, or {@code yaml}.
+ *
+ * @return the type of input file.
+ * @since 2.6.3
+ */
+ public abstract String getInputType();
+
public boolean isVerbose() {
return verbose;
}
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/Model.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/Model.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/Model.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -30,7 +30,7 @@
/**
* Model.
- *
+ *
* @version $Revision$
*
* Mise a jour: $Date$
@@ -44,7 +44,7 @@
/**
* Returns the name of this model.
- *
+ *
* @return the name of this model.
*/
String getName();
@@ -57,16 +57,22 @@
String getVersion();
/**
+ * @return the type of model.
+ * @since 2.6.3
+ */
+ String getModelType();
+
+ /**
* Returns the tagValues associated with this element.
- * For each entry, the key is the name of the tagValue, the value is the value of the tagValue :-)
- *
+ * For each entry, the key is the name of the tagValue, the value is the value of the tagValue :-)
+ *
* @return a Map containing all tagValues associated with this element
*/
Map<String, String> getTagValues();
/**
* Returns the tagValue corresponding to the given name, or null if the element has no associated tagValue for this name.
- *
+ *
* @param tagValue tag value key
* @return the value of the found tagValue, or null if the element has no associated tagValue for this name.
*/
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -30,6 +30,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.EugeneTagValues;
+import org.nuiton.eugene.ModelHelper;
import org.nuiton.eugene.ModelPropertiesUtil;
import org.nuiton.eugene.ModelReader;
import org.nuiton.eugene.models.object.reader.XmlObjectModelReader;
@@ -63,7 +64,6 @@
*
* @author fdesbois <fdesbois(a)codelutin.com>
* @version $Id$
- * @plexus.component role="org.nuiton.eugene.ModelReader" role-hint="objectmodel"
* @deprecated since 2.6.3, is replaced by {@link XmlObjectModelReader}.
*/
@Deprecated
@@ -111,6 +111,16 @@
public static final String MODEL = "model";
+ @Override
+ public String getModelType() {
+ return ModelHelper.ModelType.OBJECT.getAlias();
+ }
+
+ @Override
+ public String getInputType() {
+ return ModelHelper.ModelInputType.XML.getAlias();
+ }
+
/**
* @param files les noms des fichiers existant contenant du XML représentant
* des ObjectModel. Il est automatiquement recherche un fichier de
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -28,6 +28,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.EugeneTagValues;
+import org.nuiton.eugene.ModelHelper;
import org.nuiton.eugene.ModelPropertiesUtil;
import org.nuiton.eugene.ModelReader;
import org.nuiton.eugene.models.object.ObjectModel;
@@ -59,10 +60,10 @@
import java.util.regex.Pattern;
/**
- * TODO
+ * Abstract object model reader.
*
* @author tchemit <chemit(a)codelutin.com>
- * @since TODO
+ * @since 2.6.3
*/
public abstract class AbstractObjectModelReader extends ModelReader<ObjectModel> {
@@ -106,6 +107,11 @@
public static final String MODEL = "model";
+ @Override
+ public String getModelType() {
+ return ModelHelper.ModelType.OBJECT.getAlias();
+ }
+
protected abstract void readFileToModel(File file, ObjectModel model) throws IOException;
protected void beforeReadFile(File... files) {
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/XmlObjectModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/XmlObjectModelReader.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/XmlObjectModelReader.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -26,9 +26,9 @@
package org.nuiton.eugene.models.object.reader;
import org.apache.commons.digester3.Digester;
+import org.nuiton.eugene.ModelHelper;
import org.nuiton.eugene.models.object.ObjectModel;
import org.nuiton.eugene.models.object.xml.DigesterObjectModelRuleSet;
-import org.nuiton.eugene.models.object.xml.ObjectModelImpl;
import org.xml.sax.SAXException;
import java.io.File;
@@ -46,6 +46,11 @@
protected Digester digester;
@Override
+ public String getInputType() {
+ return ModelHelper.ModelInputType.XML.getAlias();
+ }
+
+ @Override
protected void beforeReadFile(File... files) {
super.beforeReadFile(files);
digester = new Digester();
@@ -55,7 +60,7 @@
@Override
protected void readFileToModel(File file, ObjectModel model) throws IOException {
try {
- digester.push(new ObjectModelImpl());
+ digester.push(model);
digester.parse(file);
} catch (SAXException e) {
throw new IOException("Unable to parse ObjectModel input file : " + file, e);
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -26,6 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.ModelHelper;
import org.nuiton.eugene.models.object.ObjectModel;
import java.io.File;
@@ -44,6 +45,11 @@
LogFactory.getLog(YamlObjectModelReader.class);
@Override
+ public String getInputType() {
+ return ModelHelper.ModelInputType.YAML.getAlias();
+ }
+
+ @Override
protected void beforeReadFile(File... files) {
super.beforeReadFile(files);
//TODO ?
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelImpl.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -28,6 +28,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.ModelHelper;
import org.nuiton.eugene.models.object.ObjectModel;
import org.nuiton.eugene.models.object.ObjectModelAttribute;
import org.nuiton.eugene.models.object.ObjectModelClass;
@@ -78,6 +79,11 @@
*/
private Map<String, Object> extensions = new HashMap<String, Object>();
+ @Override
+ public String getModelType() {
+ return ModelHelper.ModelType.OBJECT.getAlias();
+ }
+
public void setName(String name) {
this.name = name;
}
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelReader.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/state/StateModelReader.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -28,6 +28,7 @@
import org.apache.commons.digester3.Digester;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.ModelHelper;
import org.nuiton.eugene.ModelReader;
import org.nuiton.eugene.models.state.xml.DigesterStateModelRuleSet;
import org.nuiton.eugene.models.state.xml.StateModelImpl;
@@ -42,7 +43,7 @@
/**
* To read state model files into a memory state model.
- *
+ * <p/>
* Created: 26 oct. 2009
*
* @author fdesbois <fdesbois(a)codelutin.com>
@@ -54,6 +55,16 @@
private static final Log log = LogFactory.getLog(StateModelReader.class);
@Override
+ public String getModelType() {
+ return ModelHelper.ModelType.STATE.getAlias();
+ }
+
+ @Override
+ public String getInputType() {
+ return ModelHelper.ModelInputType.XML.getAlias();
+ }
+
+ @Override
public StateModel read(File... files) {
Digester digester = new Digester();
digester.addRuleSet(new DigesterStateModelRuleSet());
@@ -86,7 +97,7 @@
* @param stateModel
*/
protected void loadPropertyFile(File stateModelFile,
- StateModelImpl stateModel) {
+ StateModelImpl stateModel) {
// recherche et charge le fichier propriete associe au modele
File dir = stateModelFile.getParentFile();
String ext = FileUtil.extension(stateModelFile);
@@ -108,7 +119,7 @@
prop.load(inStream);
} catch (IOException e) {
log.warn("Cannot read property file " + propFile, e);
- }finally {
+ } finally {
try {
if (inStream != null) {
inStream.close();
@@ -119,7 +130,7 @@
}
// on ajoute les proprietes du fichier associe au model
- for (Enumeration<Object> e = prop.keys(); e.hasMoreElements();) {
+ for (Enumeration<Object> e = prop.keys(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
String value = prop.getProperty(key);
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/state/xml/StateModelImpl.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/state/xml/StateModelImpl.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/state/xml/StateModelImpl.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -25,6 +25,7 @@
package org.nuiton.eugene.models.state.xml;
+import org.nuiton.eugene.ModelHelper;
import org.nuiton.eugene.models.state.StateModel;
import org.nuiton.eugene.models.state.StateModelStateChart;
@@ -75,6 +76,11 @@
}
@Override
+ public String getModelType() {
+ return ModelHelper.ModelType.STATE.getAlias();
+ }
+
+ @Override
public String getName() {
return name;
}
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/writer/ChainedFileWriterConfiguration.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/writer/ChainedFileWriterConfiguration.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/writer/ChainedFileWriterConfiguration.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -25,6 +25,7 @@
package org.nuiton.eugene.writer;
+import org.nuiton.eugene.ModelHelper;
import org.nuiton.eugene.ModelReader;
import org.nuiton.eugene.Template;
@@ -79,10 +80,24 @@
/** @return the universe of availables writers */
Map<String, ChainedFileWriter> getWriters();
- /** @return the universe of available model readers */
+ /**
+ * @return model helper tool.
+ * @since 2.6.3
+ */
+ ModelHelper getModelHelper();
+
+ /**
+ * @return the universe of available model readers
+ * @deprecated since 2.6.3 (no more used, replaced by {@link ModelHelper#getModelReaders()}.
+ */
+ @Deprecated
Map<String, ModelReader<?>> getModelReaders();
- /** @return the universe of available model templates */
+ /**
+ * @return the universe of available model templates
+ * @deprecated since 2.6.3, no more used, won't be replaced
+ */
+ @Deprecated
Map<String, Template<?>> getModelTemplates();
/** @return properties to pass to writers */
Modified: trunk/eugene-maven-plugin/pom.xml
===================================================================
--- trunk/eugene-maven-plugin/pom.xml 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene-maven-plugin/pom.xml 2013-05-05 08:32:43 UTC (rev 1243)
@@ -218,8 +218,8 @@
<id>run-its</id>
<activation>
<property>
- <name>performRelease</name>
- <value>true</value>
+ <name>skipIts</name>
+ <value>!true</value>
</property>
</activation>
<build>
Modified: trunk/eugene-maven-plugin/src/it/evol-879/model/model-api/pom.xml
===================================================================
--- trunk/eugene-maven-plugin/src/it/evol-879/model/model-api/pom.xml 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene-maven-plugin/src/it/evol-879/model/model-api/pom.xml 2013-05-05 08:32:43 UTC (rev 1243)
@@ -46,8 +46,6 @@
<properties>
- <eugeneVersion>@pom.version@</eugeneVersion>
-
<!-- default encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Modified: trunk/eugene-maven-plugin/src/it/evol-879/model/model-impl/pom.xml
===================================================================
--- trunk/eugene-maven-plugin/src/it/evol-879/model/model-impl/pom.xml 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene-maven-plugin/src/it/evol-879/model/model-impl/pom.xml 2013-05-05 08:32:43 UTC (rev 1243)
@@ -78,7 +78,6 @@
<plugin>
<groupId>org.nuiton.eugene</groupId>
<artifactId>eugene-maven-plugin</artifactId>
- <version>${eugeneVersion}</version>
<configuration>
<fullPackagePath>org.nuiton.topia</fullPackagePath>
<defaultPackage>org.nuiton.topia</defaultPackage>
Modified: trunk/eugene-maven-plugin/src/it/evol-879/model/pom.xml
===================================================================
--- trunk/eugene-maven-plugin/src/it/evol-879/model/pom.xml 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene-maven-plugin/src/it/evol-879/model/pom.xml 2013-05-05 08:32:43 UTC (rev 1243)
@@ -38,24 +38,34 @@
<module>model-api</module>
<module>model-impl</module>
</modules>
-
+
<name>EUGene Test :: testEvol879-model</name>
<packaging>pom</packaging>
<properties>
- <eugeneVersion>@pom.version@</eugeneVersion>
-
<!-- default encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-
+
<!-- compiler configuration -->
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
-
+
</properties>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.nuiton.eugene</groupId>
+ <artifactId>eugene-maven-plugin</artifactId>
+ <version>@pom.version@</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
</project>
Modified: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/GenerateMojo.java
===================================================================
--- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/GenerateMojo.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/GenerateMojo.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -36,12 +36,12 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.nuiton.eugene.DefaultTemplateConfiguration;
+import org.nuiton.eugene.ModelHelper;
import org.nuiton.eugene.ModelPropertiesUtil;
import org.nuiton.eugene.ModelReader;
import org.nuiton.eugene.Template;
import org.nuiton.eugene.models.Model;
import org.nuiton.eugene.plugin.writer.BaseChainedFileWriter;
-import org.nuiton.eugene.plugin.writer.ModelChainedFileWriter;
import org.nuiton.eugene.plugin.writer.XmiChainedFileWriter;
import org.nuiton.eugene.plugin.writer.XmlModelChainedFileWriter;
import org.nuiton.eugene.plugin.writer.YamlModelChainedFileWriter;
@@ -327,6 +327,8 @@
@Component(role = ChainedWriterEngine.class)
protected ChainedWriterEngine engine;
+ protected ModelHelper modelHelper;
+
/** fixed classloader */
protected ClassLoader fixedClassLoader;
@@ -355,11 +357,14 @@
verbose = true;
}
+ modelHelper = new ModelHelper(_models, modelReaders);
+
modelType = modelType.trim().toLowerCase();
// Check model type is accepted
// pouvoir associé un nom à un type de service).
- Model model = _models.get(modelType);
+ Model model = modelHelper.getModel(modelType);
+// Model model = _models.get(modelType);
if (model == null) {
throw new MojoExecutionException(
"No modelType named '" + modelType + "', use one of " +
@@ -418,30 +423,30 @@
properties.put(XmiChainedFileWriter.PROP_RESOLVER, resolver);
}
- if (engine.containsWriter("model")) {
+// if (engine.containsWriter("model")) {
+//
+// // add model writer support
+//
+// properties.put(ModelChainedFileWriter.PROP_DEFAULT_PACKAGE,
+// defaultPackage);
+// properties.put(ModelChainedFileWriter.PROP_GENERATED_PACKAGES,
+// generatedPackages);
+// properties.put(ModelChainedFileWriter.PROP_TEMPLATES, templates);
+// properties.put(ModelChainedFileWriter.PROP_EXCLUDE_TEMPLATES,
+// getExcludeTemplatesAsString());
+// properties.put(ModelChainedFileWriter.PROP_MODEL_PROPERTIES_PROVIDER,
+// getModelPropertiesProvider());
+//
+// DefaultTemplateConfiguration configuration =
+// new DefaultTemplateConfiguration();
+// configuration.setEncoding(getEncoding());
+// configuration.setLoader(getClassLoader());
+// configuration.setOverwrite(isOverwrite());
+// configuration.setVerbose(isVerbose());
+// properties.put(ModelChainedFileWriter.PROP_TEMPLATE_CONFIGURATION,
+// configuration);
+// }
- // add model writer support
-
- properties.put(ModelChainedFileWriter.PROP_DEFAULT_PACKAGE,
- defaultPackage);
- properties.put(ModelChainedFileWriter.PROP_GENERATED_PACKAGES,
- generatedPackages);
- properties.put(ModelChainedFileWriter.PROP_TEMPLATES, templates);
- properties.put(ModelChainedFileWriter.PROP_EXCLUDE_TEMPLATES,
- getExcludeTemplatesAsString());
- properties.put(ModelChainedFileWriter.PROP_MODEL_PROPERTIES_PROVIDER,
- getModelPropertiesProvider());
-
- DefaultTemplateConfiguration configuration =
- new DefaultTemplateConfiguration();
- configuration.setEncoding(getEncoding());
- configuration.setLoader(getClassLoader());
- configuration.setOverwrite(isOverwrite());
- configuration.setVerbose(isVerbose());
- properties.put(ModelChainedFileWriter.PROP_TEMPLATE_CONFIGURATION,
- configuration);
- }
-
if (engine.containsWriter("xmlmodel")) {
// add xml model writer support
@@ -539,15 +544,6 @@
}
String message = reportGeneratedFiles(writer, t0);
getLog().info(message);
-
- if ("model".equals(writer.getInputProtocol())) {
-
- // must fix source compile roots
- File outputDir = writer.getOutputDirectory(
- getOutputDirectory(), isTestPhase());
-
- fixCompileSourceRoots(outputDir);
- }
}
// merge all models in a unique one ? or apply templates on each model ?
@@ -557,12 +553,18 @@
for (ChainedFileWriterToMemoryModel entry : models) {
Model model = entry.getModel();
Long lastModified = entry.getLastModifiedSource();
- File outputDirectory = entry.getOutputDirectory();
+ File outputDir = entry.getOutputDirectory();
- applyTemplates(model, lastModified, outputDirectory, templateList, writerReport);
+ applyTemplates(model,
+ lastModified,
+ outputDir,
+ templateList,
+ writerReport);
+
+ // must fix source compile roots
+ fixCompileSourceRoots(outputDir);
}
-
} finally {
// always clear everything to avoid side-effects in goal is
// invoked more than once
@@ -724,6 +726,11 @@
}
@Override
+ public ModelHelper getModelHelper() {
+ return modelHelper;
+ }
+
+ @Override
public File getBasedir() {
return getProject().getBasedir();
}
@@ -941,20 +948,16 @@
protected List<Template<Model>> initTemplates() {
- ChainedFileWriterConfiguration configuration = this;
+ ClassLoader loader = getClassLoader();
- ClassLoader loader = configuration.getClassLoader();
-
- boolean verbose = configuration.isVerbose();
-
Properties templateProperties = new Properties();
templateProperties.put(Template.PROP_DEFAULT_PACKAGE, defaultPackage);
- templateProperties.put(Template.PROP_ENCODING, configuration.getEncoding());
+ templateProperties.put(Template.PROP_ENCODING, getEncoding());
templateProperties.put(Template.PROP_VERBOSE, verbose);
- templateProperties.put(Template.PROP_OVERWRITE, configuration.isOverwrite());
+ templateProperties.put(Template.PROP_OVERWRITE, isOverwrite());
templateProperties.put(Template.PROP_CLASS_LOADER, loader);
- templateProperties.put(Template.PROP_EXCLUDE_TEMPLATES, excludeTemplates);
+ templateProperties.put(Template.PROP_EXCLUDE_TEMPLATES, getExcludeTemplatesAsString());
if (StringUtils.isEmpty(generatedPackages)) {
@@ -972,39 +975,39 @@
// init templates
List<Template<Model>> templatesList = new ArrayList<Template<Model>>();
- if (StringUtils.isEmpty(templates)) {
- throw new IllegalArgumentException("No template specified, use the templates parameter");
- }
- String[] templatesNames = templates.split(",");
- for (String templateName : templatesNames) {
- // remove trailing spaces
- templateName = templateName.trim();
- Template<Model> template =
- (Template<Model>) configuration.getModelTemplates().get(templateName);
+ if (StringUtils.isNotEmpty(templates)) {
- if (template == null) {
- getLog().warn("template [" + templateName + "] is not " +
- "registred via plexus, try to load it directly");
- try {
- template = (Template<Model>) Class.forName(
- templateName, true, loader).newInstance();
- } catch (Exception e) {
- throw new IllegalStateException(
- "Can't obtain template [" + templateName +
- "] for reason " + e.getMessage(), e);
+ String[] templatesNames = templates.split(",");
+ for (String templateName : templatesNames) {
+ // remove trailing spaces
+ templateName = templateName.trim();
+ Template<Model> template =
+ (Template<Model>) modelTemplates.get(templateName);
+
+ if (template == null) {
+ getLog().warn("template [" + templateName + "] is not " +
+ "registred via plexus, try to load it directly");
+ try {
+ template = (Template<Model>) Class.forName(
+ templateName, true, loader).newInstance();
+ } catch (Exception e) {
+ throw new IllegalStateException(
+ "Can't obtain template [" + templateName +
+ "] for reason " + e.getMessage(), e);
+ }
}
- }
- if (verbose) {
- getLog().info("will use the template [" + templateName + "]");
- }
+ if (verbose) {
+ getLog().info("will use the template [" + templateName + "]");
+ }
- // will use this template
- templatesList.add(template);
+ // will use this template
+ templatesList.add(template);
- // set the properties of the template
- template.setConfiguration(
- new DefaultTemplateConfiguration(templateProperties));
+ // set the properties of the template
+ template.setConfiguration(
+ new DefaultTemplateConfiguration(templateProperties));
+ }
}
return templatesList;
}
Added: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/BaseChainedFileWriterToMemoryModel.java
===================================================================
--- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/BaseChainedFileWriterToMemoryModel.java (rev 0)
+++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/BaseChainedFileWriterToMemoryModel.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -0,0 +1,191 @@
+package org.nuiton.eugene.plugin.writer;
+
+/*
+ * #%L
+ * EUGene :: Maven plugin
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2006 - 2013 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>.
+ * #L%
+ */
+
+import org.nuiton.eugene.ModelPropertiesUtil;
+import org.nuiton.eugene.ModelReader;
+import org.nuiton.eugene.models.Model;
+import org.nuiton.eugene.writer.ChainedFileWriterConfiguration;
+import org.nuiton.eugene.writer.ChainedFileWriterToMemoryModel;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.3
+ */
+public abstract class BaseChainedFileWriterToMemoryModel extends BaseChainedFileWriter implements ChainedFileWriterToMemoryModel {
+
+ public static final String PROP_MODEL_READER = "modelReader";
+
+ public static final String PROP_MODEL_PROPERTIES_PROVIDER = "modelPropertiesProvider";
+
+ public static final String PROP_READER = "reader";
+
+ protected Model model;
+
+ protected long lastModifiedSource;
+
+ protected File outputDirectory;
+
+ protected BaseChainedFileWriterToMemoryModel() {
+ super(
+ PROP_READER, "reader",
+ PROP_MODEL_READER, "xmlModelReader",
+ PROP_MODEL_PROPERTIES_PROVIDER, "modelPropertiesProvider"
+ );
+ }
+
+ @Override
+ public Model getModel() {
+ return model;
+ }
+
+ public long getLastModifiedSource() {
+ return lastModifiedSource;
+ }
+
+ @Override
+ public File getOutputDirectory() {
+ return outputDirectory;
+ }
+
+ @Override
+ public String getOutputProtocol(String modelType) {
+ // nothing after java files
+ //TODO check in engine that a memory chained file has null output protocol
+ return null;
+ }
+
+ @Override
+ public boolean acceptModel(String modelType) {
+ // accept all models
+ return acceptObjectModelOrStateModel(modelType);
+ }
+
+ protected abstract String getInputType();
+
+ protected ModelReader<?> getModelReader() {
+ return getProperty(PROP_MODEL_READER, ModelReader.class);
+ }
+
+ protected String getReader() {
+ return getProperty(PROP_READER, String.class);
+ }
+
+ protected ModelPropertiesUtil.ModelPropertiesProvider getModelPropertiesProvider() {
+ return getProperty(PROP_MODEL_PROPERTIES_PROVIDER, ModelPropertiesUtil.ModelPropertiesProvider.class);
+ }
+
+ @Override
+ protected void initWriter(ChainedFileWriterConfiguration configuration) {
+ super.initWriter(configuration);
+
+ // obtain a reader
+ ClassLoader classLoader = configuration.getClassLoader();
+ ClassLoader loader = classLoader;
+ if (getModelReader() == null) {
+
+ String modelType = configuration.getModelType();
+
+ if (getReader() != null) {
+ // use a specific reader
+ String reader = getReader();
+ try {
+ ClassLoader fixedClassLoader = loader;
+ ModelReader<?> modelReader = (ModelReader<?>)
+ Class.forName(reader, true,
+ fixedClassLoader).newInstance();
+ String modelTypeFromReader = modelReader.getModelType();
+ if (!modelType.equals(modelTypeFromReader)) {
+ throw new IllegalStateException("Model reader [" + modelTypeFromReader + "] does not match with modelType: " + modelType);
+ }
+ properties.put(PROP_MODEL_READER, modelReader);
+ } catch (IllegalStateException eee) {
+ throw eee;
+ } catch (Exception eee) {
+ throw new IllegalStateException("could not obtain reader "
+ + reader, eee);
+ }
+ } else {
+
+ String inputType = getInputType();
+ ModelReader<?> modelReader = configuration.getModelHelper().getModelReader(modelType, inputType);
+ if (modelReader == null) {
+ throw new IllegalStateException(
+ "could not find a model reader for modelType: " +
+ modelType + ", and input type: " + inputType + ", availables readers : " +
+ configuration.getModelHelper().getModelReaders().values());
+ }
+ properties.put(PROP_MODEL_READER, modelReader);
+ }
+ }
+
+ boolean verbose = configuration.isVerbose();
+
+ // gets the provider of safe tag values and stereotypes
+ ModelPropertiesUtil.ModelPropertiesProvider propertiesProvider =
+ getModelPropertiesProvider();
+
+ // affect it to the model reader
+ getModelReader().setModelPropertiesProvider(propertiesProvider);
+
+ // set the verbose level of the model reader
+ getModelReader().setVerbose(verbose);
+ }
+
+ @Override
+ public void generate(ChainedFileWriterConfiguration configuration,
+ File outputDir,
+ Map<File, List<File>> filesByRoot,
+ Map<File, List<File>> resourcesByFile) throws IOException {
+
+ Set<File> modelFiles = new HashSet<File>();
+ for (List<File> files : filesByRoot.values()) {
+ modelFiles.addAll(files);
+ }
+ File[] filesToRead = modelFiles.toArray(new File[modelFiles.size()]);
+
+ if (configuration.isVerbose()) {
+ getLog().info("Will read " + filesToRead.length + " model(s).");
+ }
+
+ // read memory model from all files models
+ model = getModelReader().read(filesToRead);
+
+ // get the last modified source timestamp from reader
+ lastModifiedSource = getModelReader().getLastModifiedSource();
+
+ // set the ouput directory
+ outputDirectory = outputDir;
+ }
+}
Property changes on: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/BaseChainedFileWriterToMemoryModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java
===================================================================
--- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -195,13 +195,13 @@
}
} else {
String modelType = configuration.getModelType();
- ModelReader<?> modelReader =
- configuration.getModelReaders().get(modelType);
+ ModelReader<?> modelReader = configuration.getModelHelper().getModelReader(modelType, "xml");
+ configuration.getModelHelper().getModelReaders().get(modelType);
if (modelReader == null) {
throw new IllegalStateException(
"could not find a model reader for modelType : " +
modelType + ", availables readers : " +
- configuration.getModelReaders().values());
+ configuration.getModelHelper().getModelReaders().values());
}
properties.put(PROP_MODEL_READER, modelReader);
}
Modified: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmiChainedFileWriter.java
===================================================================
--- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmiChainedFileWriter.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmiChainedFileWriter.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -94,7 +94,7 @@
@Override
public String getOutputProtocol(String modelType) {
// next writer : write from model files
- return "xmlmodel";
+ return "model";
}
@Override
Modified: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmlModelChainedFileWriter.java
===================================================================
--- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmlModelChainedFileWriter.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmlModelChainedFileWriter.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -25,19 +25,6 @@
package org.nuiton.eugene.plugin.writer;
-import org.nuiton.eugene.ModelPropertiesUtil;
-import org.nuiton.eugene.ModelReader;
-import org.nuiton.eugene.models.Model;
-import org.nuiton.eugene.writer.ChainedFileWriterConfiguration;
-import org.nuiton.eugene.writer.ChainedFileWriterToMemoryModel;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* To create a memory model from xml model files.
*
@@ -45,61 +32,24 @@
* @plexus.component role="org.nuiton.eugene.writer.ChainedFileWriter" role-hint="xmlModel2Memory"
* @since 2.6.3
*/
-public class XmlModelChainedFileWriter extends BaseChainedFileWriter implements ChainedFileWriterToMemoryModel {
+public class XmlModelChainedFileWriter extends BaseChainedFileWriterToMemoryModel {
- public static final String PROP_XML_MODEL_READER = "xmlModelReader";
- public static final String PROP_MODEL_PROPERTIES_PROVIDER = "modelPropertiesProvider";
-
- public static final String PROP_READER = "reader";
-
- protected Model model;
-
- protected long lastModifiedSource;
-
- protected File outputDirectory;
-
public XmlModelChainedFileWriter() {
- super(
- PROP_READER, "reader",
- PROP_XML_MODEL_READER, "modelReader",
- PROP_MODEL_PROPERTIES_PROVIDER, "modelPropertiesProvider"
- );
+ super();
}
@Override
- public Model getModel() {
- return model;
+ protected String getInputType() {
+ return "xml";
}
- public long getLastModifiedSource() {
- return lastModifiedSource;
- }
-
@Override
- public File getOutputDirectory() {
- return outputDirectory;
- }
-
- @Override
public String getInputProtocol() {
- return "xmlmodel";
+ return "model";
}
@Override
- public String getOutputProtocol(String modelType) {
- // nothing after java files
- //TODO check in engine that a memory chained file has null output protocol
- return null;
- }
-
- @Override
- public boolean acceptModel(String modelType) {
- // accept all models
- return acceptObjectModelOrStateModel(modelType);
- }
-
- @Override
public boolean acceptInclude(String include) {
return include.startsWith("model:") ||
include.endsWith(".objectmodel") ||
@@ -130,95 +80,4 @@
public String getDefaultTestOutputDirectory() {
return "test-java";
}
-
- protected ModelReader<?> getModelReader() {
- return getProperty(PROP_XML_MODEL_READER, ModelReader.class);
- }
-
- protected String getReader() {
- return getProperty(PROP_READER, String.class);
- }
-
- protected ModelPropertiesUtil.ModelPropertiesProvider getModelPropertiesProvider() {
- return getProperty(PROP_MODEL_PROPERTIES_PROVIDER, ModelPropertiesUtil.ModelPropertiesProvider.class);
- }
-
- @Override
- protected void initWriter(ChainedFileWriterConfiguration configuration) {
- super.initWriter(configuration);
-
- // obtain a reader
- ClassLoader classLoader = configuration.getClassLoader();
- ClassLoader loader = classLoader;
- if (getModelReader() == null) {
-
- if (getReader() != null) {
- // use a specific reader
- String reader = getReader();
- try {
- ClassLoader fixedClassLoader = loader;
- ModelReader<?> modelReader = (ModelReader<?>)
- Class.forName(reader, true,
- fixedClassLoader).newInstance();
- //TODO : should check that the reader is compatible with
- //TODO : given modelType
- properties.put(PROP_XML_MODEL_READER, modelReader);
- } catch (Exception eee) {
- throw new IllegalStateException("could not obtain reader "
- + reader, eee);
- }
- } else {
- String modelType = configuration.getModelType();
- ModelReader<?> modelReader =
- configuration.getModelReaders().get(modelType);
- if (modelReader == null) {
- throw new IllegalStateException(
- "could not find a model reader for modelType : " +
- modelType + ", availables readers : " +
- configuration.getModelReaders().values());
- }
- properties.put(PROP_XML_MODEL_READER, modelReader);
- }
- }
-
- boolean verbose = configuration.isVerbose();
-
- // gets the provider of safe tag values and stereotypes
- ModelPropertiesUtil.ModelPropertiesProvider propertiesProvider =
- getModelPropertiesProvider();
-
- // affect it to the model reader
- getModelReader().setModelPropertiesProvider(propertiesProvider);
-
- // set the verbose level of the model reader
- getModelReader().setVerbose(verbose);
- }
-
- @Override
- public void generate(ChainedFileWriterConfiguration configuration,
- File outputDir,
- Map<File, List<File>> filesByRoot,
- Map<File, List<File>> resourcesByFile) throws IOException {
-
- Set<File> modelFiles = new HashSet<File>();
- for (List<File> files : filesByRoot.values()) {
- modelFiles.addAll(files);
- }
- File[] filesToRead = modelFiles.toArray(new File[modelFiles.size()]);
-
- if (configuration.isVerbose()) {
- getLog().info("Will read " + filesToRead.length + " model(s).");
- }
-
- // read memory model from all files models
-
- model = getModelReader().read(filesToRead);
-
- // get the last modified source timestamp from reader
- lastModifiedSource = getModelReader().getLastModifiedSource();
-
- outputDirectory = outputDir;
-
- }
-
}
Modified: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/YamlModelChainedFileWriter.java
===================================================================
--- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/YamlModelChainedFileWriter.java 2013-05-04 11:25:19 UTC (rev 1242)
+++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/YamlModelChainedFileWriter.java 2013-05-05 08:32:43 UTC (rev 1243)
@@ -24,19 +24,6 @@
* #L%
*/
-import org.nuiton.eugene.ModelPropertiesUtil;
-import org.nuiton.eugene.ModelReader;
-import org.nuiton.eugene.models.Model;
-import org.nuiton.eugene.writer.ChainedFileWriterConfiguration;
-import org.nuiton.eugene.writer.ChainedFileWriterToMemoryModel;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* To create a memory model from yaml model files.
*
@@ -44,62 +31,23 @@
* @plexus.component role="org.nuiton.eugene.writer.ChainedFileWriter" role-hint="yamlModel2Memory"
* @since 2.6.3
*/
-public class YamlModelChainedFileWriter extends BaseChainedFileWriter implements ChainedFileWriterToMemoryModel {
+public class YamlModelChainedFileWriter extends BaseChainedFileWriterToMemoryModel {
- public static final String PROP_YAML_MODEL_READER = "yamlModelReader";
-
- public static final String PROP_MODEL_PROPERTIES_PROVIDER = "modelPropertiesProvider";
-
- public static final String PROP_READER = "reader";
-
- protected Model model;
-
- protected long lastModifiedSource;
-
- protected File outputDirectory;
-
public YamlModelChainedFileWriter() {
- super(
- PROP_READER, "reader",
- PROP_YAML_MODEL_READER, "yamlModelReader",
- PROP_MODEL_PROPERTIES_PROVIDER, "modelPropertiesProvider"
- );
+ super();
}
@Override
- public Model getModel() {
- return model;
+ protected String getInputType() {
+ return "yaml";
}
@Override
- public long getLastModifiedSource() {
- return lastModifiedSource;
- }
-
- @Override
- public File getOutputDirectory() {
- return outputDirectory;
- }
-
- @Override
public String getInputProtocol() {
return "yamlmodel";
}
@Override
- public String getOutputProtocol(String modelType) {
- // nothing after java files
- //TODO check in engine that a memory chained file has null output protocol
- return null;
- }
-
- @Override
- public boolean acceptModel(String modelType) {
- // accept all models
- return acceptObjectModelOrStateModel(modelType);
- }
-
- @Override
public boolean acceptInclude(String include) {
return include.startsWith("yaml:") ||
include.endsWith(".yamlobjectmodel") ||
@@ -130,94 +78,4 @@
public String getDefaultTestOutputDirectory() {
return "test-java";
}
-
- protected ModelReader<?> getModelReader() {
- return getProperty(PROP_YAML_MODEL_READER, ModelReader.class);
- }
-
- protected String getReader() {
- return getProperty(PROP_READER, String.class);
- }
-
- protected ModelPropertiesUtil.ModelPropertiesProvider getModelPropertiesProvider() {
- return getProperty(PROP_MODEL_PROPERTIES_PROVIDER, ModelPropertiesUtil.ModelPropertiesProvider.class);
- }
-
- @Override
- protected void initWriter(ChainedFileWriterConfiguration configuration) {
- super.initWriter(configuration);
-
- // obtain a reader
- ClassLoader classLoader = configuration.getClassLoader();
- ClassLoader loader = classLoader;
- if (getModelReader() == null) {
-
- if (getReader() != null) {
- // use a specific reader
- String reader = getReader();
- try {
- ClassLoader fixedClassLoader = loader;
- ModelReader<?> modelReader = (ModelReader<?>)
- Class.forName(reader, true,
- fixedClassLoader).newInstance();
- //TODO : should check that the reader is compatible with
- //TODO : given modelType
- properties.put(PROP_YAML_MODEL_READER, modelReader);
- } catch (Exception eee) {
- throw new IllegalStateException("could not obtain reader "
- + reader, eee);
- }
- } else {
- String modelType = configuration.getModelType();
- ModelReader<?> modelReader =
- configuration.getModelReaders().get(modelType);
- if (modelReader == null) {
- throw new IllegalStateException(
- "could not find a model reader for modelType : " +
- modelType + ", availables readers : " +
- configuration.getModelReaders().values());
- }
- properties.put(PROP_YAML_MODEL_READER, modelReader);
- }
- }
-
- boolean verbose = configuration.isVerbose();
-
- // gets the provider of safe tag values and stereotypes
- ModelPropertiesUtil.ModelPropertiesProvider propertiesProvider =
- getModelPropertiesProvider();
-
- // affect it to the model reader
- getModelReader().setModelPropertiesProvider(propertiesProvider);
-
- // set the verbose level of the model reader
- getModelReader().setVerbose(verbose);
- }
-
- @Override
- public void generate(ChainedFileWriterConfiguration configuration,
- File outputDir,
- Map<File, List<File>> filesByRoot,
- Map<File, List<File>> resourcesByFile) throws IOException {
-
- Set<File> modelFiles = new HashSet<File>();
- for (List<File> files : filesByRoot.values()) {
- modelFiles.addAll(files);
- }
- File[] filesToRead = modelFiles.toArray(new File[modelFiles.size()]);
-
- if (configuration.isVerbose()) {
- getLog().info("Will read " + filesToRead.length + " model(s).");
- }
-
- // read memory model from all files models
-
- model = getModelReader().read(filesToRead);
-
- // get the last modified source timestamp from reader
- lastModifiedSource = getModelReader().getLastModifiedSource();
-
- outputDirectory = outputDir;
- }
-
}
1
0
r1242 - in trunk: eugene/src/main/java/org/nuiton/eugene/models/object eugene/src/main/java/org/nuiton/eugene/models/object/reader eugene/src/main/java/org/nuiton/eugene/writer eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer
by tchemit@users.nuiton.org 04 May '13
by tchemit@users.nuiton.org 04 May '13
04 May '13
Author: tchemit
Date: 2013-05-04 13:25:19 +0200 (Sat, 04 May 2013)
New Revision: 1242
Url: http://nuiton.org/projects/eugene/repository/revisions/1242
Log:
refs #2681: Make possible to apply templates to different inputs
Added:
trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmlModelChainedFileWriter.java
trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/YamlModelChainedFileWriter.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/XmlObjectModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/package-info.java
trunk/eugene/src/main/java/org/nuiton/eugene/writer/ChainedFileWriterToMemoryModel.java
Modified:
trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/GenerateMojo.java
trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java
trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmiChainedFileWriter.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java 2013-05-02 14:39:36 UTC (rev 1241)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java 2013-05-04 11:25:19 UTC (rev 1242)
@@ -32,6 +32,7 @@
import org.nuiton.eugene.EugeneTagValues;
import org.nuiton.eugene.ModelPropertiesUtil;
import org.nuiton.eugene.ModelReader;
+import org.nuiton.eugene.models.object.reader.XmlObjectModelReader;
import org.nuiton.eugene.models.object.xml.DigesterObjectModelRuleSet;
import org.nuiton.eugene.models.object.xml.ObjectModelAssociationClassImpl;
import org.nuiton.eugene.models.object.xml.ObjectModelClassifierImpl;
@@ -63,7 +64,9 @@
* @author fdesbois <fdesbois(a)codelutin.com>
* @version $Id$
* @plexus.component role="org.nuiton.eugene.ModelReader" role-hint="objectmodel"
+ * @deprecated since 2.6.3, is replaced by {@link XmlObjectModelReader}.
*/
+@Deprecated
public class ObjectModelReader extends ModelReader<ObjectModel> {
private static final Log log = LogFactory.getLog(ObjectModelReader.class);
Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java 2013-05-04 11:25:19 UTC (rev 1242)
@@ -0,0 +1,579 @@
+package org.nuiton.eugene.models.object.reader;
+
+/*
+ * #%L
+ * EUGene :: EUGene
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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>.
+ * #L%
+ */
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.EugeneTagValues;
+import org.nuiton.eugene.ModelPropertiesUtil;
+import org.nuiton.eugene.ModelReader;
+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.ObjectModelClassifier;
+import org.nuiton.eugene.models.object.ObjectModelElement;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.eugene.models.object.xml.ObjectModelAssociationClassImpl;
+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.util.FileUtil;
+import org.nuiton.util.RecursiveProperties;
+import org.nuiton.util.StringUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since TODO
+ */
+public abstract class AbstractObjectModelReader extends ModelReader<ObjectModel> {
+
+ private static final Log log = LogFactory.getLog(AbstractObjectModelReader.class);
+
+ public static final String TAGVALUE = "tagvalue";
+
+ public static final String STEREOTYPE = "stereotype";
+
+ public static final String OPERATION = "operation";
+
+ public static final String ATTRIBUTE = "attribute";
+
+ public static final String CLASS = "class";
+
+ /**
+ * Pattern to define tag values authorized at classifier level in the model
+ * properties file.
+ * <p/>
+ * 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-zA-Z0-9]+)\\.)?(?:(tagvalue|tagValue)?)\\.([_a-z0-9][_a-zA-Z0-9]*)?$");
+
+ protected Pattern stereotypePattern = Pattern
+ .compile("^((?:[_a-zA-Z0-9]+\\.)+(?:_?[A-Z][_a-zA-Z0-9]*\\.)+)(?:(class|attribute|operation))\\.(?:([_a-zA-Z0-9]+)\\.)?(?:(stereotype)?)$");
+
+ /**
+ * Pattern to define tag values authorized at model level in the model
+ * properties file.
+ */
+ protected Pattern modelTagValuePattern = Pattern.compile(
+ "^model\\.(?:(tagvalue|tagValue)?)\\.((?:.+))$");
+
+ public static final String MODEL = "model";
+
+ protected abstract void readFileToModel(File file, ObjectModel model) throws IOException;
+
+ protected void beforeReadFile(File... files) {
+ setLastModifiedSource(files);
+ if (log.isDebugEnabled()) {
+ log.debug("LastModifiedSource = " + getLastModifiedSource() +
+ " for file " + Arrays.toString(files));
+ }
+
+ if (modelPropertiesProvider == null) {
+ if (log.isWarnEnabled()) {
+ log.warn("No properties provider filled, will instanciate a new default one");
+ }
+ setModelPropertiesProvider(ModelPropertiesUtil.newStore(getClass().getClassLoader(), false));
+ }
+ }
+
+ @Override
+ public ObjectModel read(File... files) throws IOException {
+
+ beforeReadFile(files);
+
+ ObjectModel model = new ObjectModelImpl();
+
+ for (File file : files) {
+
+ readFileToModel(file, model);
+
+ // 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");
+ if (!propFile.exists()) {
+ if (isVerbose()) {
+ log.info("Pas de fichier de propriete " + propFile
+ + " associé au model");
+ }
+ } else {
+ if (isVerbose()) {
+ log.info("Lecture du fichier de propriete " + propFile
+ + " associé au model");
+ }
+ loadModelProperties(propFile, model);
+ }
+
+ }
+
+
+ if (log.isDebugEnabled()) {
+ for (ObjectModelClass m : model.getClasses()) {
+ log.debug("loaded class in objectmodel : " + m.getName());
+ }
+ }
+ return model;
+ }
+
+ /**
+ * Retrieve an attribute from a {@code clazz} with its {@code name}.
+ * This method manage the association class case to explore participants
+ * attributes if needed.
+ *
+ * @param clazz where the attribute need to be find
+ * @param name attribute name to find
+ * @return the attribute found or null
+ */
+ protected ObjectModelAttribute getAttribute(ObjectModelClass clazz,
+ String name) {
+ ObjectModelAttribute result = clazz.getAttribute(name);
+
+ // Ano #619 : FD-2010-05-17 : Specific case for Association class :
+ // check on participant attributes
+ if (result == null && clazz instanceof ObjectModelAssociationClassImpl) {
+ if (log.isDebugEnabled()) {
+ log.debug("Attribute " + name + " not found from " +
+ clazz.getQualifiedName() + " association class. " +
+ "Will check participants...");
+ }
+ ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz;
+ for (ObjectModelAttribute participant : assoc.getParticipantsAttributes()) {
+ if (participant.getName().equals(name)) {
+ result = participant;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ public Properties loadModelProperties(File propFile,
+ ObjectModel model) throws IOException {
+
+ Properties prop = new RecursiveProperties();
+// try {
+ FileInputStream inStream = new FileInputStream(propFile);
+ try {
+ prop.load(inStream);
+ } finally {
+ inStream.close();
+ }
+
+ // number of sucessfull imported tag values into model
+ int numberImportedTagValues = 0;
+
+ // get all the tagvalues keys and sort them
+ List<String> keys = new ArrayList<String>();
+ CollectionUtils.addAll(keys, prop.keys());
+ Collections.sort(keys);
+
+ // for each tag value try to import in in model
+ for (String key : keys) {
+ String value = prop.getProperty(key);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Propriete: '" + key + "' = " + value);
+ }
+
+ if (key.startsWith(MODEL)) {
+
+ // model tag value
+
+ boolean loaded = loadModelTagValue(model, key, value);
+
+ if (loaded) {
+
+ numberImportedTagValues++;
+ }
+ continue;
+ }
+
+ // element tag value or stereotype
+
+ if (key.contains(STEREOTYPE)) {
+
+ // stereotype property
+
+ boolean loaded = loadStereotype(model, key, value);
+
+ if (loaded) {
+ numberImportedTagValues++;
+ }
+
+ continue;
+
+ }
+
+ // tag value property
+
+ boolean loaded = loadTagValue(model, key, value);
+
+ if (loaded) {
+ numberImportedTagValues++;
+ }
+ }
+ if (log.isInfoEnabled()) {
+ log.info(numberImportedTagValues + " tag values were succesfull imported from " + propFile);
+ }
+ int nbFailed = prop.size() - numberImportedTagValues;
+ if (nbFailed > 0 && isVerbose()) {
+ log.info(nbFailed + " tag values failed to be imported from " + propFile);
+ }
+ return prop;
+ }
+
+ public boolean loadModelTagValue(ObjectModel model, String key, String value) {
+ Matcher matcher = modelTagValuePattern.matcher(key);
+
+ if (!matcher.find()) {
+ if (log.isWarnEnabled()) {
+ log.warn("Invalid model tag value [" + key + "] : only tagvalue or tagValue is allowed on model in properties");
+ }
+ return false;
+ }
+ String tag = matcher.group(2);
+
+ boolean safe = modelPropertiesProvider.containsTagValue(tag);
+
+ if (!safe) {
+ if (log.isWarnEnabled()) {
+ log.warn("Invalid model tag value [" + key + "] : the tagvalue '" + tag + "' is unkown.");
+ }
+ } else {
+ safe = modelPropertiesProvider.acceptTagValue(tag, ObjectModel.class);
+
+ if (!safe) {
+
+ // the tag value can not be apply of model
+ if (log.isWarnEnabled()) {
+ log.warn("Invalid model tag value [" + key + "] : this tagvalue '" + tag + "' can not be apply on the model.");
+ }
+ }
+ }
+
+ if (!safe && isStrictLoading()) {
+
+ // in strict loading do not accept unsafe tags
+ return false;
+ }
+
+ ObjectModelImpl modelImpl = (ObjectModelImpl) model;
+ if (tag.equals(EugeneTagValues.TAG_VERSION)) {
+
+ // push directly the version in the model version
+ // property
+ modelImpl.setVersion(value);
+ }
+ if (isVerbose()) {
+ log.info("model tag value imported " + key + " --> " + tag + " = " + value);
+ }
+ modelImpl.addTagValue(tag, value);
+ return true;
+ }
+
+ public boolean loadStereotype(ObjectModel model, String key, String value) {
+ Matcher matcher = stereotypePattern.matcher(key);
+
+ if (!matcher.find()) {
+
+ if (log.isWarnEnabled()) {
+ log.warn("Invalid stereotype [" + key + "] : syntax is not correct.");
+ }
+ return false;
+ }
+
+ 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
+ String type = matcher.group(4).toLowerCase();
+ // target real type
+ Class<?> targetType = getTargetType(target);
+
+ boolean safe = modelPropertiesProvider.containsStereotype(value);
+
+ if (!safe) {
+
+ // stereotype unkown
+ if (log.isWarnEnabled()) {
+ log.warn("Invalid stereotype [" + key + "] : this stereotype '" + value + "' is unkown.");
+ }
+ } else {
+
+ safe = modelPropertiesProvider.acceptStereotype(value, targetType);
+
+ if (!safe) {
+
+ // the stereotype can not be apply of the given target
+ if (log.isWarnEnabled()) {
+ log.warn("Invalid stereotype [" + key + "] : this stereotype '" + value + "' can not be apply on " + target + ".");
+ }
+ }
+ }
+
+ if (!safe && isStrictLoading()) {
+
+ // in strict loading do not accept unsafe stereotypes
+ return false;
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Propriete: '" + key + "' => "
+ + "fqn:" + fqn + " target:" + target
+ + " targetName:" + targetName
+ + " type:" + type);
+ }
+
+ ObjectModelClassifier omc = getClassifier(model, STEREOTYPE, key, fqn);
+ if (omc == null) {
+
+ // classifier not found
+ return false;
+ }
+
+ List<ObjectModelElement> elems = getObjectElements(omc, STEREOTYPE, key, fqn, target, targetName);
+
+ if (elems == null) {
+
+ // no element to apply
+ return false;
+ }
+
+ for (ObjectModelElement elem1 : elems) {
+ //TODO tchemit 2010-11-29 uncomment this if there is some proble, but I don't see why there would be...
+// if (elem1 == null) {
+// if (log.isWarnEnabled()) {
+// log.warn("Invalid stereotype [" + key + "] : Element '" + targetName + "' of type '" + target + "' on classifier '" + fqn + "' is null.");
+// }
+// continue;
+// }
+ ObjectModelElementImpl elem = (ObjectModelElementImpl) elem1;
+
+ // pour les stereotypes
+ ObjectModelImplRef stereotype = new ObjectModelImplRef();
+ stereotype.setName(value);
+ elem.addStereotype(stereotype);
+ }
+
+ if (isVerbose()) {
+ log.info("stereotype imported " + key + " --> " + fqn + ":" + target + ":" + targetName + ":" + type + " = " + value);
+ }
+
+ return true;
+ }
+
+ private boolean loadTagValue(ObjectModel model, String key, String value) {
+ Matcher matcher = propertiesPattern.matcher(key);
+
+ if (!matcher.find()) {
+
+ if (log.isWarnEnabled()) {
+ log.warn("Invalid tag value [" + key + "] : syntax is not correct.");
+ }
+ return false;
+ }
+
+ String fqn = matcher.group(1);
+ fqn = StringUtil.substring(fqn, 0, -1); // remove ended
+ // .
+ // target is class, attribute or operation
+ String target = matcher.group(2);
+ // name of the target (can be null on class)
+ String targetName = matcher.group(3);
+ // type is tagvalue
+ String type = matcher.group(4).toLowerCase();
+ // name of the tag value
+ String tag = matcher.group(5);
+ // target real type
+ Class<?> targetType = getTargetType(target);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Propriete: '" + key + "' => "
+ + "fqn:" + fqn + " target:" + target
+ + " targetName:" + targetName
+ + " type:" + type + " tag:" + tag);
+ }
+
+ boolean safe = modelPropertiesProvider.containsTagValue(tag);
+
+ if (!safe) {
+
+ // unkown tag value
+ if (log.isWarnEnabled()) {
+ log.warn("Invalid tag value [" + key + "] : this tagvalue '" + tag + "' is unkown.");
+ }
+ } else {
+
+ safe = modelPropertiesProvider.acceptTagValue(tag, targetType);
+
+ if (!safe) {
+
+ // the tag value can not be apply of model
+ if (log.isWarnEnabled()) {
+ log.warn("Invalid tag value [" + key + "] : this tagvalue '" + tag + "' can not be apply on the given type '" + target + "'.");
+ }
+ }
+ }
+
+ if (!safe && isStrictLoading()) {
+
+ // in strict loading do not accept unsafe tags
+ return false;
+ }
+
+ ObjectModelClassifier omc = getClassifier(model, TAGVALUE, key, fqn);
+ if (omc == null) {
+
+ // classifier not found
+ return false;
+ }
+
+ List<ObjectModelElement> elements =
+ getObjectElements(omc, TAGVALUE, key, fqn, target, targetName);
+
+ if (elements == null) {
+
+ // no elements to apply
+ return false;
+ }
+
+ for (ObjectModelElement element : elements) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("add tagValue " + tag
+ + ", value:" + value
+ + " to element:" + element);
+ }
+ ((ObjectModelElementImpl) element).addTagValue(tag, value);
+
+ }
+ if (isVerbose()) {
+ log.info("tag value imported " + key + " --> " + fqn + ":" + target + ":" + targetName + ":" + type + ":" + tag + " = " + value);
+ }
+ return true;
+ }
+
+ protected Class<?> getTargetType(String target) {
+ Class<?> result = null;
+ if (ATTRIBUTE.equals(target)) {
+ return ObjectModelAttribute.class;
+ }
+ if (OPERATION.equals(target)) {
+ return ObjectModelOperation.class;
+ }
+ if (CLASS.equals(target)) {
+ return ObjectModelClassifier.class;
+ }
+
+ return result;
+ }
+
+ protected ObjectModelClassifier getClassifier(ObjectModel model, String type, String key, String fqn) {
+ ObjectModelClassifier omc = model.getClassifier(fqn);
+ if (omc == null) {
+ if (log.isWarnEnabled()) {
+ log.warn("Invalid " + type + " [" + key +
+ "] : Could not find classifier for " + fqn);
+ }
+ return null;
+ }
+
+ //todo tchemit 2010-11-25 : what does it mean ? every thing extends ObjectModelClassifierImpl
+ if (!(omc instanceof ObjectModelClassifierImpl)) {
+ // 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 : " +
+ omc.getQualifiedName());
+ }
+ return null;
+ }
+ return omc;
+ }
+
+ protected List<ObjectModelElement> getObjectElements(ObjectModelClassifier omc, String type, String key, String fqn, String target, String targetName) {
+ List<ObjectModelElement> elems = new ArrayList<ObjectModelElement>();
+ if (CLASS.equals(target)) {
+ elems.add(omc);
+ } else if (ATTRIBUTE.equals(target)) {
+
+ ObjectModelAttribute attr =
+ getAttribute((ObjectModelClass) omc, targetName);
+ elems.add(attr);
+
+ } else if (OPERATION.equals(target)) {
+ elems.addAll(omc.getOperations(targetName));
+ }
+
+ if (elems.isEmpty()) {
+ if (log.isWarnEnabled()) {
+ log.warn("Invalid " + type + " [" + key + "] : Could not find any element '" + targetName + "' of type '" + target + "' on classifier '" + fqn + "'.");
+ }
+ return null;
+ }
+
+ Iterator<ObjectModelElement> itr = elems.iterator();
+ while (itr.hasNext()) {
+ ObjectModelElement element = itr.next();
+ if (element == null) {
+ if (log.isWarnEnabled()) {
+ log.warn("Invalid " + type + " [" + key + "] : Element '" + targetName + "' of type '" + target + "' on classifier '" + fqn + "' is null.");
+ }
+ itr.remove();
+ }
+ }
+
+ return elems;
+ }
+}
Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/AbstractObjectModelReader.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/XmlObjectModelReader.java (from rev 1239, trunk/eugene/src/main/java/org/nuiton/eugene/models/object/ObjectModelReader.java)
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/XmlObjectModelReader.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/XmlObjectModelReader.java 2013-05-04 11:25:19 UTC (rev 1242)
@@ -0,0 +1,65 @@
+/*
+ * #%L
+ * EUGene :: EUGene
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2012 CodeLutin, Chatellier Eric
+ * %%
+ * 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>.
+ * #L%
+ */
+
+package org.nuiton.eugene.models.object.reader;
+
+import org.apache.commons.digester3.Digester;
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.xml.DigesterObjectModelRuleSet;
+import org.nuiton.eugene.models.object.xml.ObjectModelImpl;
+import org.xml.sax.SAXException;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * To read object xml model files into an memory object model.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role="org.nuiton.eugene.ModelReader" role-hint="xmlobjectmodel"
+ * @since 2.6.3
+ */
+public class XmlObjectModelReader extends AbstractObjectModelReader {
+
+ protected Digester digester;
+
+ @Override
+ protected void beforeReadFile(File... files) {
+ super.beforeReadFile(files);
+ digester = new Digester();
+ digester.addRuleSet(new DigesterObjectModelRuleSet());
+ }
+
+ @Override
+ protected void readFileToModel(File file, ObjectModel model) throws IOException {
+ try {
+ digester.push(new ObjectModelImpl());
+ digester.parse(file);
+ } catch (SAXException e) {
+ throw new IOException("Unable to parse ObjectModel input file : " + file, e);
+ }
+ }
+
+}
Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java 2013-05-04 11:25:19 UTC (rev 1242)
@@ -0,0 +1,58 @@
+package org.nuiton.eugene.models.object.reader;
+
+/*
+ * #%L
+ * EUGene :: EUGene
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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>.
+ * #L%
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.models.object.ObjectModel;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * To read object model from yaml files into an memory object model.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role="org.nuiton.eugene.ModelReader" role-hint="yamlobjectmodel"
+ * @since 2.6.3
+ */
+public class YamlObjectModelReader extends AbstractObjectModelReader {
+
+ private static final Log log =
+ LogFactory.getLog(YamlObjectModelReader.class);
+
+ @Override
+ protected void beforeReadFile(File... files) {
+ super.beforeReadFile(files);
+ //TODO ?
+ }
+
+ @Override
+ protected void readFileToModel(File file,
+ ObjectModel model) throws IOException {
+ //TODO
+ }
+
+}
Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/package-info.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/package-info.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/package-info.java 2013-05-04 11:25:19 UTC (rev 1242)
@@ -0,0 +1,32 @@
+/*
+ * #%L
+ * EUGene :: EUGene
+ * *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * 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>.
+ * #L%
+ */
+
+/**
+ * Eugene object model reader package.
+ *
+ * @since 2.6.3
+ */
+package org.nuiton.eugene.models.object.reader;
+
Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/package-info.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/eugene/src/main/java/org/nuiton/eugene/writer/ChainedFileWriterToMemoryModel.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/writer/ChainedFileWriterToMemoryModel.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/writer/ChainedFileWriterToMemoryModel.java 2013-05-04 11:25:19 UTC (rev 1242)
@@ -0,0 +1,62 @@
+package org.nuiton.eugene.writer;
+
+/*
+ * #%L
+ * EUGene :: EUGene
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2013 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>.
+ * #L%
+ */
+
+import org.nuiton.eugene.models.Model;
+
+import java.io.File;
+
+/**
+ * Contract to define a specialized {@link ChainedFileWriter} which generate
+ * no files but a memory model.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.3
+ */
+public interface ChainedFileWriterToMemoryModel extends ChainedFileWriter {
+
+ /**
+ * Reads inputs files and load them in a unique memory model.
+ *
+ * @return the memory model loaded from input files.
+ */
+ Model getModel();
+
+ /**
+ * Gets the latest last modified time of physicial files used to load
+ * the memory model.
+ *
+ * @return the latest last modified of any files used to load memory model.
+ */
+ long getLastModifiedSource();
+
+ /**
+ * Gets the directory where to generate later files froma pplying template
+ * to this memory model.
+ *
+ * @return where to generate files from this model.
+ */
+ File getOutputDirectory();
+}
Property changes on: trunk/eugene/src/main/java/org/nuiton/eugene/writer/ChainedFileWriterToMemoryModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/GenerateMojo.java
===================================================================
--- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/GenerateMojo.java 2013-05-02 14:39:36 UTC (rev 1241)
+++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/GenerateMojo.java 2013-05-04 11:25:19 UTC (rev 1242)
@@ -43,10 +43,13 @@
import org.nuiton.eugene.plugin.writer.BaseChainedFileWriter;
import org.nuiton.eugene.plugin.writer.ModelChainedFileWriter;
import org.nuiton.eugene.plugin.writer.XmiChainedFileWriter;
+import org.nuiton.eugene.plugin.writer.XmlModelChainedFileWriter;
+import org.nuiton.eugene.plugin.writer.YamlModelChainedFileWriter;
import org.nuiton.eugene.writer.ChainedFileWriter;
import org.nuiton.eugene.writer.ChainedFileWriterConfiguration;
import org.nuiton.eugene.writer.ChainedFileWriterData;
import org.nuiton.eugene.writer.ChainedFileWriterEntry;
+import org.nuiton.eugene.writer.ChainedFileWriterToMemoryModel;
import org.nuiton.eugene.writer.ChainedWriterEngine;
import org.nuiton.eugene.writer.WriterReport;
import org.nuiton.plugin.AbstractPlugin;
@@ -54,6 +57,7 @@
import org.nuiton.util.StringUtil;
import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
@@ -63,6 +67,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
/**
@@ -325,6 +330,24 @@
/** fixed classloader */
protected ClassLoader fixedClassLoader;
+ protected List<Template<Model>> templateList;
+
+ protected WriterReport newWriterReport() {
+ WriterReport writerReport = new WriterReport() {
+ @Override
+ public void addFile(String entry, File file, boolean b) {
+ super.addFile(entry, file, b);
+ if (b || isVerbose()) {
+ getLog().info("Will generate " + file);
+ }
+ if (getLog().isDebugEnabled()) {
+ getLog().debug(String.format("[%1$s] Will generate %2$s", entry, file));
+ }
+ }
+ };
+ return writerReport;
+ }
+
@Override
protected void init() throws Exception {
@@ -365,18 +388,7 @@
// add log support
((BaseChainedFileWriter) writer).setLog(getLog());
}
- writer.setWriterReport(new WriterReport() {
- @Override
- public void addFile(String entry, File file, boolean b) {
- super.addFile(entry, file, b);
- if (b || isVerbose()) {
- getLog().info("Will generate " + file);
- }
- if (getLog().isDebugEnabled()) {
- getLog().debug(String.format("[%1$s] Will generate %2$s", entry, file));
- }
- }
- });
+ writer.setWriterReport(newWriterReport());
}
// detect top level writers
@@ -429,6 +441,25 @@
properties.put(ModelChainedFileWriter.PROP_TEMPLATE_CONFIGURATION,
configuration);
}
+
+ if (engine.containsWriter("xmlmodel")) {
+
+ // add xml model writer support
+
+ properties.put(XmlModelChainedFileWriter.PROP_MODEL_PROPERTIES_PROVIDER,
+ getModelPropertiesProvider());
+ }
+
+ if (engine.containsWriter("yamlmodel")) {
+
+ // add yaml model writer support
+
+ properties.put(YamlModelChainedFileWriter.PROP_MODEL_PROPERTIES_PROVIDER,
+ getModelPropertiesProvider());
+ }
+
+ // init templates
+ templateList = initTemplates();
}
@Override
@@ -463,6 +494,8 @@
// launch writers in incoming order of dicovering of them
+ Set<ChainedFileWriterToMemoryModel> models = new HashSet<ChainedFileWriterToMemoryModel>();
+
for (ChainedFileWriter writer : engine.getSelectedWriters()) {
if (skipInputList.contains(writer.getInputProtocol())) {
getLog().info("Skip phase [" + writer.getInputProtocol() +
@@ -498,6 +531,12 @@
// launch generation
writer.generate(this, data);
+ if (writer instanceof ChainedFileWriterToMemoryModel) {
+ // keep result
+ ChainedFileWriterToMemoryModel writerToMemoryModel = (ChainedFileWriterToMemoryModel) writer;
+
+ models.add(writerToMemoryModel);
+ }
String message = reportGeneratedFiles(writer, t0);
getLog().info(message);
@@ -511,6 +550,19 @@
}
}
+ // merge all models in a unique one ? or apply templates on each model ?
+
+ WriterReport writerReport = newWriterReport();
+
+ for (ChainedFileWriterToMemoryModel entry : models) {
+ Model model = entry.getModel();
+ Long lastModified = entry.getLastModifiedSource();
+ File outputDirectory = entry.getOutputDirectory();
+
+ applyTemplates(model, lastModified, outputDirectory, templateList, writerReport);
+ }
+
+
} finally {
// always clear everything to avoid side-effects in goal is
// invoked more than once
@@ -519,7 +571,34 @@
}
}
+ protected void applyTemplates(Model model,
+ Long lastModifiedSource,
+ File outputDirectory,
+ List<Template<Model>> templateList,
+ WriterReport writerReport) throws IOException {
+ for (Template<Model> template : templateList) {
+ getLog().info("Apply generator " + template.getClass().getSimpleName());
+
+ // set the lastModified source property
+ template.setProperty(Template.PROP_LAST_MODIFIED_SOURCE, lastModifiedSource);
+
+ template.setProperty(Template.PROP_WRITER_REPORT, writerReport);
+
+ if (isVerbose()) {
+ getLog().info(" overwrite = " + template.isOverwrite());
+ getLog().info(" encoding = " + template.getEncoding());
+ getLog().info(" lastModifiedSource = " + template.getLastModifiedSource());
+ getLog().info(" exclude = " + template.getExcludeTemplates());
+ getLog().info(" output directory = " + outputDirectory);
+ }
+
+ // apply template
+ template.applyTemplate(model, outputDirectory);
+ }
+ }
+
+
public String reportGeneratedFiles(ChainedFileWriter writer, long t0) {
WriterReport writerReport = writer.getWriterReport();
int nbFiles = writerReport.getFilesCount();
@@ -859,4 +938,74 @@
}
return provider;
}
+
+ protected List<Template<Model>> initTemplates() {
+
+ ChainedFileWriterConfiguration configuration = this;
+
+ ClassLoader loader = configuration.getClassLoader();
+
+ boolean verbose = configuration.isVerbose();
+
+ Properties templateProperties = new Properties();
+
+ templateProperties.put(Template.PROP_DEFAULT_PACKAGE, defaultPackage);
+ templateProperties.put(Template.PROP_ENCODING, configuration.getEncoding());
+ templateProperties.put(Template.PROP_VERBOSE, verbose);
+ templateProperties.put(Template.PROP_OVERWRITE, configuration.isOverwrite());
+ templateProperties.put(Template.PROP_CLASS_LOADER, loader);
+ templateProperties.put(Template.PROP_EXCLUDE_TEMPLATES, excludeTemplates);
+
+
+ if (StringUtils.isEmpty(generatedPackages)) {
+ if (verbose) {
+ getLog().info("generating all packages");
+ }
+ } else {
+ templateProperties.put(Template.PROP_GENERATED_PACKAGES,
+ generatedPackages);
+ if (verbose) {
+ getLog().info("generating only for packages " + generatedPackages);
+ }
+ }
+
+ // init templates
+
+ List<Template<Model>> templatesList = new ArrayList<Template<Model>>();
+ if (StringUtils.isEmpty(templates)) {
+ throw new IllegalArgumentException("No template specified, use the templates parameter");
+ }
+ String[] templatesNames = templates.split(",");
+ for (String templateName : templatesNames) {
+ // remove trailing spaces
+ templateName = templateName.trim();
+ Template<Model> template =
+ (Template<Model>) configuration.getModelTemplates().get(templateName);
+
+ if (template == null) {
+ getLog().warn("template [" + templateName + "] is not " +
+ "registred via plexus, try to load it directly");
+ try {
+ template = (Template<Model>) Class.forName(
+ templateName, true, loader).newInstance();
+ } catch (Exception e) {
+ throw new IllegalStateException(
+ "Can't obtain template [" + templateName +
+ "] for reason " + e.getMessage(), e);
+ }
+ }
+
+ if (verbose) {
+ getLog().info("will use the template [" + templateName + "]");
+ }
+
+ // will use this template
+ templatesList.add(template);
+
+ // set the properties of the template
+ template.setConfiguration(
+ new DefaultTemplateConfiguration(templateProperties));
+ }
+ return templatesList;
+ }
}
Modified: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java
===================================================================
--- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java 2013-05-02 14:39:36 UTC (rev 1241)
+++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java 2013-05-04 11:25:19 UTC (rev 1242)
@@ -47,7 +47,6 @@
* To write model files from zargo files.
*
* @author tchemit
- * @plexus.component role="org.nuiton.eugene.writer.ChainedFileWriter" role-hint="model2Java"
* @since 2.0.0
*/
public class ModelChainedFileWriter extends BaseChainedFileWriter {
@@ -219,7 +218,18 @@
// set the verbose level of the model reader
getModelReader().setVerbose(verbose);
-
+
+ List<Template<?>> templatesList = initTemplates(configuration);
+
+ properties.put(PROP_TEMPLATES_LIST, templatesList);
+ }
+
+ protected List<Template<?>> initTemplates(ChainedFileWriterConfiguration configuration) {
+
+ ClassLoader loader = configuration.getClassLoader();
+
+ boolean verbose = configuration.isVerbose();
+
Properties templateProperties = new Properties();
templateProperties.put(Template.PROP_DEFAULT_PACKAGE, getDefaultPackage());
@@ -279,8 +289,7 @@
template.setConfiguration(
new DefaultTemplateConfiguration(templateProperties));
}
-
- properties.put(PROP_TEMPLATES_LIST, templatesList);
+ return templatesList;
}
@Override
Modified: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmiChainedFileWriter.java
===================================================================
--- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmiChainedFileWriter.java 2013-05-02 14:39:36 UTC (rev 1241)
+++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmiChainedFileWriter.java 2013-05-04 11:25:19 UTC (rev 1242)
@@ -94,7 +94,7 @@
@Override
public String getOutputProtocol(String modelType) {
// next writer : write from model files
- return "model";
+ return "xmlmodel";
}
@Override
Copied: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmlModelChainedFileWriter.java (from rev 1239, trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/ModelChainedFileWriter.java)
===================================================================
--- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmlModelChainedFileWriter.java (rev 0)
+++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/XmlModelChainedFileWriter.java 2013-05-04 11:25:19 UTC (rev 1242)
@@ -0,0 +1,224 @@
+/*
+ * #%L
+ * EUGene :: Maven plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2006 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * 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>.
+ * #L%
+ */
+
+package org.nuiton.eugene.plugin.writer;
+
+import org.nuiton.eugene.ModelPropertiesUtil;
+import org.nuiton.eugene.ModelReader;
+import org.nuiton.eugene.models.Model;
+import org.nuiton.eugene.writer.ChainedFileWriterConfiguration;
+import org.nuiton.eugene.writer.ChainedFileWriterToMemoryModel;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * To create a memory model from xml model files.
+ *
+ * @author tchemit
+ * @plexus.component role="org.nuiton.eugene.writer.ChainedFileWriter" role-hint="xmlModel2Memory"
+ * @since 2.6.3
+ */
+public class XmlModelChainedFileWriter extends BaseChainedFileWriter implements ChainedFileWriterToMemoryModel {
+
+ public static final String PROP_XML_MODEL_READER = "xmlModelReader";
+
+ public static final String PROP_MODEL_PROPERTIES_PROVIDER = "modelPropertiesProvider";
+
+ public static final String PROP_READER = "reader";
+
+ protected Model model;
+
+ protected long lastModifiedSource;
+
+ protected File outputDirectory;
+
+ public XmlModelChainedFileWriter() {
+ super(
+ PROP_READER, "reader",
+ PROP_XML_MODEL_READER, "modelReader",
+ PROP_MODEL_PROPERTIES_PROVIDER, "modelPropertiesProvider"
+ );
+ }
+
+ @Override
+ public Model getModel() {
+ return model;
+ }
+
+ public long getLastModifiedSource() {
+ return lastModifiedSource;
+ }
+
+ @Override
+ public File getOutputDirectory() {
+ return outputDirectory;
+ }
+
+ @Override
+ public String getInputProtocol() {
+ return "xmlmodel";
+ }
+
+ @Override
+ public String getOutputProtocol(String modelType) {
+ // nothing after java files
+ //TODO check in engine that a memory chained file has null output protocol
+ return null;
+ }
+
+ @Override
+ public boolean acceptModel(String modelType) {
+ // accept all models
+ return acceptObjectModelOrStateModel(modelType);
+ }
+
+ @Override
+ public boolean acceptInclude(String include) {
+ return include.startsWith("model:") ||
+ include.endsWith(".objectmodel") ||
+ include.endsWith(".statemodel");
+ }
+
+ @Override
+ public String getDefaultIncludes() {
+ return "**/*.*model";
+ }
+
+ @Override
+ public String getDefaultInputDirectory() {
+ return "src/main/models";
+ }
+
+ @Override
+ public String getDefaultOutputDirectory() {
+ return "java";
+ }
+
+ @Override
+ public String getDefaultTestInputDirectory() {
+ return "src/test/models";
+ }
+
+ @Override
+ public String getDefaultTestOutputDirectory() {
+ return "test-java";
+ }
+
+ protected ModelReader<?> getModelReader() {
+ return getProperty(PROP_XML_MODEL_READER, ModelReader.class);
+ }
+
+ protected String getReader() {
+ return getProperty(PROP_READER, String.class);
+ }
+
+ protected ModelPropertiesUtil.ModelPropertiesProvider getModelPropertiesProvider() {
+ return getProperty(PROP_MODEL_PROPERTIES_PROVIDER, ModelPropertiesUtil.ModelPropertiesProvider.class);
+ }
+
+ @Override
+ protected void initWriter(ChainedFileWriterConfiguration configuration) {
+ super.initWriter(configuration);
+
+ // obtain a reader
+ ClassLoader classLoader = configuration.getClassLoader();
+ ClassLoader loader = classLoader;
+ if (getModelReader() == null) {
+
+ if (getReader() != null) {
+ // use a specific reader
+ String reader = getReader();
+ try {
+ ClassLoader fixedClassLoader = loader;
+ ModelReader<?> modelReader = (ModelReader<?>)
+ Class.forName(reader, true,
+ fixedClassLoader).newInstance();
+ //TODO : should check that the reader is compatible with
+ //TODO : given modelType
+ properties.put(PROP_XML_MODEL_READER, modelReader);
+ } catch (Exception eee) {
+ throw new IllegalStateException("could not obtain reader "
+ + reader, eee);
+ }
+ } else {
+ String modelType = configuration.getModelType();
+ ModelReader<?> modelReader =
+ configuration.getModelReaders().get(modelType);
+ if (modelReader == null) {
+ throw new IllegalStateException(
+ "could not find a model reader for modelType : " +
+ modelType + ", availables readers : " +
+ configuration.getModelReaders().values());
+ }
+ properties.put(PROP_XML_MODEL_READER, modelReader);
+ }
+ }
+
+ boolean verbose = configuration.isVerbose();
+
+ // gets the provider of safe tag values and stereotypes
+ ModelPropertiesUtil.ModelPropertiesProvider propertiesProvider =
+ getModelPropertiesProvider();
+
+ // affect it to the model reader
+ getModelReader().setModelPropertiesProvider(propertiesProvider);
+
+ // set the verbose level of the model reader
+ getModelReader().setVerbose(verbose);
+ }
+
+ @Override
+ public void generate(ChainedFileWriterConfiguration configuration,
+ File outputDir,
+ Map<File, List<File>> filesByRoot,
+ Map<File, List<File>> resourcesByFile) throws IOException {
+
+ Set<File> modelFiles = new HashSet<File>();
+ for (List<File> files : filesByRoot.values()) {
+ modelFiles.addAll(files);
+ }
+ File[] filesToRead = modelFiles.toArray(new File[modelFiles.size()]);
+
+ if (configuration.isVerbose()) {
+ getLog().info("Will read " + filesToRead.length + " model(s).");
+ }
+
+ // read memory model from all files models
+
+ model = getModelReader().read(filesToRead);
+
+ // get the last modified source timestamp from reader
+ lastModifiedSource = getModelReader().getLastModifiedSource();
+
+ outputDirectory = outputDir;
+
+ }
+
+}
Added: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/YamlModelChainedFileWriter.java
===================================================================
--- trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/YamlModelChainedFileWriter.java (rev 0)
+++ trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/YamlModelChainedFileWriter.java 2013-05-04 11:25:19 UTC (rev 1242)
@@ -0,0 +1,223 @@
+package org.nuiton.eugene.plugin.writer;
+
+/*
+ * #%L
+ * EUGene :: Maven plugin
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2006 - 2013 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>.
+ * #L%
+ */
+
+import org.nuiton.eugene.ModelPropertiesUtil;
+import org.nuiton.eugene.ModelReader;
+import org.nuiton.eugene.models.Model;
+import org.nuiton.eugene.writer.ChainedFileWriterConfiguration;
+import org.nuiton.eugene.writer.ChainedFileWriterToMemoryModel;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * To create a memory model from yaml model files.
+ *
+ * @author tchemit
+ * @plexus.component role="org.nuiton.eugene.writer.ChainedFileWriter" role-hint="yamlModel2Memory"
+ * @since 2.6.3
+ */
+public class YamlModelChainedFileWriter extends BaseChainedFileWriter implements ChainedFileWriterToMemoryModel {
+
+ public static final String PROP_YAML_MODEL_READER = "yamlModelReader";
+
+ public static final String PROP_MODEL_PROPERTIES_PROVIDER = "modelPropertiesProvider";
+
+ public static final String PROP_READER = "reader";
+
+ protected Model model;
+
+ protected long lastModifiedSource;
+
+ protected File outputDirectory;
+
+ public YamlModelChainedFileWriter() {
+ super(
+ PROP_READER, "reader",
+ PROP_YAML_MODEL_READER, "yamlModelReader",
+ PROP_MODEL_PROPERTIES_PROVIDER, "modelPropertiesProvider"
+ );
+ }
+
+ @Override
+ public Model getModel() {
+ return model;
+ }
+
+ @Override
+ public long getLastModifiedSource() {
+ return lastModifiedSource;
+ }
+
+ @Override
+ public File getOutputDirectory() {
+ return outputDirectory;
+ }
+
+ @Override
+ public String getInputProtocol() {
+ return "yamlmodel";
+ }
+
+ @Override
+ public String getOutputProtocol(String modelType) {
+ // nothing after java files
+ //TODO check in engine that a memory chained file has null output protocol
+ return null;
+ }
+
+ @Override
+ public boolean acceptModel(String modelType) {
+ // accept all models
+ return acceptObjectModelOrStateModel(modelType);
+ }
+
+ @Override
+ public boolean acceptInclude(String include) {
+ return include.startsWith("yaml:") ||
+ include.endsWith(".yamlobjectmodel") ||
+ include.endsWith(".yamlstatemodel");
+ }
+
+ @Override
+ public String getDefaultIncludes() {
+ return "**/*.yaml*model";
+ }
+
+ @Override
+ public String getDefaultInputDirectory() {
+ return "src/main/models";
+ }
+
+ @Override
+ public String getDefaultOutputDirectory() {
+ return "java";
+ }
+
+ @Override
+ public String getDefaultTestInputDirectory() {
+ return "src/test/models";
+ }
+
+ @Override
+ public String getDefaultTestOutputDirectory() {
+ return "test-java";
+ }
+
+ protected ModelReader<?> getModelReader() {
+ return getProperty(PROP_YAML_MODEL_READER, ModelReader.class);
+ }
+
+ protected String getReader() {
+ return getProperty(PROP_READER, String.class);
+ }
+
+ protected ModelPropertiesUtil.ModelPropertiesProvider getModelPropertiesProvider() {
+ return getProperty(PROP_MODEL_PROPERTIES_PROVIDER, ModelPropertiesUtil.ModelPropertiesProvider.class);
+ }
+
+ @Override
+ protected void initWriter(ChainedFileWriterConfiguration configuration) {
+ super.initWriter(configuration);
+
+ // obtain a reader
+ ClassLoader classLoader = configuration.getClassLoader();
+ ClassLoader loader = classLoader;
+ if (getModelReader() == null) {
+
+ if (getReader() != null) {
+ // use a specific reader
+ String reader = getReader();
+ try {
+ ClassLoader fixedClassLoader = loader;
+ ModelReader<?> modelReader = (ModelReader<?>)
+ Class.forName(reader, true,
+ fixedClassLoader).newInstance();
+ //TODO : should check that the reader is compatible with
+ //TODO : given modelType
+ properties.put(PROP_YAML_MODEL_READER, modelReader);
+ } catch (Exception eee) {
+ throw new IllegalStateException("could not obtain reader "
+ + reader, eee);
+ }
+ } else {
+ String modelType = configuration.getModelType();
+ ModelReader<?> modelReader =
+ configuration.getModelReaders().get(modelType);
+ if (modelReader == null) {
+ throw new IllegalStateException(
+ "could not find a model reader for modelType : " +
+ modelType + ", availables readers : " +
+ configuration.getModelReaders().values());
+ }
+ properties.put(PROP_YAML_MODEL_READER, modelReader);
+ }
+ }
+
+ boolean verbose = configuration.isVerbose();
+
+ // gets the provider of safe tag values and stereotypes
+ ModelPropertiesUtil.ModelPropertiesProvider propertiesProvider =
+ getModelPropertiesProvider();
+
+ // affect it to the model reader
+ getModelReader().setModelPropertiesProvider(propertiesProvider);
+
+ // set the verbose level of the model reader
+ getModelReader().setVerbose(verbose);
+ }
+
+ @Override
+ public void generate(ChainedFileWriterConfiguration configuration,
+ File outputDir,
+ Map<File, List<File>> filesByRoot,
+ Map<File, List<File>> resourcesByFile) throws IOException {
+
+ Set<File> modelFiles = new HashSet<File>();
+ for (List<File> files : filesByRoot.values()) {
+ modelFiles.addAll(files);
+ }
+ File[] filesToRead = modelFiles.toArray(new File[modelFiles.size()]);
+
+ if (configuration.isVerbose()) {
+ getLog().info("Will read " + filesToRead.length + " model(s).");
+ }
+
+ // read memory model from all files models
+
+ model = getModelReader().read(filesToRead);
+
+ // get the last modified source timestamp from reader
+ lastModifiedSource = getModelReader().getLastModifiedSource();
+
+ outputDirectory = outputDir;
+ }
+
+}
Property changes on: trunk/eugene-maven-plugin/src/main/java/org/nuiton/eugene/plugin/writer/YamlModelChainedFileWriter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r1241 - trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml
by agiraudet@users.nuiton.org 02 May '13
by agiraudet@users.nuiton.org 02 May '13
02 May '13
Author: agiraudet
Date: 2013-05-02 16:39:36 +0200 (Thu, 02 May 2013)
New Revision: 1241
Url: http://nuiton.org/projects/eugene/repository/revisions/1241
Log:
modification du namespace
Modified:
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/DigesterObjectModelRuleSet.java
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/DigesterObjectModelRuleSet.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/DigesterObjectModelRuleSet.java 2013-04-28 21:12:33 UTC (rev 1240)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/DigesterObjectModelRuleSet.java 2013-05-02 14:39:36 UTC (rev 1241)
@@ -61,7 +61,7 @@
}
public DigesterObjectModelRuleSet(String prefix) {
- super("http://www.codelutin.org/lutingenerator/objectModel");
+ super("http://nuiton.org/eugene/objectModel/v1");
this.prefix = prefix;
}
1
0
Author: tchemit
Date: 2013-04-28 23:12:33 +0200 (Sun, 28 Apr 2013)
New Revision: 1240
Url: http://nuiton.org/projects/eugene/repository/revisions/1240
Log:
updates mavenpom to 3.4.10
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-04-08 12:49:16 UTC (rev 1239)
+++ trunk/pom.xml 2013-04-28 21:12:33 UTC (rev 1240)
@@ -32,7 +32,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>3.4.8</version>
+ <version>3.4.10</version>
</parent>
<artifactId>eugene</artifactId>
1
0
r1239 - in trunk: . eugene eugene-java-templates eugene-maven-plugin
by maven-release@users.nuiton.org 08 Apr '13
by maven-release@users.nuiton.org 08 Apr '13
08 Apr '13
Author: maven-release
Date: 2013-04-08 14:49:16 +0200 (Mon, 08 Apr 2013)
New Revision: 1239
Url: http://nuiton.org/projects/eugene/repository/revisions/1239
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/eugene-java-templates/pom.xml
trunk/eugene-maven-plugin/pom.xml
trunk/eugene/pom.xml
trunk/pom.xml
Modified: trunk/eugene/pom.xml
===================================================================
--- trunk/eugene/pom.xml 2013-04-08 12:49:14 UTC (rev 1238)
+++ trunk/eugene/pom.xml 2013-04-08 12:49:16 UTC (rev 1239)
@@ -32,7 +32,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.6.2</version>
+ <version>2.6.3-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/eugene-java-templates/pom.xml
===================================================================
--- trunk/eugene-java-templates/pom.xml 2013-04-08 12:49:14 UTC (rev 1238)
+++ trunk/eugene-java-templates/pom.xml 2013-04-08 12:49:16 UTC (rev 1239)
@@ -29,7 +29,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.6.2</version>
+ <version>2.6.3-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/eugene-maven-plugin/pom.xml
===================================================================
--- trunk/eugene-maven-plugin/pom.xml 2013-04-08 12:49:14 UTC (rev 1238)
+++ trunk/eugene-maven-plugin/pom.xml 2013-04-08 12:49:16 UTC (rev 1239)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.6.2</version>
+ <version>2.6.3-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-04-08 12:49:14 UTC (rev 1238)
+++ trunk/pom.xml 2013-04-08 12:49:16 UTC (rev 1239)
@@ -36,7 +36,7 @@
</parent>
<artifactId>eugene</artifactId>
- <version>2.6.2</version>
+ <version>2.6.3-SNAPSHOT</version>
<modules>
<module>eugene</module>
@@ -385,11 +385,11 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/eugene/tags/eugene-2.6.2</connection>
+ <connection>scm:svn:http://svn.nuiton.org/svn/eugene/trunk</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/eugene/tags/eugene-2.6.2
+ scm:svn:http://svn.nuiton.org/svn/eugene/trunk
</developerConnection>
- <url>http://nuiton.org/projects/eugene/repository/show/tags/eugene-2.6.2</url>
+ <url>http://nuiton.org/projects/eugene/repository/show/trunk</url>
</scm>
<distributionManagement>
1
0
Author: maven-release
Date: 2013-04-08 14:49:14 +0200 (Mon, 08 Apr 2013)
New Revision: 1238
Url: http://nuiton.org/projects/eugene/repository/revisions/1238
Log:
[maven-release-plugin] copy for tag eugene-2.6.2
Added:
tags/eugene-2.6.2/
Property changes on: tags/eugene-2.6.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
/branches/eugene-2.4.3:1151-1173
1
0
r1237 - in trunk: . eugene eugene-java-templates eugene-maven-plugin
by maven-release@users.nuiton.org 08 Apr '13
by maven-release@users.nuiton.org 08 Apr '13
08 Apr '13
Author: maven-release
Date: 2013-04-08 14:49:12 +0200 (Mon, 08 Apr 2013)
New Revision: 1237
Url: http://nuiton.org/projects/eugene/repository/revisions/1237
Log:
[maven-release-plugin] prepare release eugene-2.6.2
Modified:
trunk/eugene-java-templates/pom.xml
trunk/eugene-maven-plugin/pom.xml
trunk/eugene/pom.xml
trunk/pom.xml
Modified: trunk/eugene/pom.xml
===================================================================
--- trunk/eugene/pom.xml 2013-04-01 20:50:47 UTC (rev 1236)
+++ trunk/eugene/pom.xml 2013-04-08 12:49:12 UTC (rev 1237)
@@ -32,7 +32,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.6.2-SNAPSHOT</version>
+ <version>2.6.2</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/eugene-java-templates/pom.xml
===================================================================
--- trunk/eugene-java-templates/pom.xml 2013-04-01 20:50:47 UTC (rev 1236)
+++ trunk/eugene-java-templates/pom.xml 2013-04-08 12:49:12 UTC (rev 1237)
@@ -29,7 +29,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.6.2-SNAPSHOT</version>
+ <version>2.6.2</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/eugene-maven-plugin/pom.xml
===================================================================
--- trunk/eugene-maven-plugin/pom.xml 2013-04-01 20:50:47 UTC (rev 1236)
+++ trunk/eugene-maven-plugin/pom.xml 2013-04-08 12:49:12 UTC (rev 1237)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.6.2-SNAPSHOT</version>
+ <version>2.6.2</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-04-01 20:50:47 UTC (rev 1236)
+++ trunk/pom.xml 2013-04-08 12:49:12 UTC (rev 1237)
@@ -36,7 +36,7 @@
</parent>
<artifactId>eugene</artifactId>
- <version>2.6.2-SNAPSHOT</version>
+ <version>2.6.2</version>
<modules>
<module>eugene</module>
@@ -385,11 +385,11 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/eugene/trunk</connection>
+ <connection>scm:svn:http://svn.nuiton.org/svn/eugene/tags/eugene-2.6.2</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/eugene/trunk
+ scm:svn:http://svn.nuiton.org/svn/eugene/tags/eugene-2.6.2
</developerConnection>
- <url>http://nuiton.org/projects/eugene/repository/show/trunk</url>
+ <url>http://nuiton.org/projects/eugene/repository/show/tags/eugene-2.6.2</url>
</scm>
<distributionManagement>
1
0
r1236 - in trunk/eugene-jpa-templates/src: main/java/org/nuiton/eugene/jpa main/resources/META-INF/services site/fr/rst site/rst test/java/org/nuiton/eugene/jpa
by tchemit@users.nuiton.org 01 Apr '13
by tchemit@users.nuiton.org 01 Apr '13
01 Apr '13
Author: tchemit
Date: 2013-04-01 22:50:47 +0200 (Mon, 01 Apr 2013)
New Revision: 1236
Url: http://nuiton.org/projects/eugene/repository/revisions/1236
Log:
refs #2633: Add JPA templates (entity, dao) (renmae JPA to Jpa)
Added:
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJpaTransformer.java
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaDaoTransformer.java
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaEntityTransformer.java
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesGeneratorUtil.java
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesModelPropertiesProvider.java
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesStereoTypes.java
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesTagValues.java
trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JpaTemplatesModelPropertiesProviderTest.java
Removed:
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJPATransformer.java
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPADaoTransformer.java
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPAEntityTransformer.java
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesGeneratorUtil.java
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProvider.java
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesStereoTypes.java
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesTagValues.java
trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProviderTest.java
Modified:
trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/package-info.java
trunk/eugene-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider
trunk/eugene-jpa-templates/src/site/fr/rst/index.rst
trunk/eugene-jpa-templates/src/site/rst/index.rst
Deleted: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJPATransformer.java
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJPATransformer.java 2013-03-29 23:36:59 UTC (rev 1235)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJPATransformer.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -1,684 +0,0 @@
-package org.nuiton.eugene.jpa;
-
-/*
- * #%L
- * EUGene :: JPA templates
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2013 CodeLutin, Tony Chemit
- * %%
- * 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>.
- * #L%
- */
-
-/*{generator option: parentheses = false}*/
-/*{generator option: writeString = +}*/
-
-import org.nuiton.eugene.java.ObjectModelTransformerToJava;
-import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelInterface;
-import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Common class form jpa like transformer.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @see JPAEntityTransformer
- * @since 2.7
- */
-public abstract class AbstractJPATransformer extends ObjectModelTransformerToJava {
-
- public static final String DEFAULT_CONSTANT_PREFIX = "PROPERTY_";
-
- protected void createPropertyConstant(ObjectModelClass output,
- ObjectModelAttribute attr,
- String prefix,
- Set<String> constantNames) {
-
- String attrName = getAttributeName(attr);
-
- String constantName = prefix + builder.getConstantName(attrName);
-
- if (!constantNames.contains(constantName)) {
-
- addConstant(output,
- constantName,
- String.class,
- "\"" + attrName + "\"",
- ObjectModelJavaModifier.PUBLIC
- );
- }
- }
-
- protected String getAttributeName(ObjectModelAttribute attr) {
- String attrName = attr.getName();
- if (attr.hasAssociationClass()) {
- String assocAttrName = JPATemplatesGeneratorUtil.getAssocAttrName(attr);
- attrName = JPATemplatesGeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
- }
- return attrName;
- }
-
- protected String getAttributeType(ObjectModelAttribute attr) {
- String attrType = attr.getType();
- if (attr.hasAssociationClass()) {
- attrType = attr.getAssociationClass().getName();
- }
- return attrType;
- }
-
- protected boolean containsMutiple(List<ObjectModelAttribute> attributes) {
-
- boolean result = false;
-
- for (ObjectModelAttribute attr : attributes) {
-
- if (JPATemplatesGeneratorUtil.isNMultiplicity(attr)) {
- result = true;
-
- break;
- }
-
- }
- return result;
- }
-
- protected void createProperty(ObjectModelClass output,
- ObjectModelAttribute attr,
- boolean usePCS,
- boolean generateBooleanGetMethods) {
-
- String attrName = getAttributeName(attr);
- String attrType = getAttributeType(attr);
-
- boolean multiple = JPATemplatesGeneratorUtil.isNMultiplicity(attr);
-
- String constantName = getConstantName(attrName);
- String simpleType = JPATemplatesGeneratorUtil.getSimpleName(attrType);
-
- if (multiple) {
-
- createGetChildMethod(output,
- attrName,
- attrType,
- simpleType
- );
-
- createIsEmptyMethod(output,
- attrName
- );
-
- createSizeMethod(output,
- attrName
- );
-
- createAddChildMethod(output,
- attrName,
- attrType,
- constantName,
- usePCS
- );
-
- createAddAllChildrenMethod(output,
- attrName,
- attrType,
- constantName,
- usePCS
- );
-
- createRemoveChildMethod(output,
- attrName,
- attrType,
- constantName,
- usePCS
- );
-
- createRemoveAllChildrenMethod(output,
- attrName,
- attrType,
- constantName,
- usePCS
- );
-
- createContainsChildMethod(output,
- attrName,
- attrType,
- constantName,
- usePCS
- );
-
- createContainsAllChildrenMethod(output,
- attrName,
- attrType,
- constantName,
- usePCS
- );
-
- // Change type for Multiple attribute
- if (attr.isOrdered()) {
- attrType = List.class.getName() + "<" + attrType + ">";
- } else {
- attrType = Collection.class.getName() + "<" + attrType + ">";
- }
-
- simpleType = JPATemplatesGeneratorUtil.getSimpleName(attrType);
- }
-
- boolean booleanProperty = JPATemplatesGeneratorUtil.isBooleanPrimitive(attr);
-
- if (booleanProperty && !multiple) {
-
- // creates a isXXX method
- createGetMethod(output,
- attrName,
- attrType,
- JPATemplatesGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX
- );
- }
-
- if (multiple || !booleanProperty || generateBooleanGetMethods) {
-
- createGetMethod(output,
- attrName,
- attrType,
- JPATemplatesGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX
- );
-
- }
- createSetMethod(output,
- attrName,
- attrType,
- simpleType,
- constantName,
- usePCS
- );
-
- // Add attribute to the class
- addAttribute(output,
- attrName,
- attrType,
- "",
- ObjectModelJavaModifier.PROTECTED
- );
-
- }
-
- protected List<ObjectModelAttribute> getProperties(ObjectModelClass input) {
- List<ObjectModelAttribute> attributes =
- (List<ObjectModelAttribute>) input.getAttributes();
-
- List<ObjectModelAttribute> attrs =
- new ArrayList<ObjectModelAttribute>();
- for (ObjectModelAttribute attr : attributes) {
- if (attr.isNavigable()) {
-
- // only keep navigable attributes
- attrs.add(attr);
- }
- }
- return attrs;
- }
-
- protected void createGetMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String methodPrefix) {
-
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName(methodPrefix , attrName),
- attrType,
- ObjectModelJavaModifier.PUBLIC
- );
- setOperationBody(operation, ""
- /*{
- return <%=attrName%>;
- }*/
- );
- }
-
- protected void createGetChildMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String simpleType) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("get", attrName),
- attrType,
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, "int", "index");
- setOperationBody(operation, ""
- /*{
- <%=simpleType%> o = getChild(<%=attrName%>, index);
- return o;
- }*/
- );
- }
-
- protected void createIsEmptyMethod(ObjectModelClass output,
- String attrName) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("is", attrName)+"Empty",
- boolean.class,
- ObjectModelJavaModifier.PUBLIC
- );
- setOperationBody(operation, ""
- /*{
- return <%=attrName%> == null || <%=attrName%>.isEmpty();
- }*/
- );
- }
-
- protected void createSizeMethod(ObjectModelClass output,
- String attrName) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("size", attrName),
- int.class,
- ObjectModelJavaModifier.PUBLIC
- );
- setOperationBody(operation, ""
- /*{
- return <%=attrName%> == null ? 0 : <%=attrName%>.size();
- }*/
- );
- }
- protected void createAddChildMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("add", attrName),
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, attrType, attrName);
-
- String methodName = getJavaBeanMethodName("get", attrName);
- StringBuilder buffer = new StringBuilder(""
- /*{
- <%=methodName%>().add(<%=attrName%>);
- }*/
- );
- if (usePCS) {
- buffer.append(""
- /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
- }*/
- );
- }
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createAddAllChildrenMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("addAll", attrName),
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
-
- String methodName = getJavaBeanMethodName("get", attrName);
- StringBuilder buffer = new StringBuilder(""
- /*{
- <%=methodName%>().addAll(<%=attrName%>);
- }*/
- );
- if (usePCS) {
- buffer.append(""
- /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
- }*/
- );
- }
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createRemoveChildMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("remove", attrName),
- "boolean",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, attrType, attrName);
- String methodName = getJavaBeanMethodName("get", attrName);
- StringBuilder buffer = new StringBuilder();
- buffer.append(""
- /*{
- boolean removed = <%=methodName%>().remove(<%=attrName%>);}*/
- );
-
- if (usePCS) {
- buffer.append(""
- /*{
- if (removed) {
- firePropertyChange(<%=constantName%>, <%=attrName%>, null);
- }}*/
- );
- }
- buffer.append(""
- /*{
- return removed;
- }*/
- );
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createRemoveAllChildrenMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
-
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("removeAll", attrName),
- "boolean",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
- StringBuilder buffer = new StringBuilder();
- String methodName = getJavaBeanMethodName("get", attrName);
- buffer.append(""
- /*{
- boolean removed = <%=methodName%>().removeAll(<%=attrName%>);}*/
- );
-
- if (usePCS) {
- buffer.append(""
- /*{
- if (removed) {
- firePropertyChange(<%=constantName%>, <%=attrName%>, null);
- }}*/
- );
- }
- buffer.append(""
- /*{
- return removed;
- }*/
- );
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createContainsChildMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
-
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("contains", attrName),
- "boolean",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, attrType, attrName);
- StringBuilder buffer = new StringBuilder();
- String methodName = getJavaBeanMethodName("get", attrName);
- buffer.append(""
- /*{
- boolean contains = <%=methodName%>().contains(<%=attrName%>);
- return contains;
- }*/
- );
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createContainsAllChildrenMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String constantName,
- boolean usePCS) {
-
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("containsAll", attrName),
- "boolean",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
- StringBuilder buffer = new StringBuilder();
- String methodName = getJavaBeanMethodName("get", attrName);
- buffer.append(""
- /*{
- boolean contains = <%=methodName%>().containsAll(<%=attrName%>);
- return contains;
- }*/
- );
- setOperationBody(operation, buffer.toString());
- }
-
- protected void createSetMethod(ObjectModelClass output,
- String attrName,
- String attrType,
- String simpleType,
- String constantName,
- boolean usePCS) {
- ObjectModelOperation operation = addOperation(
- output,
- getJavaBeanMethodName("set", attrName),
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, attrType, attrName);
-
- if (usePCS) {
- String methodName = getJavaBeanMethodName("get", attrName);
- setOperationBody(operation, ""
- /*{
- <%=simpleType%> oldValue = <%=methodName%>();
- this.<%=attrName%> = <%=attrName%>;
- firePropertyChange(<%=constantName%>, oldValue, <%=attrName%>);
- }*/
- );
- } else {
- setOperationBody(operation, ""
- /*{
- this.<%=attrName%> = <%=attrName%>;
- }*/
- );
- }
- }
-
- protected void addSerializable(ObjectModelClass input,
- ObjectModelClass output,
- boolean interfaceFound) {
- if (!interfaceFound) {
- addInterface(output, Serializable.class);
- }
-
- // Generate the serialVersionUID
- long serialVersionUID = JPATemplatesGeneratorUtil.generateSerialVersionUID(input);
-
- addConstant(output,
- JPATemplatesGeneratorUtil.SERIAL_VERSION_UID,
- "long",
- serialVersionUID + "L",
- ObjectModelJavaModifier.PRIVATE
- );
- }
-
- /**
- * Add all interfaces defines in input class and returns if
- * {@link Serializable} interface was found.
- *
- * @param input the input model class to process
- * @param output the output generated class
- * @return {@code true} if {@link Serializable} was found from input,
- * {@code false} otherwise
- */
- protected boolean addInterfaces(ObjectModelClass input,
- ObjectModelClass output) {
- boolean foundSerializable = false;
- for (ObjectModelInterface parentInterface : input.getInterfaces()) {
- String fqn = parentInterface.getQualifiedName();
- addInterface(output, fqn);
- if (Serializable.class.getName().equals(fqn)) {
- foundSerializable = true;
- }
- }
- return foundSerializable;
- }
-
- protected void createPropertyChangeSupport(ObjectModelClass output) {
-
- addAttribute(output,
- "pcs",
- PropertyChangeSupport.class,
- "new PropertyChangeSupport(this)",
- ObjectModelJavaModifier.PROTECTED,
- ObjectModelJavaModifier.FINAL,
- ObjectModelJavaModifier.TRANSIENT
- );
-
- // Add PropertyListener
-
- ObjectModelOperation operation;
-
- operation = addOperation(output,
- "addPropertyChangeListener",
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, PropertyChangeListener.class, "listener");
- setOperationBody(operation, ""
- /*{
- pcs.addPropertyChangeListener(listener);
- }*/
- );
-
- operation = addOperation(output,
- "addPropertyChangeListener",
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, String.class, "propertyName");
- addParameter(operation, PropertyChangeListener.class, "listener");
- setOperationBody(operation, ""
- /*{
- pcs.addPropertyChangeListener(propertyName, listener);
- }*/
- );
-
- operation = addOperation(output,
- "removePropertyChangeListener",
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, PropertyChangeListener.class, "listener");
- setOperationBody(operation, ""
- /*{
- pcs.removePropertyChangeListener(listener);
- }*/
- );
-
- operation = addOperation(output,
- "removePropertyChangeListener",
- "void",
- ObjectModelJavaModifier.PUBLIC
- );
- addParameter(operation, String.class, "propertyName");
- addParameter(operation, PropertyChangeListener.class, "listener");
- setOperationBody(operation, ""
- /*{
- pcs.removePropertyChangeListener(propertyName, listener);
- }*/
- );
-
- operation = addOperation(output,
- "firePropertyChange",
- "void",
- ObjectModelJavaModifier.PROTECTED
- );
- addParameter(operation, String.class, "propertyName");
- addParameter(operation, Object.class, "oldValue");
- addParameter(operation, Object.class, "newValue");
- setOperationBody(operation, ""
- /*{
- pcs.firePropertyChange(propertyName, oldValue, newValue);
- }*/
- );
-
- operation = addOperation(output,
- "firePropertyChange",
- "void",
- ObjectModelJavaModifier.PROTECTED
- );
- addParameter(operation, String.class, "propertyName");
- addParameter(operation, Object.class, "newValue");
- setOperationBody(operation, ""
- /*{
- firePropertyChange(propertyName, null, newValue);
- }*/
- );
- }
-
- protected void createGetChildMethod(ObjectModelClass output) {
- ObjectModelOperation getChild = addOperation(
- output,
- "getChild", "<T> T",
- ObjectModelJavaModifier.PROTECTED
- );
- addImport(output, List.class);
-
- addParameter(getChild, "java.util.Collection<T>", "childs");
- addParameter(getChild, "int", "index");
- setOperationBody(getChild, ""
-/*{
- T result = null;
- if (childs != null) {
- if (childs instanceof List) {
- if (index < childs.size()) {
- result = ((List<T>) childs).get(index);
- }
- } else {
- int i = 0;
- for (T o : childs) {
- if (index == i) {
- result = o;
- break;
- }
- i++;
- }
- }
- }
- return result;
-}*/
- );
- }
-}
Copied: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJpaTransformer.java (from rev 1234, trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJPATransformer.java)
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJpaTransformer.java (rev 0)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJpaTransformer.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -0,0 +1,684 @@
+package org.nuiton.eugene.jpa;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * 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>.
+ * #L%
+ */
+
+/*{generator option: parentheses = false}*/
+/*{generator option: writeString = +}*/
+
+import org.nuiton.eugene.java.ObjectModelTransformerToJava;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelInterface;
+import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Common class form jpa like transformer.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @see JpaEntityTransformer
+ * @since 2.7
+ */
+public abstract class AbstractJpaTransformer extends ObjectModelTransformerToJava {
+
+ public static final String DEFAULT_CONSTANT_PREFIX = "PROPERTY_";
+
+ protected void createPropertyConstant(ObjectModelClass output,
+ ObjectModelAttribute attr,
+ String prefix,
+ Set<String> constantNames) {
+
+ String attrName = getAttributeName(attr);
+
+ String constantName = prefix + builder.getConstantName(attrName);
+
+ if (!constantNames.contains(constantName)) {
+
+ addConstant(output,
+ constantName,
+ String.class,
+ "\"" + attrName + "\"",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ }
+ }
+
+ protected String getAttributeName(ObjectModelAttribute attr) {
+ String attrName = attr.getName();
+ if (attr.hasAssociationClass()) {
+ String assocAttrName = JpaTemplatesGeneratorUtil.getAssocAttrName(attr);
+ attrName = JpaTemplatesGeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
+ }
+ return attrName;
+ }
+
+ protected String getAttributeType(ObjectModelAttribute attr) {
+ String attrType = attr.getType();
+ if (attr.hasAssociationClass()) {
+ attrType = attr.getAssociationClass().getName();
+ }
+ return attrType;
+ }
+
+ protected boolean containsMutiple(List<ObjectModelAttribute> attributes) {
+
+ boolean result = false;
+
+ for (ObjectModelAttribute attr : attributes) {
+
+ if (JpaTemplatesGeneratorUtil.isNMultiplicity(attr)) {
+ result = true;
+
+ break;
+ }
+
+ }
+ return result;
+ }
+
+ protected void createProperty(ObjectModelClass output,
+ ObjectModelAttribute attr,
+ boolean usePCS,
+ boolean generateBooleanGetMethods) {
+
+ String attrName = getAttributeName(attr);
+ String attrType = getAttributeType(attr);
+
+ boolean multiple = JpaTemplatesGeneratorUtil.isNMultiplicity(attr);
+
+ String constantName = getConstantName(attrName);
+ String simpleType = JpaTemplatesGeneratorUtil.getSimpleName(attrType);
+
+ if (multiple) {
+
+ createGetChildMethod(output,
+ attrName,
+ attrType,
+ simpleType
+ );
+
+ createIsEmptyMethod(output,
+ attrName
+ );
+
+ createSizeMethod(output,
+ attrName
+ );
+
+ createAddChildMethod(output,
+ attrName,
+ attrType,
+ constantName,
+ usePCS
+ );
+
+ createAddAllChildrenMethod(output,
+ attrName,
+ attrType,
+ constantName,
+ usePCS
+ );
+
+ createRemoveChildMethod(output,
+ attrName,
+ attrType,
+ constantName,
+ usePCS
+ );
+
+ createRemoveAllChildrenMethod(output,
+ attrName,
+ attrType,
+ constantName,
+ usePCS
+ );
+
+ createContainsChildMethod(output,
+ attrName,
+ attrType,
+ constantName,
+ usePCS
+ );
+
+ createContainsAllChildrenMethod(output,
+ attrName,
+ attrType,
+ constantName,
+ usePCS
+ );
+
+ // Change type for Multiple attribute
+ if (attr.isOrdered()) {
+ attrType = List.class.getName() + "<" + attrType + ">";
+ } else {
+ attrType = Collection.class.getName() + "<" + attrType + ">";
+ }
+
+ simpleType = JpaTemplatesGeneratorUtil.getSimpleName(attrType);
+ }
+
+ boolean booleanProperty = JpaTemplatesGeneratorUtil.isBooleanPrimitive(attr);
+
+ if (booleanProperty && !multiple) {
+
+ // creates a isXXX method
+ createGetMethod(output,
+ attrName,
+ attrType,
+ JpaTemplatesGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX
+ );
+ }
+
+ if (multiple || !booleanProperty || generateBooleanGetMethods) {
+
+ createGetMethod(output,
+ attrName,
+ attrType,
+ JpaTemplatesGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX
+ );
+
+ }
+ createSetMethod(output,
+ attrName,
+ attrType,
+ simpleType,
+ constantName,
+ usePCS
+ );
+
+ // Add attribute to the class
+ addAttribute(output,
+ attrName,
+ attrType,
+ "",
+ ObjectModelJavaModifier.PROTECTED
+ );
+
+ }
+
+ protected List<ObjectModelAttribute> getProperties(ObjectModelClass input) {
+ List<ObjectModelAttribute> attributes =
+ (List<ObjectModelAttribute>) input.getAttributes();
+
+ List<ObjectModelAttribute> attrs =
+ new ArrayList<ObjectModelAttribute>();
+ for (ObjectModelAttribute attr : attributes) {
+ if (attr.isNavigable()) {
+
+ // only keep navigable attributes
+ attrs.add(attr);
+ }
+ }
+ return attrs;
+ }
+
+ protected void createGetMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String methodPrefix) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName(methodPrefix , attrName),
+ attrType,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ setOperationBody(operation, ""
+ /*{
+ return <%=attrName%>;
+ }*/
+ );
+ }
+
+ protected void createGetChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String simpleType) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("get", attrName),
+ attrType,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, "int", "index");
+ setOperationBody(operation, ""
+ /*{
+ <%=simpleType%> o = getChild(<%=attrName%>, index);
+ return o;
+ }*/
+ );
+ }
+
+ protected void createIsEmptyMethod(ObjectModelClass output,
+ String attrName) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("is", attrName)+"Empty",
+ boolean.class,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ setOperationBody(operation, ""
+ /*{
+ return <%=attrName%> == null || <%=attrName%>.isEmpty();
+ }*/
+ );
+ }
+
+ protected void createSizeMethod(ObjectModelClass output,
+ String attrName) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("size", attrName),
+ int.class,
+ ObjectModelJavaModifier.PUBLIC
+ );
+ setOperationBody(operation, ""
+ /*{
+ return <%=attrName%> == null ? 0 : <%=attrName%>.size();
+ }*/
+ );
+ }
+ protected void createAddChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("add", attrName),
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+
+ String methodName = getJavaBeanMethodName("get", attrName);
+ StringBuilder buffer = new StringBuilder(""
+ /*{
+ <%=methodName%>().add(<%=attrName%>);
+ }*/
+ );
+ if (usePCS) {
+ buffer.append(""
+ /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
+ }*/
+ );
+ }
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createAddAllChildrenMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("addAll", attrName),
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
+
+ String methodName = getJavaBeanMethodName("get", attrName);
+ StringBuilder buffer = new StringBuilder(""
+ /*{
+ <%=methodName%>().addAll(<%=attrName%>);
+ }*/
+ );
+ if (usePCS) {
+ buffer.append(""
+ /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>);
+ }*/
+ );
+ }
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createRemoveChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("remove", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+ String methodName = getJavaBeanMethodName("get", attrName);
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(""
+ /*{
+ boolean removed = <%=methodName%>().remove(<%=attrName%>);}*/
+ );
+
+ if (usePCS) {
+ buffer.append(""
+ /*{
+ if (removed) {
+ firePropertyChange(<%=constantName%>, <%=attrName%>, null);
+ }}*/
+ );
+ }
+ buffer.append(""
+ /*{
+ return removed;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createRemoveAllChildrenMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("removeAll", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
+ StringBuilder buffer = new StringBuilder();
+ String methodName = getJavaBeanMethodName("get", attrName);
+ buffer.append(""
+ /*{
+ boolean removed = <%=methodName%>().removeAll(<%=attrName%>);}*/
+ );
+
+ if (usePCS) {
+ buffer.append(""
+ /*{
+ if (removed) {
+ firePropertyChange(<%=constantName%>, <%=attrName%>, null);
+ }}*/
+ );
+ }
+ buffer.append(""
+ /*{
+ return removed;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createContainsChildMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("contains", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+ StringBuilder buffer = new StringBuilder();
+ String methodName = getJavaBeanMethodName("get", attrName);
+ buffer.append(""
+ /*{
+ boolean contains = <%=methodName%>().contains(<%=attrName%>);
+ return contains;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createContainsAllChildrenMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String constantName,
+ boolean usePCS) {
+
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("containsAll", attrName),
+ "boolean",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, "java.util.Collection<" + attrType + ">", attrName);
+ StringBuilder buffer = new StringBuilder();
+ String methodName = getJavaBeanMethodName("get", attrName);
+ buffer.append(""
+ /*{
+ boolean contains = <%=methodName%>().containsAll(<%=attrName%>);
+ return contains;
+ }*/
+ );
+ setOperationBody(operation, buffer.toString());
+ }
+
+ protected void createSetMethod(ObjectModelClass output,
+ String attrName,
+ String attrType,
+ String simpleType,
+ String constantName,
+ boolean usePCS) {
+ ObjectModelOperation operation = addOperation(
+ output,
+ getJavaBeanMethodName("set", attrName),
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, attrType, attrName);
+
+ if (usePCS) {
+ String methodName = getJavaBeanMethodName("get", attrName);
+ setOperationBody(operation, ""
+ /*{
+ <%=simpleType%> oldValue = <%=methodName%>();
+ this.<%=attrName%> = <%=attrName%>;
+ firePropertyChange(<%=constantName%>, oldValue, <%=attrName%>);
+ }*/
+ );
+ } else {
+ setOperationBody(operation, ""
+ /*{
+ this.<%=attrName%> = <%=attrName%>;
+ }*/
+ );
+ }
+ }
+
+ protected void addSerializable(ObjectModelClass input,
+ ObjectModelClass output,
+ boolean interfaceFound) {
+ if (!interfaceFound) {
+ addInterface(output, Serializable.class);
+ }
+
+ // Generate the serialVersionUID
+ long serialVersionUID = JpaTemplatesGeneratorUtil.generateSerialVersionUID(input);
+
+ addConstant(output,
+ JpaTemplatesGeneratorUtil.SERIAL_VERSION_UID,
+ "long",
+ serialVersionUID + "L",
+ ObjectModelJavaModifier.PRIVATE
+ );
+ }
+
+ /**
+ * Add all interfaces defines in input class and returns if
+ * {@link Serializable} interface was found.
+ *
+ * @param input the input model class to process
+ * @param output the output generated class
+ * @return {@code true} if {@link Serializable} was found from input,
+ * {@code false} otherwise
+ */
+ protected boolean addInterfaces(ObjectModelClass input,
+ ObjectModelClass output) {
+ boolean foundSerializable = false;
+ for (ObjectModelInterface parentInterface : input.getInterfaces()) {
+ String fqn = parentInterface.getQualifiedName();
+ addInterface(output, fqn);
+ if (Serializable.class.getName().equals(fqn)) {
+ foundSerializable = true;
+ }
+ }
+ return foundSerializable;
+ }
+
+ protected void createPropertyChangeSupport(ObjectModelClass output) {
+
+ addAttribute(output,
+ "pcs",
+ PropertyChangeSupport.class,
+ "new PropertyChangeSupport(this)",
+ ObjectModelJavaModifier.PROTECTED,
+ ObjectModelJavaModifier.FINAL,
+ ObjectModelJavaModifier.TRANSIENT
+ );
+
+ // Add PropertyListener
+
+ ObjectModelOperation operation;
+
+ operation = addOperation(output,
+ "addPropertyChangeListener",
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, PropertyChangeListener.class, "listener");
+ setOperationBody(operation, ""
+ /*{
+ pcs.addPropertyChangeListener(listener);
+ }*/
+ );
+
+ operation = addOperation(output,
+ "addPropertyChangeListener",
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, String.class, "propertyName");
+ addParameter(operation, PropertyChangeListener.class, "listener");
+ setOperationBody(operation, ""
+ /*{
+ pcs.addPropertyChangeListener(propertyName, listener);
+ }*/
+ );
+
+ operation = addOperation(output,
+ "removePropertyChangeListener",
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, PropertyChangeListener.class, "listener");
+ setOperationBody(operation, ""
+ /*{
+ pcs.removePropertyChangeListener(listener);
+ }*/
+ );
+
+ operation = addOperation(output,
+ "removePropertyChangeListener",
+ "void",
+ ObjectModelJavaModifier.PUBLIC
+ );
+ addParameter(operation, String.class, "propertyName");
+ addParameter(operation, PropertyChangeListener.class, "listener");
+ setOperationBody(operation, ""
+ /*{
+ pcs.removePropertyChangeListener(propertyName, listener);
+ }*/
+ );
+
+ operation = addOperation(output,
+ "firePropertyChange",
+ "void",
+ ObjectModelJavaModifier.PROTECTED
+ );
+ addParameter(operation, String.class, "propertyName");
+ addParameter(operation, Object.class, "oldValue");
+ addParameter(operation, Object.class, "newValue");
+ setOperationBody(operation, ""
+ /*{
+ pcs.firePropertyChange(propertyName, oldValue, newValue);
+ }*/
+ );
+
+ operation = addOperation(output,
+ "firePropertyChange",
+ "void",
+ ObjectModelJavaModifier.PROTECTED
+ );
+ addParameter(operation, String.class, "propertyName");
+ addParameter(operation, Object.class, "newValue");
+ setOperationBody(operation, ""
+ /*{
+ firePropertyChange(propertyName, null, newValue);
+ }*/
+ );
+ }
+
+ protected void createGetChildMethod(ObjectModelClass output) {
+ ObjectModelOperation getChild = addOperation(
+ output,
+ "getChild", "<T> T",
+ ObjectModelJavaModifier.PROTECTED
+ );
+ addImport(output, List.class);
+
+ addParameter(getChild, "java.util.Collection<T>", "childs");
+ addParameter(getChild, "int", "index");
+ setOperationBody(getChild, ""
+/*{
+ T result = null;
+ if (childs != null) {
+ if (childs instanceof List) {
+ if (index < childs.size()) {
+ result = ((List<T>) childs).get(index);
+ }
+ } else {
+ int i = 0;
+ for (T o : childs) {
+ if (index == i) {
+ result = o;
+ break;
+ }
+ i++;
+ }
+ }
+ }
+ return result;
+}*/
+ );
+ }
+}
Deleted: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPADaoTransformer.java
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPADaoTransformer.java 2013-03-29 23:36:59 UTC (rev 1235)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPADaoTransformer.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -1,72 +0,0 @@
-package org.nuiton.eugene.jpa;
-
-/*
- * #%L
- * EUGene :: JPA templates
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2013 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>.
- * #L%
- */
-
-
-/*{generator option: parentheses = false}*/
-/*{generator option: writeString = +}*/
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.java.ObjectModelTransformerToJava;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-
-import java.util.Collection;
-
-/**
- * JPADaoTransformer generates a dao for an entity.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JPADaoTransformer"
- * @since 2.7
- */
-public class JPADaoTransformer extends ObjectModelTransformerToJava {
-
- private static final Log log = LogFactory.getLog(JPADaoTransformer.class);
-
- @Override
- public void transformFromClass(ObjectModelClass input) {
-
- if (!canGenerate(input)) {
-
- // not an entity, or skip, or already in classpath
- return;
- }
-
- //TODO
- ObjectModelClass output = null;
- }
-
- protected boolean canGenerate(ObjectModelClass input) {
- boolean b = !JPATemplatesGeneratorUtil.hasSkipStereotype(input) &&
- JPATemplatesGeneratorUtil.hasEntityStereotype(input);
- if (b) {
-
- // check if not found in class-path
- b = !isInClassPath(input);
- }
- return b;
- }
-}
\ No newline at end of file
Deleted: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPAEntityTransformer.java
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPAEntityTransformer.java 2013-03-29 23:36:59 UTC (rev 1235)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPAEntityTransformer.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -1,303 +0,0 @@
-package org.nuiton.eugene.jpa;
-
-/*
- * #%L
- * EUGene :: JPA templates
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2013 CodeLutin, Tony Chemit
- * %%
- * 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>.
- * #L%
- */
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-
-import javax.persistence.EntityManager;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-/*{generator option: parentheses = false}*/
-/*{generator option: writeString = +}*/
-
-/**
- * JavaBeanTransformer generates simple bean with pcs support
- * (and nothing else) according to the JavaBeans 1.1 norm.
- *
- * Since version 2.2.1, it is possible to
- * <ul>
- * <li>generate a simple POJO (says with no PCS support) by using the tag value {@link JPATemplatesTagValues#TAG_NO_PCS}.</li>
- * <li>generate i18n keys using the tag value {@link JPATemplatesTagValues#TAG_I18N_PREFIX}.</li>
- * </ul>
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JPAEntityTransformer"
- * @since 2.7
- */
-public class JPAEntityTransformer extends AbstractJPATransformer{
-
- private static final Log log = LogFactory.getLog(JPAEntityTransformer.class);
-
- @Override
- public void transformFromClass(ObjectModelClass input) {
-
- if (!canGenerate(input)) {
-
- // not an entity, or skip
- return;
- }
-
- EntityManager m;
-
- ObjectModelClass output = null;
-
- if (canGenerateAbstract(input)) {
-
- // nothing more to do
- output = generateAbstract(input);
- }
-
- if (canGenerateImpl(input, output)) {
-
- generateImpl(input);
- }
- }
-
- protected boolean canGenerate(ObjectModelClass input) {
- boolean b = !JPATemplatesGeneratorUtil.hasSkipStereotype(input) &&
- JPATemplatesGeneratorUtil.hasEntityStereotype(input);
- return b;
- }
-
- protected boolean canGenerateAbstract(ObjectModelClass input) {
- boolean b = !isInClassPath(input);
- return b;
- }
-
- protected boolean canGenerateImpl(ObjectModelClass input,
- ObjectModelClass abstractOutput) {
- String fqn = input.getQualifiedName() + "Impl";
-
- if (isInClassPath(fqn)) {
-
- // already in class-path
- return false;
- }
-
- Collection<ObjectModelOperation> operations = input.getOperations();
- if (!operations.isEmpty()) {
-
- // this input have some specific operations (so Impl can not be generated)
- return false;
- }
-
- Collection<ObjectModelOperation> allOtherOperations =
- input.getAllOtherOperations(true);
-
- if (!allOtherOperations.isEmpty()) {
-
- Collection<ObjectModelOperation> allExistingOperations =
- new ArrayList<ObjectModelOperation>(input.getAllSuperclassOperations(true));
-
- if (abstractOutput!=null) {
- allExistingOperations.addAll(abstractOutput.getOperations());
- }
-
- for (ObjectModelOperation operation : allOtherOperations) {
- if (!allExistingOperations.contains(operation)) {
-
- // found one method not on super classe, so can't generate Impl
- return false;
- }
- }
- }
- return true;
-
-// boolean hasOperations = !allOtherOperations.isEmpty() ||
-// !operations.isEmpty();
-//
-// // generate only if no user operations found
-// return !hasOperations;
- }
-
-
-
-
- protected void createAbstractOperations(ObjectModelClass ouput,
- Iterable<ObjectModelOperation> operations) {
- JPATemplatesGeneratorUtil.cloneOperations(
- this,
- operations,
- ouput,
- true,
- ObjectModelJavaModifier.ABSTRACT
- );
- }
-
- protected ObjectModelClass generateAbstract(ObjectModelClass input) {
- // test if a super class has bean stereotype
- boolean superClassIsBean = false;
- Collection<ObjectModelClass> superclasses = input.getSuperclasses();
- if(CollectionUtils.isNotEmpty(superclasses)) {
- for (ObjectModelClass superclass : superclasses) {
- if (JPATemplatesGeneratorUtil.hasEntityStereotype(superclass)) {
- superClassIsBean = true;
- break;
- }
- }
- }
-
- String superClass = null;
-
- if (!superClassIsBean) {
-
- // try to find a super class by tag-value
- superClass =
- JPATemplatesGeneratorUtil.getEntitySuperClassTagValue(
- model, input);
- if (superClass != null) {
-
- // will act as if super class is a bean
- superClassIsBean = true;
- }
- }
-
- ObjectModelClass output =
- createAbstractClass(input.getName(), input.getPackageName());
-
- if (superClass != null) {
- setSuperClass(output, superClass);
- }
- if (log.isDebugEnabled()) {
- log.debug("will generate " + output.getQualifiedName());
- }
-
- String i18nPrefix = JPATemplatesGeneratorUtil.getI18nPrefixTagValue(input, model);
- if (!StringUtils.isEmpty(i18nPrefix)) {
- generateI18nBlock(input, output, i18nPrefix);
- }
-
- String noPCSTagValue = JPATemplatesGeneratorUtil.getNoPCSTagValue(model, input);
- boolean usePCS = StringUtils.isEmpty(noPCSTagValue) ||
- !"true".equals(noPCSTagValue.trim());
-
- String noGenerateBooleanGetMethods =
- JPATemplatesGeneratorUtil.getDoNotGenerateBooleanGetMethods(model, input);
- boolean generateBooleanGetMethods =
- StringUtils.isEmpty(noGenerateBooleanGetMethods) ||
- !"true".equals(noGenerateBooleanGetMethods.trim());
-
- String prefix = getConstantPrefix(input, DEFAULT_CONSTANT_PREFIX);
-
- setConstantPrefix(prefix);
-
- addSuperClass(input, output);
-
- boolean serializableFound = addInterfaces(input, output);
-
- if (superClassIsBean) {
- serializableFound = true;
- }
-
- addSerializable(input, output, serializableFound);
-
- Set<String> constantNames = addConstantsFromDependency(input, output);
-
- // Get available properties
- List<ObjectModelAttribute> properties = getProperties(input);
-
- // Add properties constant
- for (ObjectModelAttribute attr : properties) {
-
- createPropertyConstant(output, attr, prefix, constantNames);
- }
-
- // Add properties field + javabean methods
- for (ObjectModelAttribute attr : properties) {
-
- createProperty(output, attr, usePCS, generateBooleanGetMethods);
- }
-
- // Add operations
- createAbstractOperations(output, input.getOperations());
-
- if (!superClassIsBean) {
-
- if (usePCS) {
-
- // Add property change support
- createPropertyChangeSupport(output);
- }
- }
-
- boolean hasAMultipleProperty = containsMutiple(properties);
-
- // Add helper operations
- if (hasAMultipleProperty) {
-
- if (!superClassIsBean) {
-
- // add getChild methods
- createGetChildMethod(output);
- }
-
- }
- return output;
- }
-
- protected ObjectModelClass generateImpl(ObjectModelClass input) {
-
- ObjectModelClass resultClassImpl = createClass(
- input.getName() + "Impl",
- input.getPackageName()
- );
-
- // set the abstract resulClass as the resultClassImpl super class
- setSuperClass(resultClassImpl, input.getQualifiedName());
-
- // add a fix serialVersionUID, since the class has no field nor method
- addConstant(resultClassImpl,
- JPATemplatesGeneratorUtil.SERIAL_VERSION_UID,
- "long",
- "1L",
- ObjectModelJavaModifier.PRIVATE
- );
- return resultClassImpl;
- }
-
- protected void addSuperClass(ObjectModelClass input,
- ObjectModelClass output) {
- // Set superclass
- Iterator<ObjectModelClass> j = input.getSuperclasses().iterator();
- if (j.hasNext()) {
- ObjectModelClass p = j.next();
- // We want to set the inheritance to the implementation class of the father
- // Ex for model : A -> B (a inherits B) we want : A -> BImpl -> B
- String qualifiedName = p.getQualifiedName() + "Impl";
- setSuperClass(output, qualifiedName);
- }
- }
-}
\ No newline at end of file
Deleted: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesGeneratorUtil.java
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesGeneratorUtil.java 2013-03-29 23:36:59 UTC (rev 1235)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesGeneratorUtil.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -1,84 +0,0 @@
-package org.nuiton.eugene.jpa;
-
-/*
- * #%L
- * EUGene :: JPA templates
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2013 CodeLutin, Tony Chemit
- * %%
- * 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>.
- * #L%
- */
-
-import org.nuiton.eugene.java.JavaGeneratorUtil;
-import org.nuiton.eugene.models.object.ObjectModel;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-
-/**
- * Utility class for pure jpa templates.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.7
- */
-public class JPATemplatesGeneratorUtil extends JavaGeneratorUtil {
-
- /**
- * Check if the given classifier has the
- * {@link JPATemplatesStereoTypes#STEREOTYPE_ENTITY} stereotype.
- *
- * @param classifier classifier to test
- * @return {@code true} if stereotype was found, {@code false otherwise}
- * @see JPATemplatesStereoTypes#STEREOTYPE_ENTITY
- */
- public static boolean hasEntityStereotype(ObjectModelClassifier classifier) {
- return classifier.hasStereotype(JPATemplatesStereoTypes.STEREOTYPE_ENTITY);
- }
-
- /**
- * Obtain the value of the {@link JPATemplatesTagValues#TAG_NO_PCS}
- * tag value on the given model or classifier.
- * <p/>
- * It will first look on the model, and then in the given classifier.
- *
- * @param model model to seek
- * @param classifier classifier to seek
- * @return the none empty value of the found tag value or {@code null} if not found nor empty.
- * @see JPATemplatesTagValues#TAG_NO_PCS
- * @since 2.3
- */
- public static String getNoPCSTagValue(ObjectModel model, ObjectModelClassifier classifier) {
- String value = findTagValue(JPATemplatesTagValues.TAG_NO_PCS, classifier, model);
- return value;
- }
-
- /**
- * Obtain the value of the {@link JPATemplatesTagValues#TAG_ENTITY_SUPER_CLASS}
- * tag value on the given model or classifier.
- * <p/>
- * It will first look on the model, and then in the given classifier.
- *
- * @param model model to seek
- * @param classifier classifier to seek
- * @return the none empty value of the found tag value or {@code null} if not found nor empty.
- * @see JPATemplatesTagValues#TAG_ENTITY_SUPER_CLASS
- * @since 2.3
- */
- public static String getEntitySuperClassTagValue(ObjectModel model, ObjectModelClassifier classifier) {
- String value = findTagValue(JPATemplatesTagValues.TAG_ENTITY_SUPER_CLASS, classifier, model);
- return value;
- }
-}
Deleted: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProvider.java
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProvider.java 2013-03-29 23:36:59 UTC (rev 1235)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProvider.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -1,43 +0,0 @@
-package org.nuiton.eugene.jpa;
-
-/*
- * #%L
- * EUGene :: JPA templates
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2013 CodeLutin, Tony Chemit
- * %%
- * 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>.
- * #L%
- */
-
-import org.nuiton.eugene.ModelPropertiesUtil;
-
-/**
- * The JPA templates provider of tag values and stereotypes.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @plexus.component role="org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider" role-hint="jpa"
- * @since 2.7
- */
-public class JPATemplatesModelPropertiesProvider extends ModelPropertiesUtil.ModelPropertiesProvider {
-
- @Override
- public void init() throws IllegalAccessException {
- scanStereotypeClass(JPATemplatesStereoTypes.class);
- scanTagValueClass(JPATemplatesTagValues.class);
- }
-}
Deleted: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesStereoTypes.java
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesStereoTypes.java 2013-03-29 23:36:59 UTC (rev 1235)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesStereoTypes.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -1,49 +0,0 @@
-package org.nuiton.eugene.jpa;
-
-/*
- * #%L
- * EUGene :: JPA templates
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2013 CodeLutin, Tony Chemit
- * %%
- * 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>.
- * #L%
- */
-
-import org.nuiton.eugene.EugeneStereoTypes;
-import org.nuiton.eugene.ModelPropertiesUtil;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-
-/**
- * Defines all stereotypes managed by JPA templates.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.7
- */
-public interface JPATemplatesStereoTypes extends EugeneStereoTypes {
-
- /**
- * Stereotype for JPA entities to place on a classifier.
- *
- * @see JPATemplatesGeneratorUtil#hasEntityStereotype(ObjectModelClassifier)
- * @since 2.5.6
- */
- @ModelPropertiesUtil.StereotypeDefinition(
- target = ObjectModelClassifier.class,
- documentation = "To specify that a class is a JPA Entity")
- String STEREOTYPE_ENTITY = "entity";
-}
Deleted: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesTagValues.java
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesTagValues.java 2013-03-29 23:36:59 UTC (rev 1235)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesTagValues.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -1,116 +0,0 @@
-package org.nuiton.eugene.jpa;
-
-/*
- * #%L
- * EUGene :: JPA templates
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2013 CodeLutin, Tony Chemit
- * %%
- * 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>.
- * #L%
- */
-
-import org.nuiton.eugene.EugeneTagValues;
-import org.nuiton.eugene.ModelPropertiesUtil;
-import org.nuiton.eugene.models.object.ObjectModel;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-
-/**
- * Defines all tag values managed by JPA templates.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.7
- */
-public interface JPATemplatesTagValues extends EugeneTagValues {
-
- /**
- * Tag value to set if do not want any pcs (says PropertyChangeSupport in a generated bean).
- * <p/>
- * You can globaly use it on the complete model or to a specific classifier.
- *
- * @see JPATemplatesGeneratorUtil#getNoPCSTagValue(ObjectModel, ObjectModelClassifier)
- * @since 2.7
- */
- @ModelPropertiesUtil.TagValueDefinition(
- target = {ObjectModel.class, ObjectModelClassifier.class},
- documentation = "To specify to not generate any propertyChange " +
- "code for a class or any class of a model")
- String TAG_NO_PCS = "noPCS";
-
- /**
- * Tag value to use a super class for generated bean.
- * <p/>
- * If the bean needs Property change support (says you do not add the {@link #TAG_NO_PCS} on classifier or model,
- * then your class must provide evrything for it.
- * <p/>
- * More over, if you use some collections in your bean you must also define
- * two method named {@code getChild(Collection list, int index)} and
- * {@code getChild(List list, int index)}
- * <p/>
- * See new code to know minimum stuff to add in your class for this purpose.
- * <pre>
- * public abstract class AbstractEntity implements Serializable {
- *
- * private static final long serialVersionUID = 1L;
- *
- * protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
- *
- * public void addPropertyChangeListener(PropertyChangeListener listener) {
- * pcs.addPropertyChangeListener(listener);
- * }
- *
- * public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- * pcs.addPropertyChangeListener(propertyName, listener);
- * }
- *
- * public void removePropertyChangeListener(PropertyChangeListener listener) {
- * pcs.removePropertyChangeListener(listener);
- * }
- *
- * public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- * pcs.removePropertyChangeListener(propertyName, listener);
- * }
- *
- * protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
- * pcs.firePropertyChange(propertyName, oldValue, newValue);
- * }
- *
- * protected void firePropertyChange(String propertyName, Object newValue) {
- * firePropertyChange(propertyName, null, newValue);
- * }
- *
- * protected <T> T getChild(Collection<T> list, int index) {
- * return CollectionUtil.getOrNull(list, index);
- * }
- *
- * protected <T> T getChild(List<T> list, int index) {
- * return CollectionUtil.getOrNull(list, index);
- * }
- * }
- * </pre>
- * <p/>
- * You can globaly use it on the complete model or to a specific classifier.
- *
- * @see JPATemplatesGeneratorUtil#getEntitySuperClassTagValue(ObjectModel, ObjectModelClassifier)
- * @since 2.7
- */
- @ModelPropertiesUtil.TagValueDefinition(
- target = {ObjectModel.class, ObjectModelClassifier.class},
- documentation = "To specify a super-class to used on generated entities " +
- "for a class or any class of a model")
- String TAG_ENTITY_SUPER_CLASS = "entitySuperClass";
-}
Copied: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaDaoTransformer.java (from rev 1234, trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPADaoTransformer.java)
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaDaoTransformer.java (rev 0)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaDaoTransformer.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -0,0 +1,70 @@
+package org.nuiton.eugene.jpa;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 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>.
+ * #L%
+ */
+
+
+/*{generator option: parentheses = false}*/
+/*{generator option: writeString = +}*/
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.java.ObjectModelTransformerToJava;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+
+/**
+ * JpaDaoTransformer generates a dao for an entity.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JpaDaoTransformer"
+ * @since 2.7
+ */
+public class JpaDaoTransformer extends ObjectModelTransformerToJava {
+
+ private static final Log log = LogFactory.getLog(JpaDaoTransformer.class);
+
+ @Override
+ public void transformFromClass(ObjectModelClass input) {
+
+ if (!canGenerate(input)) {
+
+ // not an entity, or skip, or already in classpath
+ return;
+ }
+
+ //TODO
+ ObjectModelClass output = null;
+ }
+
+ protected boolean canGenerate(ObjectModelClass input) {
+ boolean b = !JpaTemplatesGeneratorUtil.hasSkipStereotype(input) &&
+ JpaTemplatesGeneratorUtil.hasEntityStereotype(input);
+ if (b) {
+
+ // check if not found in class-path
+ b = !isInClassPath(input);
+ }
+ return b;
+ }
+}
\ No newline at end of file
Copied: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaEntityTransformer.java (from rev 1234, trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPAEntityTransformer.java)
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaEntityTransformer.java (rev 0)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaEntityTransformer.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -0,0 +1,303 @@
+package org.nuiton.eugene.jpa;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * 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>.
+ * #L%
+ */
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelJavaModifier;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+
+import javax.persistence.EntityManager;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/*{generator option: parentheses = false}*/
+/*{generator option: writeString = +}*/
+
+/**
+ * JavaBeanTransformer generates simple bean with pcs support
+ * (and nothing else) according to the JavaBeans 1.1 norm.
+ *
+ * Since version 2.2.1, it is possible to
+ * <ul>
+ * <li>generate a simple POJO (says with no PCS support) by using the tag value {@link JpaTemplatesTagValues#TAG_NO_PCS}.</li>
+ * <li>generate i18n keys using the tag value {@link JpaTemplatesTagValues#TAG_I18N_PREFIX}.</li>
+ * </ul>
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JpaEntityTransformer"
+ * @since 2.7
+ */
+public class JpaEntityTransformer extends AbstractJpaTransformer {
+
+ private static final Log log = LogFactory.getLog(JpaEntityTransformer.class);
+
+ @Override
+ public void transformFromClass(ObjectModelClass input) {
+
+ if (!canGenerate(input)) {
+
+ // not an entity, or skip
+ return;
+ }
+
+ EntityManager m;
+
+ ObjectModelClass output = null;
+
+ if (canGenerateAbstract(input)) {
+
+ // nothing more to do
+ output = generateAbstract(input);
+ }
+
+ if (canGenerateImpl(input, output)) {
+
+ generateImpl(input);
+ }
+ }
+
+ protected boolean canGenerate(ObjectModelClass input) {
+ boolean b = !JpaTemplatesGeneratorUtil.hasSkipStereotype(input) &&
+ JpaTemplatesGeneratorUtil.hasEntityStereotype(input);
+ return b;
+ }
+
+ protected boolean canGenerateAbstract(ObjectModelClass input) {
+ boolean b = !isInClassPath(input);
+ return b;
+ }
+
+ protected boolean canGenerateImpl(ObjectModelClass input,
+ ObjectModelClass abstractOutput) {
+ String fqn = input.getQualifiedName() + "Impl";
+
+ if (isInClassPath(fqn)) {
+
+ // already in class-path
+ return false;
+ }
+
+ Collection<ObjectModelOperation> operations = input.getOperations();
+ if (!operations.isEmpty()) {
+
+ // this input have some specific operations (so Impl can not be generated)
+ return false;
+ }
+
+ Collection<ObjectModelOperation> allOtherOperations =
+ input.getAllOtherOperations(true);
+
+ if (!allOtherOperations.isEmpty()) {
+
+ Collection<ObjectModelOperation> allExistingOperations =
+ new ArrayList<ObjectModelOperation>(input.getAllSuperclassOperations(true));
+
+ if (abstractOutput!=null) {
+ allExistingOperations.addAll(abstractOutput.getOperations());
+ }
+
+ for (ObjectModelOperation operation : allOtherOperations) {
+ if (!allExistingOperations.contains(operation)) {
+
+ // found one method not on super classe, so can't generate Impl
+ return false;
+ }
+ }
+ }
+ return true;
+
+// boolean hasOperations = !allOtherOperations.isEmpty() ||
+// !operations.isEmpty();
+//
+// // generate only if no user operations found
+// return !hasOperations;
+ }
+
+
+
+
+ protected void createAbstractOperations(ObjectModelClass ouput,
+ Iterable<ObjectModelOperation> operations) {
+ JpaTemplatesGeneratorUtil.cloneOperations(
+ this,
+ operations,
+ ouput,
+ true,
+ ObjectModelJavaModifier.ABSTRACT
+ );
+ }
+
+ protected ObjectModelClass generateAbstract(ObjectModelClass input) {
+ // test if a super class has bean stereotype
+ boolean superClassIsBean = false;
+ Collection<ObjectModelClass> superclasses = input.getSuperclasses();
+ if(CollectionUtils.isNotEmpty(superclasses)) {
+ for (ObjectModelClass superclass : superclasses) {
+ if (JpaTemplatesGeneratorUtil.hasEntityStereotype(superclass)) {
+ superClassIsBean = true;
+ break;
+ }
+ }
+ }
+
+ String superClass = null;
+
+ if (!superClassIsBean) {
+
+ // try to find a super class by tag-value
+ superClass =
+ JpaTemplatesGeneratorUtil.getEntitySuperClassTagValue(
+ model, input);
+ if (superClass != null) {
+
+ // will act as if super class is a bean
+ superClassIsBean = true;
+ }
+ }
+
+ ObjectModelClass output =
+ createAbstractClass(input.getName(), input.getPackageName());
+
+ if (superClass != null) {
+ setSuperClass(output, superClass);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("will generate " + output.getQualifiedName());
+ }
+
+ String i18nPrefix = JpaTemplatesGeneratorUtil.getI18nPrefixTagValue(input, model);
+ if (!StringUtils.isEmpty(i18nPrefix)) {
+ generateI18nBlock(input, output, i18nPrefix);
+ }
+
+ String noPCSTagValue = JpaTemplatesGeneratorUtil.getNoPCSTagValue(model, input);
+ boolean usePCS = StringUtils.isEmpty(noPCSTagValue) ||
+ !"true".equals(noPCSTagValue.trim());
+
+ String noGenerateBooleanGetMethods =
+ JpaTemplatesGeneratorUtil.getDoNotGenerateBooleanGetMethods(model, input);
+ boolean generateBooleanGetMethods =
+ StringUtils.isEmpty(noGenerateBooleanGetMethods) ||
+ !"true".equals(noGenerateBooleanGetMethods.trim());
+
+ String prefix = getConstantPrefix(input, DEFAULT_CONSTANT_PREFIX);
+
+ setConstantPrefix(prefix);
+
+ addSuperClass(input, output);
+
+ boolean serializableFound = addInterfaces(input, output);
+
+ if (superClassIsBean) {
+ serializableFound = true;
+ }
+
+ addSerializable(input, output, serializableFound);
+
+ Set<String> constantNames = addConstantsFromDependency(input, output);
+
+ // Get available properties
+ List<ObjectModelAttribute> properties = getProperties(input);
+
+ // Add properties constant
+ for (ObjectModelAttribute attr : properties) {
+
+ createPropertyConstant(output, attr, prefix, constantNames);
+ }
+
+ // Add properties field + javabean methods
+ for (ObjectModelAttribute attr : properties) {
+
+ createProperty(output, attr, usePCS, generateBooleanGetMethods);
+ }
+
+ // Add operations
+ createAbstractOperations(output, input.getOperations());
+
+ if (!superClassIsBean) {
+
+ if (usePCS) {
+
+ // Add property change support
+ createPropertyChangeSupport(output);
+ }
+ }
+
+ boolean hasAMultipleProperty = containsMutiple(properties);
+
+ // Add helper operations
+ if (hasAMultipleProperty) {
+
+ if (!superClassIsBean) {
+
+ // add getChild methods
+ createGetChildMethod(output);
+ }
+
+ }
+ return output;
+ }
+
+ protected ObjectModelClass generateImpl(ObjectModelClass input) {
+
+ ObjectModelClass resultClassImpl = createClass(
+ input.getName() + "Impl",
+ input.getPackageName()
+ );
+
+ // set the abstract resulClass as the resultClassImpl super class
+ setSuperClass(resultClassImpl, input.getQualifiedName());
+
+ // add a fix serialVersionUID, since the class has no field nor method
+ addConstant(resultClassImpl,
+ JpaTemplatesGeneratorUtil.SERIAL_VERSION_UID,
+ "long",
+ "1L",
+ ObjectModelJavaModifier.PRIVATE
+ );
+ return resultClassImpl;
+ }
+
+ protected void addSuperClass(ObjectModelClass input,
+ ObjectModelClass output) {
+ // Set superclass
+ Iterator<ObjectModelClass> j = input.getSuperclasses().iterator();
+ if (j.hasNext()) {
+ ObjectModelClass p = j.next();
+ // We want to set the inheritance to the implementation class of the father
+ // Ex for model : A -> B (a inherits B) we want : A -> BImpl -> B
+ String qualifiedName = p.getQualifiedName() + "Impl";
+ setSuperClass(output, qualifiedName);
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesGeneratorUtil.java (from rev 1234, trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesGeneratorUtil.java)
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesGeneratorUtil.java (rev 0)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesGeneratorUtil.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -0,0 +1,84 @@
+package org.nuiton.eugene.jpa;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * 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>.
+ * #L%
+ */
+
+import org.nuiton.eugene.java.JavaGeneratorUtil;
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelClassifier;
+
+/**
+ * Utility class for pure jpa templates.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.7
+ */
+public class JpaTemplatesGeneratorUtil extends JavaGeneratorUtil {
+
+ /**
+ * Check if the given classifier has the
+ * {@link JpaTemplatesStereoTypes#STEREOTYPE_ENTITY} stereotype.
+ *
+ * @param classifier classifier to test
+ * @return {@code true} if stereotype was found, {@code false otherwise}
+ * @see JpaTemplatesStereoTypes#STEREOTYPE_ENTITY
+ */
+ public static boolean hasEntityStereotype(ObjectModelClassifier classifier) {
+ return classifier.hasStereotype(JpaTemplatesStereoTypes.STEREOTYPE_ENTITY);
+ }
+
+ /**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_NO_PCS}
+ * tag value on the given model or classifier.
+ * <p/>
+ * It will first look on the model, and then in the given classifier.
+ *
+ * @param model model to seek
+ * @param classifier classifier to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_NO_PCS
+ * @since 2.3
+ */
+ public static String getNoPCSTagValue(ObjectModel model, ObjectModelClassifier classifier) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_NO_PCS, classifier, model);
+ return value;
+ }
+
+ /**
+ * Obtain the value of the {@link JpaTemplatesTagValues#TAG_ENTITY_SUPER_CLASS}
+ * tag value on the given model or classifier.
+ * <p/>
+ * It will first look on the model, and then in the given classifier.
+ *
+ * @param model model to seek
+ * @param classifier classifier to seek
+ * @return the none empty value of the found tag value or {@code null} if not found nor empty.
+ * @see JpaTemplatesTagValues#TAG_ENTITY_SUPER_CLASS
+ * @since 2.3
+ */
+ public static String getEntitySuperClassTagValue(ObjectModel model, ObjectModelClassifier classifier) {
+ String value = findTagValue(JpaTemplatesTagValues.TAG_ENTITY_SUPER_CLASS, classifier, model);
+ return value;
+ }
+}
Copied: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesModelPropertiesProvider.java (from rev 1234, trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProvider.java)
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesModelPropertiesProvider.java (rev 0)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesModelPropertiesProvider.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -0,0 +1,43 @@
+package org.nuiton.eugene.jpa;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * 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>.
+ * #L%
+ */
+
+import org.nuiton.eugene.ModelPropertiesUtil;
+
+/**
+ * The JPA templates provider of tag values and stereotypes.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @plexus.component role="org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider" role-hint="jpa"
+ * @since 2.7
+ */
+public class JpaTemplatesModelPropertiesProvider extends ModelPropertiesUtil.ModelPropertiesProvider {
+
+ @Override
+ public void init() throws IllegalAccessException {
+ scanStereotypeClass(JpaTemplatesStereoTypes.class);
+ scanTagValueClass(JpaTemplatesTagValues.class);
+ }
+}
Copied: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesStereoTypes.java (from rev 1234, trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesStereoTypes.java)
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesStereoTypes.java (rev 0)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesStereoTypes.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -0,0 +1,49 @@
+package org.nuiton.eugene.jpa;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * 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>.
+ * #L%
+ */
+
+import org.nuiton.eugene.EugeneStereoTypes;
+import org.nuiton.eugene.ModelPropertiesUtil;
+import org.nuiton.eugene.models.object.ObjectModelClassifier;
+
+/**
+ * Defines all stereotypes managed by JPA templates.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.7
+ */
+public interface JpaTemplatesStereoTypes extends EugeneStereoTypes {
+
+ /**
+ * Stereotype for JPA entities to place on a classifier.
+ *
+ * @see JpaTemplatesGeneratorUtil#hasEntityStereotype(ObjectModelClassifier)
+ * @since 2.5.6
+ */
+ @ModelPropertiesUtil.StereotypeDefinition(
+ target = ObjectModelClassifier.class,
+ documentation = "To specify that a class is a JPA Entity")
+ String STEREOTYPE_ENTITY = "entity";
+}
Copied: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesTagValues.java (from rev 1234, trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesTagValues.java)
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesTagValues.java (rev 0)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JpaTemplatesTagValues.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -0,0 +1,116 @@
+package org.nuiton.eugene.jpa;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * 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>.
+ * #L%
+ */
+
+import org.nuiton.eugene.EugeneTagValues;
+import org.nuiton.eugene.ModelPropertiesUtil;
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelClassifier;
+
+/**
+ * Defines all tag values managed by JPA templates.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.7
+ */
+public interface JpaTemplatesTagValues extends EugeneTagValues {
+
+ /**
+ * Tag value to set if do not want any pcs (says PropertyChangeSupport in a generated bean).
+ * <p/>
+ * You can globaly use it on the complete model or to a specific classifier.
+ *
+ * @see JpaTemplatesGeneratorUtil#getNoPCSTagValue(ObjectModel, ObjectModelClassifier)
+ * @since 2.7
+ */
+ @ModelPropertiesUtil.TagValueDefinition(
+ target = {ObjectModel.class, ObjectModelClassifier.class},
+ documentation = "To specify to not generate any propertyChange " +
+ "code for a class or any class of a model")
+ String TAG_NO_PCS = "noPCS";
+
+ /**
+ * Tag value to use a super class for generated bean.
+ * <p/>
+ * If the bean needs Property change support (says you do not add the {@link #TAG_NO_PCS} on classifier or model,
+ * then your class must provide evrything for it.
+ * <p/>
+ * More over, if you use some collections in your bean you must also define
+ * two method named {@code getChild(Collection list, int index)} and
+ * {@code getChild(List list, int index)}
+ * <p/>
+ * See new code to know minimum stuff to add in your class for this purpose.
+ * <pre>
+ * public abstract class AbstractEntity implements Serializable {
+ *
+ * private static final long serialVersionUID = 1L;
+ *
+ * protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
+ *
+ * public void addPropertyChangeListener(PropertyChangeListener listener) {
+ * pcs.addPropertyChangeListener(listener);
+ * }
+ *
+ * public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ * pcs.addPropertyChangeListener(propertyName, listener);
+ * }
+ *
+ * public void removePropertyChangeListener(PropertyChangeListener listener) {
+ * pcs.removePropertyChangeListener(listener);
+ * }
+ *
+ * public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ * pcs.removePropertyChangeListener(propertyName, listener);
+ * }
+ *
+ * protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ * pcs.firePropertyChange(propertyName, oldValue, newValue);
+ * }
+ *
+ * protected void firePropertyChange(String propertyName, Object newValue) {
+ * firePropertyChange(propertyName, null, newValue);
+ * }
+ *
+ * protected <T> T getChild(Collection<T> list, int index) {
+ * return CollectionUtil.getOrNull(list, index);
+ * }
+ *
+ * protected <T> T getChild(List<T> list, int index) {
+ * return CollectionUtil.getOrNull(list, index);
+ * }
+ * }
+ * </pre>
+ * <p/>
+ * You can globaly use it on the complete model or to a specific classifier.
+ *
+ * @see JpaTemplatesGeneratorUtil#getEntitySuperClassTagValue(ObjectModel, ObjectModelClassifier)
+ * @since 2.7
+ */
+ @ModelPropertiesUtil.TagValueDefinition(
+ target = {ObjectModel.class, ObjectModelClassifier.class},
+ documentation = "To specify a super-class to used on generated entities " +
+ "for a class or any class of a model")
+ String TAG_ENTITY_SUPER_CLASS = "entitySuperClass";
+}
Modified: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/package-info.java
===================================================================
--- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/package-info.java 2013-03-29 23:36:59 UTC (rev 1235)
+++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/package-info.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -1,8 +1,8 @@
/**
* Eugene jpa package : JPA generators.
* <pre>
- * - Generator : {@link JPAEntityTransformer } to generate a jap entity.
- * - Generator : {@link JPADaoTransformer } to generate a dao.
+ * - Generator : {@link JpaEntityTransformer } to generate a jap entity.
+ * - Generator : {@link JpaDaoTransformer } to generate a dao.
* </pre>
*/
package org.nuiton.eugene.jpa;
Modified: trunk/eugene-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider
===================================================================
--- trunk/eugene-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider 2013-03-29 23:36:59 UTC (rev 1235)
+++ trunk/eugene-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider 2013-04-01 20:50:47 UTC (rev 1236)
@@ -1 +1 @@
-org.nuiton.eugene.jpa.JPATemplatesModelPropertiesProvider
\ No newline at end of file
+org.nuiton.eugene.jpa.JpaTemplatesModelPropertiesProvider
\ No newline at end of file
Modified: trunk/eugene-jpa-templates/src/site/fr/rst/index.rst
===================================================================
--- trunk/eugene-jpa-templates/src/site/fr/rst/index.rst 2013-03-29 23:36:59 UTC (rev 1235)
+++ trunk/eugene-jpa-templates/src/site/fr/rst/index.rst 2013-04-01 20:50:47 UTC (rev 1236)
@@ -38,7 +38,7 @@
Ce module offre des templates pour générer des objets jpa, à savoir :
-- des entités (*org.nuiton.eugene.jpa.JPAEntityTransformer*)
-- des dao (*org.nuiton.eugene.jpa.JPADaoTransformer*)
+- des entités (*org.nuiton.eugene.jpa.JpaEntityTransformer*)
+- des dao (*org.nuiton.eugene.jpa.JpaDaoTransformer*)
*TODO Finir cette documentation avant la version 3.0 en donnant un exemple complet d'utilisation.*
\ No newline at end of file
Modified: trunk/eugene-jpa-templates/src/site/rst/index.rst
===================================================================
--- trunk/eugene-jpa-templates/src/site/rst/index.rst 2013-03-29 23:36:59 UTC (rev 1235)
+++ trunk/eugene-jpa-templates/src/site/rst/index.rst 2013-04-01 20:50:47 UTC (rev 1236)
@@ -38,7 +38,7 @@
This module offers you some templates to generate some JPA stuff:
-- entities (*org.nuiton.eugene.jpa.JPAEntityTransformer*)
-- dao (*org.nuiton.eugene.jpa.JPADaoTransformer*)
+- entities (*org.nuiton.eugene.jpa.JpaEntityTransformer*)
+- dao (*org.nuiton.eugene.jpa.JpaDaoTransformer*)
* TODO Finish this documentation before version 3.0*.
Deleted: trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProviderTest.java
===================================================================
--- trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProviderTest.java 2013-03-29 23:36:59 UTC (rev 1235)
+++ trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProviderTest.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -1,146 +0,0 @@
-package org.nuiton.eugene.jpa;
-
-/*
- * #%L
- * EUGene :: JPA templates
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2013 CodeLutin, Tony Chemit
- * %%
- * 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>.
- * #L%
- */
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.nuiton.eugene.ModelPropertiesUtil;
-import org.nuiton.eugene.models.object.ObjectModel;
-import org.nuiton.eugene.models.object.ObjectModelAttribute;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-import org.nuiton.eugene.models.object.ObjectModelEnumeration;
-import org.nuiton.eugene.models.object.ObjectModelInterface;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-
-/**
- * To test stereotypes and tag values of this module.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.7
- */
-public class JPATemplatesModelPropertiesProviderTest {
-
- protected ModelPropertiesUtil.ModelPropertiesProvider provider;
-
- @Before
- public void setUp() throws Exception {
- provider = new JPATemplatesModelPropertiesProvider();
- provider.init();
- }
-
- @Test
- public void getTagValueTarget() throws Exception {
- getTagValueTarget(JPATemplatesTagValues.TAG_NO_PCS, ObjectModel.class, ObjectModelClassifier.class);
- }
-
- @Test
- public void containsTagValue() throws Exception {
- containsTagValue(JPATemplatesTagValues.TAG_NO_PCS, true);
- containsTagValue(JPATemplatesTagValues.TAG_ENTITY_SUPER_CLASS, true);
-
- long l = System.nanoTime();
- containsTagValue(JPATemplatesTagValues.TAG_NO_PCS + l, false);
- containsTagValue(JPATemplatesTagValues.TAG_ENTITY_SUPER_CLASS + l, false);
- }
-
- @Test
- public void acceptTagValue() throws Exception {
- acceptTagValue(JPATemplatesTagValues.TAG_NO_PCS, true, ObjectModel.class, ObjectModelClassifier.class, ObjectModelClass.class, ObjectModelEnumeration.class);
- acceptTagValue(JPATemplatesTagValues.TAG_ENTITY_SUPER_CLASS, true, ObjectModel.class, ObjectModelClassifier.class, ObjectModelClass.class, ObjectModelEnumeration.class);
-
- acceptTagValue(JPATemplatesTagValues.TAG_NO_PCS, false, ObjectModelOperation.class, ObjectModelAttribute.class);
- acceptTagValue(JPATemplatesTagValues.TAG_ENTITY_SUPER_CLASS, false, ObjectModelOperation.class, ObjectModelAttribute.class);
-
- long l = System.nanoTime();
- acceptTagValue(JPATemplatesTagValues.TAG_NO_PCS + l, false, ObjectModelOperation.class, ObjectModelAttribute.class);
- acceptTagValue(JPATemplatesTagValues.TAG_ENTITY_SUPER_CLASS + l, false, ObjectModelOperation.class, ObjectModelAttribute.class);
- }
-
- @Test
- public void getStereotypeTarget() throws Exception {
-
- getStereotypeTarget(JPATemplatesStereoTypes.STEREOTYPE_ENTITY, ObjectModelClassifier.class);
- }
-
- @Test
- public void containsStereotype() throws Exception {
- containsStereotype(JPATemplatesStereoTypes.STEREOTYPE_ENTITY, true);
-
- long l = System.nanoTime();
- containsStereotype(JPATemplatesStereoTypes.STEREOTYPE_ENTITY + l, false);
- }
-
- @Test
- public void acceptStereotype() throws Exception {
-
- acceptStereotype(JPATemplatesStereoTypes.STEREOTYPE_ENTITY, true, ObjectModelClassifier.class, ObjectModelClass.class, ObjectModelEnumeration.class, ObjectModelInterface.class);
-
- acceptStereotype(JPATemplatesStereoTypes.STEREOTYPE_ENTITY, false, ObjectModel.class, ObjectModelOperation.class);
-
- long l = System.nanoTime();
- acceptStereotype(JPATemplatesStereoTypes.STEREOTYPE_ENTITY + l, false, ObjectModel.class, ObjectModelOperation.class);
-
- }
-
- protected void getTagValueTarget(String name, Class<?>... expected) {
- Class<?>[] classes = provider.getTagValueTarget(name);
- Assert.assertNotNull("Could not find target for " + name, classes);
- Assert.assertEquals("Should have " + expected.length + " targets for " + name + " but had " + classes.length, classes.length, expected.length);
- Assert.assertArrayEquals(expected, classes);
- }
-
- protected void containsTagValue(String name, boolean expected) {
- boolean classes = provider.containsTagValue(name);
- Assert.assertEquals(expected, classes);
- }
-
- protected void acceptTagValue(String name, boolean expected, Class<?>... types) {
- for (Class<?> type : types) {
- boolean actual = provider.acceptTagValue(name, type);
- Assert.assertEquals(expected, actual);
- }
- }
-
- protected void getStereotypeTarget(String name, Class<?>... expected) {
- Class<?>[] classes = provider.getStereotypeTarget(name);
- Assert.assertNotNull("Could not find target for " + name, classes);
- Assert.assertEquals("Should have " + expected.length + " targets for " + name + " but had " + classes.length, classes.length, expected.length);
- Assert.assertArrayEquals(expected, classes);
- }
-
- protected void containsStereotype(String name, boolean expected) {
- boolean classes = provider.containsStereotype(name);
- Assert.assertEquals(expected, classes);
- }
-
- protected void acceptStereotype(String name, boolean expected, Class<?>... types) {
- for (Class<?> type : types) {
- boolean actual = provider.acceptStereotype(name, type);
- Assert.assertEquals(expected, actual);
- }
- }
-}
Copied: trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JpaTemplatesModelPropertiesProviderTest.java (from rev 1234, trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProviderTest.java)
===================================================================
--- trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JpaTemplatesModelPropertiesProviderTest.java (rev 0)
+++ trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JpaTemplatesModelPropertiesProviderTest.java 2013-04-01 20:50:47 UTC (rev 1236)
@@ -0,0 +1,146 @@
+package org.nuiton.eugene.jpa;
+
+/*
+ * #%L
+ * EUGene :: JPA templates
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 CodeLutin, Tony Chemit
+ * %%
+ * 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>.
+ * #L%
+ */
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.nuiton.eugene.ModelPropertiesUtil;
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelAttribute;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelClassifier;
+import org.nuiton.eugene.models.object.ObjectModelEnumeration;
+import org.nuiton.eugene.models.object.ObjectModelInterface;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+
+/**
+ * To test stereotypes and tag values of this module.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.7
+ */
+public class JpaTemplatesModelPropertiesProviderTest {
+
+ protected ModelPropertiesUtil.ModelPropertiesProvider provider;
+
+ @Before
+ public void setUp() throws Exception {
+ provider = new JpaTemplatesModelPropertiesProvider();
+ provider.init();
+ }
+
+ @Test
+ public void getTagValueTarget() throws Exception {
+ getTagValueTarget(JpaTemplatesTagValues.TAG_NO_PCS, ObjectModel.class, ObjectModelClassifier.class);
+ }
+
+ @Test
+ public void containsTagValue() throws Exception {
+ containsTagValue(JpaTemplatesTagValues.TAG_NO_PCS, true);
+ containsTagValue(JpaTemplatesTagValues.TAG_ENTITY_SUPER_CLASS, true);
+
+ long l = System.nanoTime();
+ containsTagValue(JpaTemplatesTagValues.TAG_NO_PCS + l, false);
+ containsTagValue(JpaTemplatesTagValues.TAG_ENTITY_SUPER_CLASS + l, false);
+ }
+
+ @Test
+ public void acceptTagValue() throws Exception {
+ acceptTagValue(JpaTemplatesTagValues.TAG_NO_PCS, true, ObjectModel.class, ObjectModelClassifier.class, ObjectModelClass.class, ObjectModelEnumeration.class);
+ acceptTagValue(JpaTemplatesTagValues.TAG_ENTITY_SUPER_CLASS, true, ObjectModel.class, ObjectModelClassifier.class, ObjectModelClass.class, ObjectModelEnumeration.class);
+
+ acceptTagValue(JpaTemplatesTagValues.TAG_NO_PCS, false, ObjectModelOperation.class, ObjectModelAttribute.class);
+ acceptTagValue(JpaTemplatesTagValues.TAG_ENTITY_SUPER_CLASS, false, ObjectModelOperation.class, ObjectModelAttribute.class);
+
+ long l = System.nanoTime();
+ acceptTagValue(JpaTemplatesTagValues.TAG_NO_PCS + l, false, ObjectModelOperation.class, ObjectModelAttribute.class);
+ acceptTagValue(JpaTemplatesTagValues.TAG_ENTITY_SUPER_CLASS + l, false, ObjectModelOperation.class, ObjectModelAttribute.class);
+ }
+
+ @Test
+ public void getStereotypeTarget() throws Exception {
+
+ getStereotypeTarget(JpaTemplatesStereoTypes.STEREOTYPE_ENTITY, ObjectModelClassifier.class);
+ }
+
+ @Test
+ public void containsStereotype() throws Exception {
+ containsStereotype(JpaTemplatesStereoTypes.STEREOTYPE_ENTITY, true);
+
+ long l = System.nanoTime();
+ containsStereotype(JpaTemplatesStereoTypes.STEREOTYPE_ENTITY + l, false);
+ }
+
+ @Test
+ public void acceptStereotype() throws Exception {
+
+ acceptStereotype(JpaTemplatesStereoTypes.STEREOTYPE_ENTITY, true, ObjectModelClassifier.class, ObjectModelClass.class, ObjectModelEnumeration.class, ObjectModelInterface.class);
+
+ acceptStereotype(JpaTemplatesStereoTypes.STEREOTYPE_ENTITY, false, ObjectModel.class, ObjectModelOperation.class);
+
+ long l = System.nanoTime();
+ acceptStereotype(JpaTemplatesStereoTypes.STEREOTYPE_ENTITY + l, false, ObjectModel.class, ObjectModelOperation.class);
+
+ }
+
+ protected void getTagValueTarget(String name, Class<?>... expected) {
+ Class<?>[] classes = provider.getTagValueTarget(name);
+ Assert.assertNotNull("Could not find target for " + name, classes);
+ Assert.assertEquals("Should have " + expected.length + " targets for " + name + " but had " + classes.length, classes.length, expected.length);
+ Assert.assertArrayEquals(expected, classes);
+ }
+
+ protected void containsTagValue(String name, boolean expected) {
+ boolean classes = provider.containsTagValue(name);
+ Assert.assertEquals(expected, classes);
+ }
+
+ protected void acceptTagValue(String name, boolean expected, Class<?>... types) {
+ for (Class<?> type : types) {
+ boolean actual = provider.acceptTagValue(name, type);
+ Assert.assertEquals(expected, actual);
+ }
+ }
+
+ protected void getStereotypeTarget(String name, Class<?>... expected) {
+ Class<?>[] classes = provider.getStereotypeTarget(name);
+ Assert.assertNotNull("Could not find target for " + name, classes);
+ Assert.assertEquals("Should have " + expected.length + " targets for " + name + " but had " + classes.length, classes.length, expected.length);
+ Assert.assertArrayEquals(expected, classes);
+ }
+
+ protected void containsStereotype(String name, boolean expected) {
+ boolean classes = provider.containsStereotype(name);
+ Assert.assertEquals(expected, classes);
+ }
+
+ protected void acceptStereotype(String name, boolean expected, Class<?>... types) {
+ for (Class<?> type : types) {
+ boolean actual = provider.acceptStereotype(name, type);
+ Assert.assertEquals(expected, actual);
+ }
+ }
+}
1
0