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
May 2013
- 5 participants
- 32 discussions
r1248 - in trunk: eugene/src/main/java/org/nuiton/eugene/models/object/reader eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml eugene-plantuml-templates eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml
by agiraudet@users.nuiton.org 16 May '13
by agiraudet@users.nuiton.org 16 May '13
16 May '13
Author: agiraudet
Date: 2013-05-16 18:01:22 +0200 (Thu, 16 May 2013)
New Revision: 1248
Url: http://nuiton.org/projects/eugene/repository/revisions/1248
Log:
ajout de nouvelles fonctionnalit?\195?\169s ?\195?\160 YamlToObjectModel.java : g?\195?\168re presque toutes les options de l'ObjectModel (les principales) pour la syntaxe pure YAML
ajout de nouvelles fonctionnalit?\195?\169s ?\195?\160 PlantumlTemplatesGenerator.java : affiches d?\195?\169sormais les g?\195?\169n?\195?\169ralisations et classes d'association dans les diagrammes g?\195?\169n?\195?\169r?\195?\169s avec PlantUML
mise ?\195?\160 jour de la version de la d?\195?\169pendance de PlantUML du module eugene-plantuml-template
correction d'un import vers une classe supprim?\195?\169e dans YamlObjectModelReader.java
Note: d?\195?\169couverte d'un bug dans ObjectModelClassImpl.java ligne 124 (v?\195?\169rification avant prochain commit)
Modified:
trunk/eugene-plantuml-templates/pom.xml
trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/PlantumlTemplatesGenerator.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/yaml/YamlToObjectModel.java
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlUtil.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-15 15:59:44 UTC (rev 1247)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java 2013-05-16 16:01:22 UTC (rev 1248)
@@ -29,7 +29,6 @@
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.Test;
import org.nuiton.eugene.models.object.reader.yaml.YamlToObjectModel;
import org.yaml.snakeyaml.error.YAMLException;
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-15 15:59:44 UTC (rev 1247)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java 2013-05-16 16:01:22 UTC (rev 1248)
@@ -35,7 +35,7 @@
public static final String DOCUMENTATION = "documentation";
public static final String TAG_VALUES = "tagvalues";
public static final String COMMENTS = "comments";
- public static final String STEREOTYPES = "stereotype";
+ public static final String STEREOTYPES = "stereotypes";
public static final String EXTERN = "extern";
public static final String INNER = "inner";
public static final String TYPE = "type";
@@ -64,28 +64,30 @@
public static final String PARTICIPANT = "participant";
public static final String LITERAL = "literal";
+ private boolean _loginit = true;
+ private void log(String str) {
+ try {
+ FileWriter log;
+ String path = "/tmp/log.yaml.txt";
- private boolean _log = false;
-
- private void log(String str) throws IOException {
- FileWriter log = null;
- String path = "/tmp/log.yaml.txt";
- if (_log) {
- log = new FileWriter(path, _log);
+ if (_loginit) {
+ log = new FileWriter(path, false);
+ log.close();
+ _loginit = false;
+ }
+ log = new FileWriter(path, true);
log.write("[LOG] " + str + "\n");
log.close();
- } else {
- log = new FileWriter(path, _log);
- log.write("[LOG] start v1.0\n");
- log.close();
- _log = true;
- }
+ } catch (IOException e) {;}
}
public YamlToObjectModel() {
yaml = new Yaml();
}
+ //TODO: retourner boolean sur reussite chargement ? ou lever excpetions ?
+ //TODO: charger valeurs par defaut en fonction de la version de la syntaxe yaml (syntaxe: version), charger les valeurs à partir d'un fichier ou d'une classe ?
+ //if(valeur == null) -> charger valeur par defaut -charger celles de l'utilisateur ou celles du programme ou rien
public void loadFile(File file, ObjectModel model) throws IOException {
ObjectModelImpl modelOM = (ObjectModelImpl) model;
InputStream input = new FileInputStream(file);
@@ -93,8 +95,8 @@
input.close();
List<String> ignore = new LinkedList<String>();
- ignore.add("imports");
- ignore.add("tagvalues");
+ ignore.add(IMPORTS);
+ ignore.add(TAG_VALUES);
browseKeySetToLowerCase(modelYAML, ignore);
loadModel(modelYAML, modelOM);
@@ -111,8 +113,8 @@
return null;
}
- public List collectAllElements(List data, Object key) {
- List res = new LinkedList();
+ public List<Object> collectAllElements(List data, Object key) {
+ List<Object> res = new LinkedList<Object>();
for (Object obj : data) {
if (obj instanceof Map) {
if (((Map) obj).containsKey(key)) {
@@ -194,9 +196,7 @@
loadEnumeration(enumerationYAML, enumerationOM);
modelOM.addEnumeration(enumerationOM);
}
-
}
- //return true/false -> chargement reussi ?
}
public void loadElement(Object elementYAML, ObjectModelElementImpl elementOM) {
@@ -249,6 +249,9 @@
ObjectModelImplRef stereotypeOM = new ObjectModelImplRef();
stereotypeOM.setName(String.valueOf(stereotype));
elementOM.addStereotype(stereotypeOM);
+ //log
+ log("stereotype="+stereotypeOM.getName());
+ //log
}
}
}
@@ -350,8 +353,29 @@
List participantsYAML = collectAllElements((List) associationClassYAML, PARTICIPANT);
for (Object participantYAML : participantsYAML) {
- ObjectModeImplAssociationClassParticipant participant = new ObjectModeImplAssociationClassParticipant();
- //TODO:
+ if (participantYAML instanceof List) {
+
+ ObjectModeImplAssociationClassParticipant participantOM = new ObjectModeImplAssociationClassParticipant();
+ participantOM.setAssociationClass(associationClassOM);
+
+ Object nameYAML = collectElement((List) participantYAML, NAME);
+ if (nameYAML == null) {
+ ;
+ } else {
+ participantOM.setName(String.valueOf(nameYAML));
+ }
+
+ Object attributeYAML = collectElement((List) participantYAML, ATTRIBUTE);
+ if (attributeYAML == null) {
+ ;
+ } else {
+ participantOM.setAttribute(String.valueOf(attributeYAML));
+ }
+
+ associationClassOM.addParticipant(participantOM);
+
+ log("associationClass");
+ }
}
}
}
@@ -545,5 +569,4 @@
}
}
}
-
}
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlUtil.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlUtil.java 2013-05-15 15:59:44 UTC (rev 1247)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlUtil.java 2013-05-16 16:01:22 UTC (rev 1248)
@@ -24,6 +24,7 @@
keySetToLowerCase((Map) obj);
for (Object key : ((Map) obj).keySet()) {
+ //tester si String ou caster avec valueOf
if (!ignore.contains(key)) {
browseKeySetToLowerCase(((Map) obj).get(key), ignore);
}
Modified: trunk/eugene-plantuml-templates/pom.xml
===================================================================
--- trunk/eugene-plantuml-templates/pom.xml 2013-05-15 15:59:44 UTC (rev 1247)
+++ trunk/eugene-plantuml-templates/pom.xml 2013-05-16 16:01:22 UTC (rev 1248)
@@ -46,7 +46,7 @@
<dependency>
<groupId>net.sourceforge.plantuml</groupId>
<artifactId>plantuml</artifactId>
- <version>7962</version>
+ <version>7965</version>
</dependency>
</dependencies>
Modified: 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 2013-05-15 15:59:44 UTC (rev 1247)
+++ trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/PlantumlTemplatesGenerator.java 2013-05-16 16:01:22 UTC (rev 1248)
@@ -3,6 +3,7 @@
import net.sourceforge.plantuml.GeneratedImage;
import net.sourceforge.plantuml.SourceFileReader;
import org.nuiton.eugene.models.object.*;
+import org.nuiton.eugene.models.object.xml.ObjectModelClassImpl;
import java.io.*;
import java.util.*;
@@ -12,12 +13,27 @@
public class PlantumlTemplatesGenerator extends ObjectModelGenerator {
+ private boolean _loginit = true;
+ private void log(String str) {
+ try {
+ FileWriter log;
+ String path = "/tmp/log.yaml.txt";
+
+ if (_loginit) {
+ log = new FileWriter(path, false);
+ log.close();
+ _loginit = false;
+ }
+ log = new FileWriter(path, true);
+ log.write("[LOG] " + str + "\n");
+ log.close();
+ } catch (IOException e) {;}
+ }
+
@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
+ //log
+ //log
// utiliser le systeme de templates a l'avenir
@@ -33,9 +49,18 @@
if(class_tmp.getStereotypes().size()>0)
{
classStereotype = "<<";
+ boolean first = true;
for(String str : class_tmp.getStereotypes())
{
- classStereotype = classStereotype+","+str;
+ if(first)
+ {
+ classStereotype = classStereotype+str;
+ first = false;
+ }
+ else
+ {
+ classStereotype = classStereotype+" ,"+str;
+ }
}
classStereotype = classStereotype+">>";
}
@@ -147,6 +172,55 @@
}
}
+ //classes d'association
+ Map<String,LinkedList<String>> associationClass = new LinkedHashMap<String, LinkedList<String>>();
+ for(ObjectModelClassifier classifier : input.getClassifiers())
+ {
+ for(ObjectModelAttribute attribute : classifier.getAttributes())
+ {
+ if(attribute.hasAssociationClass())
+ {
+ String key = attribute.getAssociationClass().getName();
+ String value = classifier.getName();
+ if(associationClass.containsKey(key))
+ {
+ associationClass.get(key).add(value);
+ }
+ else
+ {
+ associationClass.put(key,new LinkedList<String>());
+ associationClass.get(key).add(value);
+ }
+ }
+ }
+ }
+ for(Map.Entry<String,LinkedList<String>> entry : associationClass.entrySet())
+ {
+ boolean first = true;
+ output.write("(");
+ for(String value : entry.getValue())
+ {
+ if(first)
+ {
+ output.write(value);
+ first = false;
+ }else
+ {
+ output.write(", "+value);
+ }
+ }
+ output.write(") .. "+entry.getKey()+"\n");
+ }
+
+ //extensions/generalisations (heritage)
+ for(ObjectModelClass classOM : input.getClasses())
+ {
+ for(ObjectModelClass superClassOM : classOM.getSuperclasses())
+ {
+ output.write(superClassOM.getName()+" <|-- "+classOM.getName());
+ }
+ }
+
// fin du fichier
output.write("\n@enduml");
}
@@ -177,8 +251,7 @@
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();
+ new File(lst.get(0).getPngFile(), destDir+File.separator+model.getName()+".png");
} catch (InterruptedException e) {
e.printStackTrace();
}
1
0
r1247 - trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml
by agiraudet@users.nuiton.org 15 May '13
by agiraudet@users.nuiton.org 15 May '13
15 May '13
Author: agiraudet
Date: 2013-05-15 17:59:44 +0200 (Wed, 15 May 2013)
New Revision: 1247
Url: http://nuiton.org/projects/eugene/repository/revisions/1247
Log:
ajout de YamlUtil.java
Added:
trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlUtil.java
Modified:
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/yaml/YamlToObjectModel.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java 2013-05-15 15:38:03 UTC (rev 1246)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java 2013-05-15 15:59:44 UTC (rev 1247)
@@ -8,15 +8,19 @@
import java.util.*;
import static org.nuiton.eugene.models.object.reader.yaml.YamlUtil.browseKeySetToLowerCase;
+
/**
* User: agiraudet
* Date: 15/05/13
* Time: 11:15
*/
+
+//TODO: gestion des labels
+
public class YamlToObjectModel {
protected Yaml yaml;
protected String packageOM;
- protected Map<String,String> imports;
+ protected Map<String, String> imports;
//mots clefs
public static final String IMPORTS = "imports";
@@ -62,17 +66,15 @@
private boolean _log = false;
+
private void log(String str) throws IOException {
FileWriter log = null;
String path = "/tmp/log.yaml.txt";
- if(_log)
- {
+ if (_log) {
log = new FileWriter(path, _log);
log.write("[LOG] " + str + "\n");
log.close();
- }
- else
- {
+ } else {
log = new FileWriter(path, _log);
log.write("[LOG] start v1.0\n");
log.close();
@@ -80,8 +82,7 @@
}
}
- public YamlToObjectModel()
- {
+ public YamlToObjectModel() {
yaml = new Yaml();
}
@@ -96,7 +97,7 @@
ignore.add("tagvalues");
browseKeySetToLowerCase(modelYAML, ignore);
- loadModel(modelYAML,modelOM);
+ loadModel(modelYAML, modelOM);
}
public Object collectElement(List data, Object key) {
@@ -122,96 +123,75 @@
return res;
}
- public void loadModel(Object modelYAML, ObjectModelImpl modelOM)
- {
- if(modelYAML instanceof List)
- {
+ public void loadModel(Object modelYAML, ObjectModelImpl modelOM) {
+ if (modelYAML instanceof List) {
//load imports
imports = new LinkedHashMap<String, String>();
Object importsYAML = collectElement((List) modelYAML, IMPORTS);
- if(importsYAML instanceof Map)
- {
- for(Object entry : ((Map) importsYAML).entrySet())
- {
- if(entry instanceof Map.Entry)
- {
- imports.put(String.valueOf(((Map.Entry) entry).getKey()),String.valueOf(((Map.Entry) entry).getValue()));
+ if (importsYAML instanceof Map) {
+ for (Object entry : ((Map) importsYAML).entrySet()) {
+ if (entry instanceof Map.Entry) {
+ imports.put(String.valueOf(((Map.Entry) entry).getKey()), String.valueOf(((Map.Entry) entry).getValue()));
}
}
}
//load package
Object packageYAML = collectElement((List) modelYAML, PACKAGE);
- if(packageYAML == null)
- {
+ if (packageYAML == null) {
;
- }
- else
- {
+ } else {
packageOM = String.valueOf(packageYAML);
}
Object nameYAML = collectElement((List) modelYAML, NAME);
- if(nameYAML == null)
- {
+ if (nameYAML == null) {
;
- }
- else
- {
+ } else {
modelOM.setName(String.valueOf(nameYAML));
}
Object versionYAML = collectElement((List) modelYAML, VERSION);
- if(versionYAML == null)
- {
+ if (versionYAML == null) {
;
- }
- else
- {
+ } else {
modelOM.setVersion(String.valueOf(versionYAML));
}
Object tagValuesYAML = collectElement((List) modelYAML, TAG_VALUES);
- if(tagValuesYAML instanceof Map)
- {
- for(Object entry : ((Map) tagValuesYAML).entrySet())
- {
- if(entry instanceof Map.Entry)
- {
- modelOM.addTagValue(String.valueOf(((Map.Entry) entry).getKey()),String.valueOf(((Map.Entry) entry).getValue()));
+ if (tagValuesYAML instanceof Map) {
+ for (Object entry : ((Map) tagValuesYAML).entrySet()) {
+ if (entry instanceof Map.Entry) {
+ modelOM.addTagValue(String.valueOf(((Map.Entry) entry).getKey()), String.valueOf(((Map.Entry) entry).getValue()));
}
}
}
List classesYAML = collectAllElements((List) modelYAML, CLASS);
- for(Object classYAML : classesYAML)
- {
+ for (Object classYAML : classesYAML) {
ObjectModelClassImpl classOM = new ObjectModelClassImpl();
- loadClass(classYAML,classOM);
+ loadClass(classYAML, classOM);
modelOM.addClass(classOM);
}
List interfacesYAML = collectAllElements((List) modelYAML, INTERFACE);
- for(Object interfaceYAML : interfacesYAML)
- {
+ for (Object interfaceYAML : interfacesYAML) {
ObjectModelInterfaceImpl interfaceOM = new ObjectModelInterfaceImpl();
- loadInterface(interfaceYAML,interfaceOM);
+ loadInterface(interfaceYAML, interfaceOM);
modelOM.addInterface(interfaceOM);
}
List classesAssociationYAML = collectAllElements((List) modelYAML, CLASS_ASSOCIATION);
- for(Object classAssociationYAML : classesAssociationYAML)
- {
+ for (Object classAssociationYAML : classesAssociationYAML) {
ObjectModelAssociationClassImpl classAssociationOM = new ObjectModelAssociationClassImpl();
- loadAssociationClass(classAssociationYAML,classAssociationOM);
+ loadAssociationClass(classAssociationYAML, classAssociationOM);
modelOM.addAssociationClass(classAssociationOM);
}
List enumerationsYAML = collectAllElements((List) modelYAML, ENUMERATION);
- for(Object enumerationYAML : enumerationsYAML)
- {
+ for (Object enumerationYAML : enumerationsYAML) {
ObjectModelEnumerationImpl enumerationOM = new ObjectModelEnumerationImpl();
- loadEnumeration(enumerationYAML,enumerationOM);
+ loadEnumeration(enumerationYAML, enumerationOM);
modelOM.addEnumeration(enumerationOM);
}
@@ -219,71 +199,53 @@
//return true/false -> chargement reussi ?
}
- public void loadElement(Object elementYAML, ObjectModelElementImpl elementOM)
- {
- if(elementYAML instanceof List)
- {
+ public void loadElement(Object elementYAML, ObjectModelElementImpl elementOM) {
+ if (elementYAML instanceof List) {
//TODO: setDeclaringElement
//TODO: setObjectModelImpl
//TODO: addModifier
Object nameYAML = collectElement((List) elementYAML, NAME);
- if(nameYAML == null)
- {
+ if (nameYAML == null) {
;
- }
- else
- {
+ } else {
elementOM.setName(String.valueOf(nameYAML));
}
Object staticYAML = collectElement((List) elementYAML, STATIC);
- if(staticYAML == null)
- {
+ if (staticYAML == null) {
;
- }
- else
- {
+ } else {
elementOM.setStatic(Boolean.valueOf(String.valueOf(staticYAML)));
}
Object documentationYAML = collectElement((List) elementYAML, DOCUMENTATION);
- if(documentationYAML == null)
- {
+ if (documentationYAML == null) {
;
- }
- else
- {
+ } else {
elementOM.setDocumentation(String.valueOf(documentationYAML));
}
Object tagValuesYAML = collectElement((List) elementYAML, TAG_VALUES);
- if(tagValuesYAML instanceof Map)
- {
- for(Object entry : ((Map) tagValuesYAML).entrySet())
- {
- if(entry instanceof Map.Entry)
- {
- elementOM.addTagValue(String.valueOf(((Map.Entry) entry).getKey()),String.valueOf(((Map.Entry) entry).getValue()));
+ if (tagValuesYAML instanceof Map) {
+ for (Object entry : ((Map) tagValuesYAML).entrySet()) {
+ if (entry instanceof Map.Entry) {
+ elementOM.addTagValue(String.valueOf(((Map.Entry) entry).getKey()), String.valueOf(((Map.Entry) entry).getValue()));
}
}
}
Object commentsYAML = collectElement((List) elementYAML, COMMENTS);
- if(commentsYAML instanceof List)
- {
- for(Object comment : (List) commentsYAML)
- {
+ if (commentsYAML instanceof List) {
+ for (Object comment : (List) commentsYAML) {
elementOM.addComment(String.valueOf(comment));
}
}
Object stereotypesYAML = collectElement((List) elementYAML, STEREOTYPES);
{
- if(stereotypesYAML instanceof List)
- {
- for(Object stereotype : (List) stereotypesYAML)
- {
+ if (stereotypesYAML instanceof List) {
+ for (Object stereotype : (List) stereotypesYAML) {
ObjectModelImplRef stereotypeOM = new ObjectModelImplRef();
stereotypeOM.setName(String.valueOf(stereotype));
elementOM.addStereotype(stereotypeOM);
@@ -293,75 +255,57 @@
}
}
- public void loadClassifier(Object classifierYAML, ObjectModelClassifierImpl classifierOM)
- {
- if(classifierYAML instanceof List)
- {
+ public void loadClassifier(Object classifierYAML, ObjectModelClassifierImpl classifierOM) {
+ if (classifierYAML instanceof List) {
//TODO: addDependency
loadElement(classifierYAML, classifierOM);
Object packageYAML = collectElement((List) classifierYAML, PACKAGE);
- if(packageYAML == null)
- {
+ if (packageYAML == null) {
classifierOM.setPackage(packageOM);
- }
- else
- {
+ } else {
classifierOM.setPackage(String.valueOf(packageYAML));
}
Object externYAML = collectElement((List) classifierYAML, EXTERN);
- if(externYAML == null)
- {
+ if (externYAML == null) {
;
- }
- else
- {
+ } else {
classifierOM.setExtern(Boolean.valueOf(String.valueOf(externYAML)));
}
Object innerYAML = collectElement((List) classifierYAML, INNER);
- if(innerYAML == null)
- {
+ if (innerYAML == null) {
;
- }
- else
- {
+ } else {
classifierOM.setInner(Boolean.valueOf(String.valueOf(innerYAML)));
}
Object typeYAML = collectElement((List) classifierYAML, TYPE);
- if(typeYAML == null)
- {
+ if (typeYAML == null) {
;
- }
- else
- {
+ } else {
classifierOM.setType(String.valueOf(typeYAML));
}
List attributesYAML = collectAllElements((List) classifierYAML, ATTRIBUTE);
- for(Object attributeYAML : attributesYAML)
- {
+ for (Object attributeYAML : attributesYAML) {
ObjectModelAttributeImpl attributeOM = new ObjectModelAttributeImpl();
loadAttribute(attributeYAML, attributeOM);
classifierOM.addAttribute(attributeOM);
}
List operationsYAML = collectAllElements((List) classifierYAML, OPERATION);
- for(Object operationYAML : operationsYAML)
- {
+ for (Object operationYAML : operationsYAML) {
ObjectModelOperationImpl operationOM = new ObjectModelOperationImpl();
loadOperation(operationYAML, operationOM);
classifierOM.addOperation(operationOM);
}
Object superInterfacesYAML = collectElement((List) classifierYAML, SUPER_INTERFACES);
- if(superInterfacesYAML instanceof List)
- {
- for(Object superInterface : (List) superInterfacesYAML)
- {
+ if (superInterfacesYAML instanceof List) {
+ for (Object superInterface : (List) superInterfacesYAML) {
ObjectModelImplRef superInterfaceOM = new ObjectModelImplRef();
superInterfaceOM.setName(String.valueOf(superInterface));
classifierOM.addInterface(superInterfaceOM);
@@ -370,29 +314,22 @@
}
}
- public void loadClass(Object classYAML, ObjectModelClassImpl classOM)
- {
- if(classYAML instanceof List)
- {
+ public void loadClass(Object classYAML, ObjectModelClassImpl classOM) {
+ if (classYAML instanceof List) {
//TODO: addInnerClassifier
loadClassifier(classYAML, classOM);
Object abstractYAML = collectElement((List) classYAML, ABSTRACT);
- if(abstractYAML == null)
- {
+ if (abstractYAML == null) {
;
- }
- else
- {
+ } else {
classOM.setAbstract(Boolean.valueOf(String.valueOf(abstractYAML)));
}
Object superClassesYAML = collectElement((List) classYAML, SUPER_CLASSES);
- if(superClassesYAML instanceof List)
- {
- for(Object superClass : (List) superClassesYAML)
- {
+ if (superClassesYAML instanceof List) {
+ for (Object superClass : (List) superClassesYAML) {
ObjectModelImplRef superClassOM = new ObjectModelImplRef();
superClassOM.setName(String.valueOf(superClass));
classOM.addSuperclass(superClassOM);
@@ -401,40 +338,31 @@
}
}
- public void loadInterface(Object interfaceYAML, ObjectModelInterfaceImpl interfaceOM)
- {
- if(interfaceYAML instanceof List)
- {
+ public void loadInterface(Object interfaceYAML, ObjectModelInterfaceImpl interfaceOM) {
+ if (interfaceYAML instanceof List) {
loadClassifier(interfaceYAML, interfaceOM);
}
}
- public void loadAssociationClass(Object associationClassYAML, ObjectModelAssociationClassImpl associationClassOM)
- {
- if(associationClassYAML instanceof List)
- {
+ public void loadAssociationClass(Object associationClassYAML, ObjectModelAssociationClassImpl associationClassOM) {
+ if (associationClassYAML instanceof List) {
loadClass(associationClassYAML, associationClassOM);
- List participantsYAML = collectAllElements((List) associationClassYAML, PARTICIPANT);
- for(Object participantYAML : participantsYAML)
- {
+ List participantsYAML = collectAllElements((List) associationClassYAML, PARTICIPANT);
+ for (Object participantYAML : participantsYAML) {
ObjectModeImplAssociationClassParticipant participant = new ObjectModeImplAssociationClassParticipant();
//TODO:
}
}
}
- public void loadEnumeration(Object enumerationYAML, ObjectModelEnumerationImpl enumerationOM)
- {
- if(enumerationYAML instanceof List)
- {
+ public void loadEnumeration(Object enumerationYAML, ObjectModelEnumerationImpl enumerationOM) {
+ if (enumerationYAML instanceof List) {
loadElement(enumerationYAML, enumerationOM);
Object literalsYAML = collectElement((List) enumerationYAML, LITERAL);
- if(literalsYAML instanceof List)
- {
- for(Object literalYAML : (List) literalsYAML)
- {
+ if (literalsYAML instanceof List) {
+ for (Object literalYAML : (List) literalsYAML) {
ObjectModelImplRef literalOM = new ObjectModelImplRef();
literalOM.setName(String.valueOf(literalYAML));
enumerationOM.addLiteral(literalOM);
@@ -443,249 +371,177 @@
}
}
- public void loadParameter(Object parameterYAML, ObjectModelParameterImpl parameterOM)
- {
- if(parameterYAML instanceof List)
- {
+ public void loadParameter(Object parameterYAML, ObjectModelParameterImpl parameterOM) {
+ if (parameterYAML instanceof List) {
loadElement(parameterYAML, parameterOM);
Object orderingYAML = collectElement((List) parameterYAML, ORDERING);
- if(orderingYAML == null)
- {
+ if (orderingYAML == null) {
;
- }
- else
- {
+ } else {
parameterOM.setOrdering(String.valueOf(orderingYAML));
}
Object typeYAML = collectElement((List) parameterYAML, TYPE);
- if(typeYAML == null)
- {
+ if (typeYAML == null) {
;
- }
- else
- {
+ } else {
String type = String.valueOf(typeYAML);
- if(imports.containsKey(type))
- {
+ if (imports.containsKey(type)) {
parameterOM.setType(imports.get(type));
- }
- else
- {
+ } else {
parameterOM.setType(type);
}
}
Object defaultValueYAML = collectElement((List) parameterYAML, DEFAULT_VALUE);
- if(defaultValueYAML == null)
- {
+ if (defaultValueYAML == null) {
;
- }
- else
- {
+ } else {
parameterOM.setDefaultValue(String.valueOf(defaultValueYAML));
}
Object minMultiplicityYAML = collectElement((List) parameterYAML, MIN_MULTIPLICITY);
- if(minMultiplicityYAML == null)
- {
+ if (minMultiplicityYAML == null) {
;
- }
- else
- {
+ } else {
parameterOM.setMinMultiplicity(Integer.valueOf(String.valueOf(minMultiplicityYAML)));
}
Object maxMultiplicityYAML = collectElement((List) parameterYAML, MAX_MULTIPLICITY);
- if(maxMultiplicityYAML == null)
- {
+ if (maxMultiplicityYAML == null) {
;
- }
- else
- {
+ } else {
parameterOM.setMaxMultiplicity(Integer.valueOf(String.valueOf(maxMultiplicityYAML)));
}
Object orderedYAML = collectElement((List) parameterYAML, ORDERED);
- if(orderedYAML == null)
- {
+ if (orderedYAML == null) {
;
- }
- else
- {
+ } else {
parameterOM.setOrdered(Boolean.valueOf(String.valueOf(orderedYAML)));
}
Object uniqueYAML = collectElement((List) parameterYAML, UNIQUE);
- if(uniqueYAML == null)
- {
+ if (uniqueYAML == null) {
;
- }
- else
- {
+ } else {
parameterOM.setUnique(Boolean.valueOf(String.valueOf(uniqueYAML)));
}
}
}
- public void loadAttribute(Object attributeYAML, ObjectModelAttributeImpl attributeOM)
- {
- if(attributeYAML instanceof List)
- {
+ public void loadAttribute(Object attributeYAML, ObjectModelAttributeImpl attributeOM) {
+ if (attributeYAML instanceof List) {
loadParameter(attributeYAML, attributeOM);
Object navigableYAML = collectElement((List) attributeYAML, NAVIGABLE);
- if(navigableYAML == null)
- {
+ if (navigableYAML == null) {
;
- }
- else
- {
+ } else {
attributeOM.setNavigable(Boolean.valueOf(String.valueOf(navigableYAML)));
}
Object associationTypeYAML = collectElement((List) attributeYAML, ASSOCIATION_TYPE);
- if(associationTypeYAML == null)
- {
+ if (associationTypeYAML == null) {
;
- }
- else
- {
+ } else {
attributeOM.setAssociationType(String.valueOf(associationTypeYAML));
}
Object finalYAML = collectElement((List) attributeYAML, FINAL);
- if(finalYAML == null)
- {
+ if (finalYAML == null) {
;
- }
- else
- {
+ } else {
attributeOM.setFinal(Boolean.valueOf(String.valueOf(finalYAML)));
}
Object staticYAML = collectElement((List) attributeYAML, STATIC);
- if(staticYAML == null)
- {
+ if (staticYAML == null) {
;
- }
- else
- {
+ } else {
attributeOM.setStatic(Boolean.valueOf(String.valueOf(staticYAML)));
}
Object associationClassNameYAML = collectElement((List) attributeYAML, ASSOCIATION_CLASS_NAME);
- if(associationClassNameYAML == null)
- {
+ if (associationClassNameYAML == null) {
;
- }
- else
- {
+ } else {
attributeOM.setAssociationClassName(String.valueOf(associationClassNameYAML));
}
Object reverseAttributeNameYAML = collectElement((List) attributeYAML, REVERSE_ATTRIBUTE_NAME);
- if(reverseAttributeNameYAML == null)
- {
+ if (reverseAttributeNameYAML == null) {
;
- }
- else
- {
+ } else {
attributeOM.setReverseAttributeName(String.valueOf(reverseAttributeNameYAML));
}
Object reverseMaxMultiplicityYAML = collectElement((List) attributeYAML, REVERSE_MAX_MULTIPLICITY);
- if(reverseMaxMultiplicityYAML == null)
- {
+ if (reverseMaxMultiplicityYAML == null) {
;
- }
- else
- {
+ } else {
attributeOM.setReverseMaxMultiplicity(Integer.valueOf(String.valueOf(reverseMaxMultiplicityYAML)));
}
Object transientYAML = collectElement((List) attributeYAML, TRANSIENT);
- if(transientYAML == null)
- {
+ if (transientYAML == null) {
;
- }
- else
- {
+ } else {
attributeOM.setTransient(Boolean.valueOf(String.valueOf(transientYAML)));
}
Object visibilityYAML = collectElement((List) attributeYAML, VISIBILITY);
- if(visibilityYAML == null)
- {
+ if (visibilityYAML == null) {
;
- }
- else
- {
+ } else {
attributeOM.setVisibility(String.valueOf(visibilityYAML));
}
}
}
- public void loadOperation(Object operationYAML, ObjectModelOperationImpl operationOM)
- {
- if(operationYAML instanceof List)
- {
+ public void loadOperation(Object operationYAML, ObjectModelOperationImpl operationOM) {
+ if (operationYAML instanceof List) {
//TODO: addExceptionParameter
loadElement(operationYAML, operationOM);
Object abstractYAML = collectElement((List) operationYAML, ABSTRACT);
- if(abstractYAML == null)
- {
+ if (abstractYAML == null) {
;
- }
- else
- {
+ } else {
operationOM.setAbstract(Boolean.valueOf(String.valueOf(abstractYAML)));
}
Object visibilityYAML = collectElement((List) operationYAML, VISIBILITY);
- if(visibilityYAML == null)
- {
+ if (visibilityYAML == null) {
;
- }
- else
- {
+ } else {
operationOM.setVisibility(String.valueOf(visibilityYAML));
}
Object returnParameterYAML = collectElement((List) operationYAML, RETURN_PARAMETER);
- if(returnParameterYAML == null)
- {
+ if (returnParameterYAML == null) {
;
- }
- else
- {
+ } else {
ObjectModelParameterImpl parameterOM = new ObjectModelAttributeImpl();
loadParameter(returnParameterYAML, parameterOM);
operationOM.setReturnParameter(parameterOM);
}
Object bodyCodeYAML = collectElement((List) operationYAML, BODY_CODE);
- if(bodyCodeYAML == null)
- {
+ if (bodyCodeYAML == null) {
;
- }
- else
- {
+ } else {
operationOM.setBodyCode(String.valueOf(bodyCodeYAML));
}
List parametersYAML = collectAllElements((List) operationYAML, PARAMETER);
- {
- for(Object parameterYAML : parametersYAML)
- {
- ObjectModelParameterImpl parameterOM = new ObjectModelAttributeImpl();
- loadParameter(parameterYAML, parameterOM);
- operationOM.addParameter(parameterOM);
- }
+ for (Object parameterYAML : parametersYAML) {
+ ObjectModelParameterImpl parameterOM = new ObjectModelAttributeImpl();
+ loadParameter(parameterYAML, parameterOM);
+ operationOM.addParameter(parameterOM);
}
}
}
Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlUtil.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlUtil.java (rev 0)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlUtil.java 2013-05-15 15:59:44 UTC (rev 1247)
@@ -0,0 +1,37 @@
+package org.nuiton.eugene.models.object.reader.yaml;
+
+import java.util.*;
+
+/**
+ * User: agiraudet
+ * Date: 14/05/13
+ * Time: 11:53
+ */
+public class YamlUtil {
+
+ public static void keySetToLowerCase(Map map) {
+ List keys = new ArrayList(map.keySet());
+ for (Object obj : keys) {
+ String key = String.valueOf(obj).toLowerCase();
+ Object value = map.get(obj);
+ map.remove(obj);
+ map.put(key, value);
+ }
+ }
+
+ public static void browseKeySetToLowerCase(Object obj, List ignore) {
+ if (obj instanceof Map) {
+ keySetToLowerCase((Map) obj);
+
+ for (Object key : ((Map) obj).keySet()) {
+ if (!ignore.contains(key)) {
+ browseKeySetToLowerCase(((Map) obj).get(key), ignore);
+ }
+ }
+ } else if (obj instanceof List) {
+ for (Object tmp : (List) obj) {
+ browseKeySetToLowerCase(tmp, ignore);
+ }
+ }
+ }
+}
1
0
r1246 - in trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader: . yaml
by agiraudet@users.nuiton.org 15 May '13
by agiraudet@users.nuiton.org 15 May '13
15 May '13
Author: agiraudet
Date: 2013-05-15 17:38:03 +0200 (Wed, 15 May 2013)
New Revision: 1246
Url: http://nuiton.org/projects/eugene/repository/revisions/1246
Log:
modification de eugene/models/object/reader/YamlObjectModelReader.java : nouveaux appels des m?\195?\169thodes de la classe YamlToObjectModel
modification de eugene/models/object/reader/yaml/YamlToObjectModel.java : nouvelle impl?\195?\169mentation et nouvelles fonctionnalit?\195?\169s
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-14 09:45:39 UTC (rev 1245)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java 2013-05-15 15:38:03 UTC (rev 1246)
@@ -29,6 +29,7 @@
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.Test;
import org.nuiton.eugene.models.object.reader.yaml.YamlToObjectModel;
import org.yaml.snakeyaml.error.YAMLException;
@@ -55,18 +56,13 @@
@Override
protected void beforeReadFile(File... files) {
super.beforeReadFile(files);
- //TODO : instancier parser yaml + controler clefs des maps
yamlToObjectModel = new YamlToObjectModel();
}
@Override
protected void readFileToModel(File file, ObjectModel model) throws IOException {
try {
- //TODO
- //test
- //NOTE: model deja instance
- yamlToObjectModel.test(file, model);
- //test
+ yamlToObjectModel.loadFile(file,model);
} 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-14 09:45:39 UTC (rev 1245)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java 2013-05-15 15:38:03 UTC (rev 1246)
@@ -7,431 +7,687 @@
import java.io.*;
import java.util.*;
+import static org.nuiton.eugene.models.object.reader.yaml.YamlUtil.browseKeySetToLowerCase;
/**
* 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 ?
+ * Date: 15/05/13
+ * Time: 11:15
*/
public class YamlToObjectModel {
protected Yaml yaml;
- protected Object modelYAML;
- protected ObjectModelImpl modelOM;
-
protected String packageOM;
protected Map<String,String> imports;
- private String _log = "/tmp/log.yaml.txt";
+ //mots clefs
+ public static final String IMPORTS = "imports";
+ public static final String PACKAGE = "package";
+ public static final String VERSION = "version";
+ public static final String NAME = "name";
+ public static final String CLASS = "class";
+ public static final String INTERFACE = "interface";
+ public static final String CLASS_ASSOCIATION = "classassociation";
+ public static final String ENUMERATION = "enumeration";
+ public static final String STATIC = "static";
+ public static final String DOCUMENTATION = "documentation";
+ public static final String TAG_VALUES = "tagvalues";
+ public static final String COMMENTS = "comments";
+ public static final String STEREOTYPES = "stereotype";
+ public static final String EXTERN = "extern";
+ public static final String INNER = "inner";
+ public static final String TYPE = "type";
+ public static final String ATTRIBUTE = "attribute";
+ public static final String OPERATION = "operation";
+ public static final String SUPER_INTERFACES = "superinterfaces";
+ public static final String SUPER_CLASSES = "superclasses";
+ public static final String ORDERING = "ordering";
+ public static final String DEFAULT_VALUE = "defaultvalue";
+ public static final String MIN_MULTIPLICITY = "minmultiplicity";
+ public static final String MAX_MULTIPLICITY = "maxmultiplicity";
+ public static final String ORDERED = "ordered";
+ public static final String UNIQUE = "unique";
+ public static final String NAVIGABLE = "navigable";
+ public static final String ASSOCIATION_TYPE = "associationtype";
+ public static final String FINAL = "final";
+ public static final String ASSOCIATION_CLASS_NAME = "associationclassname";
+ public static final String REVERSE_ATTRIBUTE_NAME = "reverseattributename";
+ public static final String REVERSE_MAX_MULTIPLICITY = "reversemaxmultiplicity";
+ public static final String TRANSIENT = "transient";
+ public static final String VISIBILITY = "visibility";
+ public static final String ABSTRACT = "abstract";
+ public static final String PARAMETER = "parameter";
+ public static final String RETURN_PARAMETER = "returnparameter";
+ public static final String BODY_CODE = "bodeycode";
+ public static final String PARTICIPANT = "participant";
+ public static final String LITERAL = "literal";
- 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();
- }
-
- private void startLog() {
+ private boolean _log = false;
+ private void log(String str) throws IOException {
FileWriter log = null;
- try {
- log = new FileWriter(this._log, false);
+ String path = "/tmp/log.yaml.txt";
+ if(_log)
+ {
+ log = new FileWriter(path, _log);
+ log.write("[LOG] " + str + "\n");
+ log.close();
+ }
+ else
+ {
+ log = new FileWriter(path, _log);
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.
+ _log = true;
}
}
- 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 YamlToObjectModel()
+ {
+ yaml = new Yaml();
}
- public void test(File file, ObjectModel model) throws IOException {
- //load file
+ public void loadFile(File file, ObjectModel model) throws IOException {
+ ObjectModelImpl modelOM = (ObjectModelImpl) model;
InputStream input = new FileInputStream(file);
- modelYAML = this.yaml.load(input);
+ Object modelYAML = yaml.load(input);
input.close();
- //file loaded
- modelOM = (ObjectModelImpl) model;
- loadModel();
+
+ List<String> ignore = new LinkedList<String>();
+ ignore.add("imports");
+ ignore.add("tagvalues");
+ browseKeySetToLowerCase(modelYAML, ignore);
+
+ loadModel(modelYAML,modelOM);
}
- //TODO : utiliser design pattern
- //TODO : utiliser genericite
- public void loadModel() {
- if (modelYAML instanceof List) {
- loadImports();
- Object nameYAML = collectElement((List) modelYAML, "name");
- if(nameYAML != null)
+ 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 collectAllElements(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;
+ }
+
+ public void loadModel(Object modelYAML, ObjectModelImpl modelOM)
+ {
+ if(modelYAML instanceof List)
+ {
+ //load imports
+ imports = new LinkedHashMap<String, String>();
+ Object importsYAML = collectElement((List) modelYAML, IMPORTS);
+ if(importsYAML instanceof Map)
{
- modelOM.setName(String.valueOf(nameYAML));
+ for(Object entry : ((Map) importsYAML).entrySet())
+ {
+ if(entry instanceof Map.Entry)
+ {
+ imports.put(String.valueOf(((Map.Entry) entry).getKey()),String.valueOf(((Map.Entry) entry).getValue()));
+ }
+ }
}
+
+ //load package
+ Object packageYAML = collectElement((List) modelYAML, PACKAGE);
+ if(packageYAML == null)
+ {
+ ;
+ }
else
{
- ;//TODO : charger valeur par defaut ou lever exception ?
+ packageOM = String.valueOf(packageYAML);
}
- Object versionYAML = collectElement((List) modelYAML, "version");
- if(versionYAML != null)
+ Object nameYAML = collectElement((List) modelYAML, NAME);
+ if(nameYAML == null)
{
- modelOM.setVersion(String.valueOf(versionYAML));
+ ;
}
else
{
- ;//TODO : charger valeur par defaut
+ modelOM.setName(String.valueOf(nameYAML));
}
- Object packageYAML = collectElement((List) modelYAML, "package");
- if(packageYAML != null)
+ Object versionYAML = collectElement((List) modelYAML, VERSION);
+ if(versionYAML == null)
{
- packageOM = String.valueOf(packageYAML);
+ ;
}
else
{
- ;//TODO : charger valeur par defaut
+ modelOM.setVersion(String.valueOf(versionYAML));
}
- //modelOM.setName(String.valueOf(this.collectElement((List) modelYAML, "name")));
- //modelOM.setVersion(String.valueOf(this.collectElement((List) modelYAML, "version")));
+ Object tagValuesYAML = collectElement((List) modelYAML, TAG_VALUES);
+ if(tagValuesYAML instanceof Map)
+ {
+ for(Object entry : ((Map) tagValuesYAML).entrySet())
+ {
+ if(entry instanceof Map.Entry)
+ {
+ modelOM.addTagValue(String.valueOf(((Map.Entry) entry).getKey()),String.valueOf(((Map.Entry) entry).getValue()));
+ }
+ }
+ }
- List classesYAML = this.collectAllElement((List) modelYAML, "class");
- for (Object classYAML : classesYAML) {
- ObjectModelClassImpl classOM = loadClass(classYAML);
- //tester null ?
+ List classesYAML = collectAllElements((List) modelYAML, CLASS);
+ for(Object classYAML : classesYAML)
+ {
+ ObjectModelClassImpl classOM = new ObjectModelClassImpl();
+ loadClass(classYAML,classOM);
modelOM.addClass(classOM);
}
- } else {
- ;//TODO : lever exception
+
+ List interfacesYAML = collectAllElements((List) modelYAML, INTERFACE);
+ for(Object interfaceYAML : interfacesYAML)
+ {
+ ObjectModelInterfaceImpl interfaceOM = new ObjectModelInterfaceImpl();
+ loadInterface(interfaceYAML,interfaceOM);
+ modelOM.addInterface(interfaceOM);
+ }
+
+ List classesAssociationYAML = collectAllElements((List) modelYAML, CLASS_ASSOCIATION);
+ for(Object classAssociationYAML : classesAssociationYAML)
+ {
+ ObjectModelAssociationClassImpl classAssociationOM = new ObjectModelAssociationClassImpl();
+ loadAssociationClass(classAssociationYAML,classAssociationOM);
+ modelOM.addAssociationClass(classAssociationOM);
+ }
+
+ List enumerationsYAML = collectAllElements((List) modelYAML, ENUMERATION);
+ for(Object enumerationYAML : enumerationsYAML)
+ {
+ ObjectModelEnumerationImpl enumerationOM = new ObjectModelEnumerationImpl();
+ loadEnumeration(enumerationYAML,enumerationOM);
+ modelOM.addEnumeration(enumerationOM);
+ }
+
}
+ //return true/false -> chargement reussi ?
}
- public ObjectModelClassImpl loadClass(Object classYAML) {
- if (classYAML instanceof List) {
- ObjectModelClassImpl classOM = new ObjectModelClassImpl();
+ public void loadElement(Object elementYAML, ObjectModelElementImpl elementOM)
+ {
+ if(elementYAML instanceof List)
+ {
+ //TODO: setDeclaringElement
+ //TODO: setObjectModelImpl
+ //TODO: addModifier
- this.loadStereotypes((List) classYAML, classOM);
- this.loadTagValues((List) classYAML, classOM);
- this.loadComments((List) classYAML, classOM);
+ Object nameYAML = collectElement((List) elementYAML, NAME);
+ if(nameYAML == null)
+ {
+ ;
+ }
+ else
+ {
+ elementOM.setName(String.valueOf(nameYAML));
+ }
- classOM.setPackage(packageOM);
+ Object staticYAML = collectElement((List) elementYAML, STATIC);
+ if(staticYAML == null)
+ {
+ ;
+ }
+ else
+ {
+ elementOM.setStatic(Boolean.valueOf(String.valueOf(staticYAML)));
+ }
- Object nameYAML = collectElement((List) classYAML, "name");
- if(nameYAML != null)
+ Object documentationYAML = collectElement((List) elementYAML, DOCUMENTATION);
+ if(documentationYAML == null)
{
- classOM.setName(String.valueOf(nameYAML));
+ ;
}
else
{
- //TODO : lever exception ?
+ elementOM.setDocumentation(String.valueOf(documentationYAML));
}
- Object abstractYAML = collectElement((List) classYAML, "abstract");
- if(abstractYAML != null)
+ Object tagValuesYAML = collectElement((List) elementYAML, TAG_VALUES);
+ if(tagValuesYAML instanceof Map)
{
- classOM.setAbstract(Boolean.valueOf(String.valueOf(abstractYAML)));//degolass
+ for(Object entry : ((Map) tagValuesYAML).entrySet())
+ {
+ if(entry instanceof Map.Entry)
+ {
+ elementOM.addTagValue(String.valueOf(((Map.Entry) entry).getKey()),String.valueOf(((Map.Entry) entry).getValue()));
+ }
+ }
}
+
+ Object commentsYAML = collectElement((List) elementYAML, COMMENTS);
+ if(commentsYAML instanceof List)
+ {
+ for(Object comment : (List) commentsYAML)
+ {
+ elementOM.addComment(String.valueOf(comment));
+ }
+ }
+
+ Object stereotypesYAML = collectElement((List) elementYAML, STEREOTYPES);
+ {
+ if(stereotypesYAML instanceof List)
+ {
+ for(Object stereotype : (List) stereotypesYAML)
+ {
+ ObjectModelImplRef stereotypeOM = new ObjectModelImplRef();
+ stereotypeOM.setName(String.valueOf(stereotype));
+ elementOM.addStereotype(stereotypeOM);
+ }
+ }
+ }
+ }
+ }
+
+ public void loadClassifier(Object classifierYAML, ObjectModelClassifierImpl classifierOM)
+ {
+ if(classifierYAML instanceof List)
+ {
+ //TODO: addDependency
+
+ loadElement(classifierYAML, classifierOM);
+
+ Object packageYAML = collectElement((List) classifierYAML, PACKAGE);
+ if(packageYAML == null)
+ {
+ classifierOM.setPackage(packageOM);
+ }
else
{
- ;//TODO : charger la valeur par defaut
+ classifierOM.setPackage(String.valueOf(packageYAML));
}
- /*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 (abstractYAML instanceof Boolean) {
- classOM.setAbstract((Boolean) abstractYAML);
- } else//sale
+ Object externYAML = collectElement((List) classifierYAML, EXTERN);
+ if(externYAML == null)
{
- classOM.setAbstract(Boolean.valueOf(String.valueOf(abstractYAML)));
- }*/
+ ;
+ }
+ else
+ {
+ classifierOM.setExtern(Boolean.valueOf(String.valueOf(externYAML)));
+ }
- //TODO : loadAttributes
- List attributesYAML = this.collectAllElement((List) classYAML, "attribute");
- for (Object attributeYAML : attributesYAML) {
- ObjectModelAttributeImpl attributeOM = loadAttribute(attributeYAML);
- classOM.addAttribute(attributeOM);
+ Object innerYAML = collectElement((List) classifierYAML, INNER);
+ if(innerYAML == null)
+ {
+ ;
}
- //TODO : loadOperations
+ else
+ {
+ classifierOM.setInner(Boolean.valueOf(String.valueOf(innerYAML)));
+ }
- //this.modelOM.addClass(classOM);
- return classOM;
- } else {
- ;//TODO : lever exception
- return null;
+ Object typeYAML = collectElement((List) classifierYAML, TYPE);
+ if(typeYAML == null)
+ {
+ ;
+ }
+ else
+ {
+ classifierOM.setType(String.valueOf(typeYAML));
+ }
+
+ List attributesYAML = collectAllElements((List) classifierYAML, ATTRIBUTE);
+ for(Object attributeYAML : attributesYAML)
+ {
+ ObjectModelAttributeImpl attributeOM = new ObjectModelAttributeImpl();
+ loadAttribute(attributeYAML, attributeOM);
+ classifierOM.addAttribute(attributeOM);
+ }
+
+ List operationsYAML = collectAllElements((List) classifierYAML, OPERATION);
+ for(Object operationYAML : operationsYAML)
+ {
+ ObjectModelOperationImpl operationOM = new ObjectModelOperationImpl();
+ loadOperation(operationYAML, operationOM);
+ classifierOM.addOperation(operationOM);
+ }
+
+ Object superInterfacesYAML = collectElement((List) classifierYAML, SUPER_INTERFACES);
+ if(superInterfacesYAML instanceof List)
+ {
+ for(Object superInterface : (List) superInterfacesYAML)
+ {
+ ObjectModelImplRef superInterfaceOM = new ObjectModelImplRef();
+ superInterfaceOM.setName(String.valueOf(superInterface));
+ classifierOM.addInterface(superInterfaceOM);
+ }
+ }
}
}
- public void loadInterface(Object _interface) {
- ;//TODO
+ public void loadClass(Object classYAML, ObjectModelClassImpl classOM)
+ {
+ if(classYAML instanceof List)
+ {
+ //TODO: addInnerClassifier
+
+ loadClassifier(classYAML, classOM);
+
+ Object abstractYAML = collectElement((List) classYAML, ABSTRACT);
+ if(abstractYAML == null)
+ {
+ ;
+ }
+ else
+ {
+ classOM.setAbstract(Boolean.valueOf(String.valueOf(abstractYAML)));
+ }
+
+ Object superClassesYAML = collectElement((List) classYAML, SUPER_CLASSES);
+ if(superClassesYAML instanceof List)
+ {
+ for(Object superClass : (List) superClassesYAML)
+ {
+ ObjectModelImplRef superClassOM = new ObjectModelImplRef();
+ superClassOM.setName(String.valueOf(superClass));
+ classOM.addSuperclass(superClassOM);
+ }
+ }
+ }
}
- public void loadAssociationClass(Object _associationClass) {
- ;//TODO
+ public void loadInterface(Object interfaceYAML, ObjectModelInterfaceImpl interfaceOM)
+ {
+ if(interfaceYAML instanceof List)
+ {
+ loadClassifier(interfaceYAML, interfaceOM);
+ }
}
- public void loadEnumeration(Object _enumeration) {
- ;//TODO
+ public void loadAssociationClass(Object associationClassYAML, ObjectModelAssociationClassImpl associationClassOM)
+ {
+ if(associationClassYAML instanceof List)
+ {
+ loadClass(associationClassYAML, associationClassOM);
+
+ List participantsYAML = collectAllElements((List) associationClassYAML, PARTICIPANT);
+ for(Object participantYAML : participantsYAML)
+ {
+ ObjectModeImplAssociationClassParticipant participant = new ObjectModeImplAssociationClassParticipant();
+ //TODO:
+ }
+ }
}
- public ObjectModelAttributeImpl loadAttribute(Object attributeYAML) {
- if(attributeYAML instanceof List)
+ public void loadEnumeration(Object enumerationYAML, ObjectModelEnumerationImpl enumerationOM)
+ {
+ if(enumerationYAML instanceof List)
{
- ObjectModelAttributeImpl attributeOM = new ObjectModelAttributeImpl();
+ loadElement(enumerationYAML, enumerationOM);
- this.loadStereotypes((List) attributeYAML, attributeOM);
- this.loadTagValues((List) attributeYAML, attributeOM);
- this.loadComments((List) attributeYAML, attributeOM);
+ Object literalsYAML = collectElement((List) enumerationYAML, LITERAL);
+ if(literalsYAML instanceof List)
+ {
+ for(Object literalYAML : (List) literalsYAML)
+ {
+ ObjectModelImplRef literalOM = new ObjectModelImplRef();
+ literalOM.setName(String.valueOf(literalYAML));
+ enumerationOM.addLiteral(literalOM);
+ }
+ }
+ }
+ }
- Object nameYAML = collectElement((List) attributeYAML, "name");
- if(nameYAML != null)
+ public void loadParameter(Object parameterYAML, ObjectModelParameterImpl parameterOM)
+ {
+ if(parameterYAML instanceof List)
+ {
+ loadElement(parameterYAML, parameterOM);
+
+ Object orderingYAML = collectElement((List) parameterYAML, ORDERING);
+ if(orderingYAML == null)
{
- attributeOM.setName(String.valueOf(nameYAML));
+ ;
}
else
{
- //TODO : charger la valeur par defaut
+ parameterOM.setOrdering(String.valueOf(orderingYAML));
}
- Object typeYAML = collectElement((List) attributeYAML, "type");
- if(typeYAML != null)
+ Object typeYAML = collectElement((List) parameterYAML, TYPE);
+ if(typeYAML == null)
{
- //TODO : gerer les imports et detection des types primitifs...
+ ;
+ }
+ else
+ {
String type = String.valueOf(typeYAML);
if(imports.containsKey(type))
{
- attributeOM.setType(imports.get(type));
+ parameterOM.setType(imports.get(type));
}
else
{
- attributeOM.setType(type);
+ parameterOM.setType(type);
}
}
+
+ Object defaultValueYAML = collectElement((List) parameterYAML, DEFAULT_VALUE);
+ if(defaultValueYAML == null)
+ {
+ ;
+ }
else
{
- ;//TODO : lever exception
+ parameterOM.setDefaultValue(String.valueOf(defaultValueYAML));
}
- Object visibilityYAML = collectElement((List) attributeYAML, "visibility");
- if(visibilityYAML != null)
+ Object minMultiplicityYAML = collectElement((List) parameterYAML, MIN_MULTIPLICITY);
+ if(minMultiplicityYAML == null)
{
- attributeOM.setVisibility(String.valueOf(visibilityYAML));
+ ;
}
else
{
- //TODO : charger valeur par defaut
+ parameterOM.setMinMultiplicity(Integer.valueOf(String.valueOf(minMultiplicityYAML)));
}
- Object staticYAML = collectElement((List) attributeYAML, "static");
- if(staticYAML != null)
+ Object maxMultiplicityYAML = collectElement((List) parameterYAML, MAX_MULTIPLICITY);
+ if(maxMultiplicityYAML == null)
{
- attributeOM.setStatic(Boolean.valueOf(String.valueOf(staticYAML)));//tester boolean ?
+ ;
}
else
{
- //TODO : charger valeur par defaut
+ parameterOM.setMaxMultiplicity(Integer.valueOf(String.valueOf(maxMultiplicityYAML)));
}
- Object finalYAML = collectElement((List) attributeYAML, "final");
- if(finalYAML != null)
+ Object orderedYAML = collectElement((List) parameterYAML, ORDERED);
+ if(orderedYAML == null)
{
- attributeOM.setFinal(Boolean.valueOf(String.valueOf(finalYAML)));
+ ;
}
else
{
- //TODO : charger la valeur par defaut
+ parameterOM.setOrdered(Boolean.valueOf(String.valueOf(orderedYAML)));
}
- Object associationTypeYAML = collectElement((List) attributeYAML, "asociationType");
- if(associationTypeYAML != null)
+ Object uniqueYAML = collectElement((List) parameterYAML, UNIQUE);
+ if(uniqueYAML == null)
{
- attributeOM.setAssociationType(String.valueOf(associationTypeYAML));
+ ;
}
else
{
- //TODO : charger la valeur par defaut
+ parameterOM.setUnique(Boolean.valueOf(String.valueOf(uniqueYAML)));
}
+ }
+ }
- Object minMultiplicityYAML = collectElement((List) attributeYAML, "minMultiplicity");
- if(minMultiplicityYAML != null)
+ public void loadAttribute(Object attributeYAML, ObjectModelAttributeImpl attributeOM)
+ {
+ if(attributeYAML instanceof List)
+ {
+ loadParameter(attributeYAML, attributeOM);
+
+ Object navigableYAML = collectElement((List) attributeYAML, NAVIGABLE);
+ if(navigableYAML == null)
{
- attributeOM.setMinMultiplicity(Integer.valueOf(String.valueOf(minMultiplicityYAML)));
+ ;
}
else
{
- //TODO : charger la valeur par defaut
+ attributeOM.setNavigable(Boolean.valueOf(String.valueOf(navigableYAML)));
}
- Object maxMultiplicityYAML = collectElement((List) attributeYAML, "maxMultiplicity");
- if(maxMultiplicityYAML != null)
+ Object associationTypeYAML = collectElement((List) attributeYAML, ASSOCIATION_TYPE);
+ if(associationTypeYAML == null)
{
- attributeOM.setMaxMultiplicity(Integer.valueOf(String.valueOf(maxMultiplicityYAML)));
+ ;
}
else
{
- //TODO : charger la valeur par defaut
+ attributeOM.setAssociationType(String.valueOf(associationTypeYAML));
}
- Object navigableYAML = collectElement((List) attributeYAML, "navigable");
- if(navigableYAML != null)
+ Object finalYAML = collectElement((List) attributeYAML, FINAL);
+ if(finalYAML == null)
{
- attributeOM.setNavigable(Boolean.valueOf(String.valueOf(navigableYAML)));
+ ;
}
else
{
- //TODO : charger la valeur par defaut
+ attributeOM.setFinal(Boolean.valueOf(String.valueOf(finalYAML)));
}
- Object orderingYAML = collectElement((List) attributeYAML, "ordering");
- if(orderingYAML != null)
+ Object staticYAML = collectElement((List) attributeYAML, STATIC);
+ if(staticYAML == null)
{
- attributeOM.setOrdering(String.valueOf(orderingYAML));
+ ;
}
else
{
- //TODO : charger la valeur par defaut
+ attributeOM.setStatic(Boolean.valueOf(String.valueOf(staticYAML)));
}
- Object labelYAML = collectElement((List) attributeYAML, "label");
- if(labelYAML != null)
+ Object associationClassNameYAML = collectElement((List) attributeYAML, ASSOCIATION_CLASS_NAME);
+ if(associationClassNameYAML == null)
{
- //TODO : gestion des labels et operations correspondantes
- writeLog("label="+String.valueOf(labelYAML));
+ ;
}
+ else
+ {
+ attributeOM.setAssociationClassName(String.valueOf(associationClassNameYAML));
+ }
- return attributeOM;
- }
- return null;
- }
+ Object reverseAttributeNameYAML = collectElement((List) attributeYAML, REVERSE_ATTRIBUTE_NAME);
+ if(reverseAttributeNameYAML == null)
+ {
+ ;
+ }
+ else
+ {
+ attributeOM.setReverseAttributeName(String.valueOf(reverseAttributeNameYAML));
+ }
- public void loadOperation(Object operationYAML) {
- ;//TODO
- }
+ Object reverseMaxMultiplicityYAML = collectElement((List) attributeYAML, REVERSE_MAX_MULTIPLICITY);
+ if(reverseMaxMultiplicityYAML == null)
+ {
+ ;
+ }
+ else
+ {
+ attributeOM.setReverseMaxMultiplicity(Integer.valueOf(String.valueOf(reverseMaxMultiplicityYAML)));
+ }
- 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())
+
+ Object transientYAML = collectElement((List) attributeYAML, TRANSIENT);
+ if(transientYAML == null)
{
- imports.put(String.valueOf(entry.getKey()),String.valueOf(entry.getValue()));
+ ;
}
- writeLog("imports="+imports);
- }
- }
+ else
+ {
+ attributeOM.setTransient(Boolean.valueOf(String.valueOf(transientYAML)));
+ }
- 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));
- elementOM.addStereotype(ref);
+ Object visibilityYAML = collectElement((List) attributeYAML, VISIBILITY);
+ if(visibilityYAML == null)
+ {
+ ;
}
+ else
+ {
+ attributeOM.setVisibility(String.valueOf(visibilityYAML));
+ }
}
}
- //TODO : pour model
- public void loadComments(List elementYAML, ObjectModelElementImpl elementOM) {
- Object comments = this.collectElement(elementYAML, "comments");
- if (comments instanceof List) {
- for (Object comment : (List) comments) {
- elementOM.addComment(String.valueOf(comment));
+ public void loadOperation(Object operationYAML, ObjectModelOperationImpl operationOM)
+ {
+ if(operationYAML instanceof List)
+ {
+ //TODO: addExceptionParameter
+
+ loadElement(operationYAML, operationOM);
+
+ Object abstractYAML = collectElement((List) operationYAML, ABSTRACT);
+ if(abstractYAML == null)
+ {
+ ;
}
- }
- }
+ else
+ {
+ operationOM.setAbstract(Boolean.valueOf(String.valueOf(abstractYAML)));
+ }
- //TODO : pour model
- 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());
- elementOM.addTagValue(key, value);
+ Object visibilityYAML = collectElement((List) operationYAML, VISIBILITY);
+ if(visibilityYAML == null)
+ {
+ ;
}
- }
- }
+ else
+ {
+ operationOM.setVisibility(String.valueOf(visibilityYAML));
+ }
- 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);
- }
+ Object returnParameterYAML = collectElement((List) operationYAML, RETURN_PARAMETER);
+ if(returnParameterYAML == null)
+ {
+ ;
}
- }
- return null;
- }
+ else
+ {
+ ObjectModelParameterImpl parameterOM = new ObjectModelAttributeImpl();
+ loadParameter(returnParameterYAML, parameterOM);
+ operationOM.setReturnParameter(parameterOM);
+ }
- 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;*/
- }
- }
+ Object bodyCodeYAML = collectElement((List) operationYAML, BODY_CODE);
+ if(bodyCodeYAML == null)
+ {
+ ;
}
- }
- return null;
- }
+ else
+ {
+ operationOM.setBodyCode(String.valueOf(bodyCodeYAML));
+ }
- 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;*/
- }
+ List parametersYAML = collectAllElements((List) operationYAML, PARAMETER);
+ {
+ for(Object parameterYAML : parametersYAML)
+ {
+ ObjectModelParameterImpl parameterOM = new ObjectModelAttributeImpl();
+ loadParameter(parameterYAML, parameterOM);
+ operationOM.addParameter(parameterOM);
}
}
}
- return null;
}
- //collectElements
- 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;
- }
}
1
0
Jenkins build is back to normal : eugene » EUGene :: Java templates #1133
by admin+hudson@codelutin.com 14 May '13
by admin+hudson@codelutin.com 14 May '13
14 May '13
Jenkins build is back to normal : eugene » EUGene :: Maven plugin #1133
by admin+hudson@codelutin.com 14 May '13
by admin+hudson@codelutin.com 14 May '13
14 May '13
Jenkins build is back to normal : eugene » EUGene :: EUGene #1133
by admin+hudson@codelutin.com 14 May '13
by admin+hudson@codelutin.com 14 May '13
14 May '13
14 May '13
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