r599 - in testEugeneUML-YAML/testsnakeyaml: . src/main/java src/main/java/model
Author: agiraudet Date: 2013-04-24 17:55:37 +0200 (Wed, 24 Apr 2013) New Revision: 599 Url: http://nuiton.org/projects/sandbox/repository/revisions/599 Log: ajout d'une nouvelle syntaxe uml/yaml : uml4.yaml, plus proche de l'objectmodel Added: testEugeneUML-YAML/testsnakeyaml/src/main/java/model/ testEugeneUML-YAML/testsnakeyaml/src/main/java/model/Model.java testEugeneUML-YAML/testsnakeyaml/src/main/java/model/Uml3.java testEugeneUML-YAML/testsnakeyaml/uml4.yaml Modified: testEugeneUML-YAML/testsnakeyaml/uml3.yaml Added: testEugeneUML-YAML/testsnakeyaml/src/main/java/model/Model.java =================================================================== --- testEugeneUML-YAML/testsnakeyaml/src/main/java/model/Model.java (rev 0) +++ testEugeneUML-YAML/testsnakeyaml/src/main/java/model/Model.java 2013-04-24 15:55:37 UTC (rev 599) @@ -0,0 +1,5 @@ +package model; + +public class Model { + +} Added: testEugeneUML-YAML/testsnakeyaml/src/main/java/model/Uml3.java =================================================================== --- testEugeneUML-YAML/testsnakeyaml/src/main/java/model/Uml3.java (rev 0) +++ testEugeneUML-YAML/testsnakeyaml/src/main/java/model/Uml3.java 2013-04-24 15:55:37 UTC (rev 599) @@ -0,0 +1,223 @@ +package model; + +import org.yaml.snakeyaml.Yaml; + +import java.io.*; +import java.util.*; + +import static parser.Parser.*; + +// classe permettant de parser la syntaxe uml3 +// uml3.yaml -> objectmodel.xml + +// http://cui.unige.ch/java/JAVAF/ +// equivalent dtd ? : http://maven-site.nuiton.org/eugene/xsd/v1/objectmodel.xsd +/* +- classes, interfaces et enumerations : +abstract | public protected private | class interface enumeration | extends implements +- attributs +static | final +- methodes +public protected private | static | final | abstract +*/ +// final not implemented yet + +public class Uml3 { + public static void main(String[] args) throws IOException { + //debut chargement fichier + InputStream input = new FileInputStream(new File("uml3.yaml")); + Yaml yaml = new Yaml(); + Object data = yaml.load(input); + input.close(); + //fin chargement fichier + + //debut ecriture fichier + FileWriter model = new FileWriter("/tmp/test.objectmodel"); + String nameModel = ""; + String versionModel = ""; + model.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<objectModel xmlns=\"http://nuiton.org/eugene/objectModel/v1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://nuiton.org/eugene/objectModel/v1 http://maven-site.nuiton.org/eugene/xsd/v1/objectmodel.xsd\" name=\""+nameModel+"\" version=\""+versionModel+"\">\n"); + + if(data instanceof Map) + { + for(Object e : ((Map) data).entrySet())// les classes et autres + { + if(e instanceof Map.Entry) + { + if (((Map.Entry) e).getKey() instanceof String && ((Map.Entry) e).getValue() instanceof ArrayList) + { + Map<String, Object> tmp = parseClass((String) ((Map.Entry) e).getKey()); + String type = (String) tmp.get("type"); + String name = (String) tmp.get("name"); + + model.write(" <"+type+" name=\""+name+"\" package=\""+"\">\n"); + if(tmp.containsKey("stereotype")) + { + String stereotype = (String) tmp.get("stereotype"); + model.write(" <stereotype name=\""+stereotype+"\"/>\n"); + } + + model.write(" </"+type+">\n"); + } + } + } + } + + //fin ecriture fichier + model.write("\n</objectModel>"); + model.close(); + } + + //OK + public static Map<String, Object> parseClass(String clazz) + { + LinkedList<String> tmp = new LinkedList<String>(spaceParse(clazz)); + Map<String, Object> res = new LinkedHashMap<String, Object>(); + + int index; + //stereotype + if(tmp.contains("<<entity>>")) + { + res.put("stereotype","entity"); + } + //abstraite + if(tmp.contains("abstract")) + { + res.put("abstract",true); + } + //visibilite + if(tmp.contains("public")) + { + res.put("visibility","protected"); + } + else if(tmp.contains("protected")) + { + res.put("visibility", "protected"); + } + else if(tmp.contains("private")) + { + res.put("visibility", "private"); + } + //type + if(tmp.contains("class")) + { + index = tmp.indexOf("class"); + res.put("type","class"); + res.put("name",tmp.get(index+1)); + } + else if(tmp.contains("interface")) + { + index = tmp.indexOf("interface"); + res.put("type","interface"); + res.put("name",tmp.get(index + 1)); + } + else if(tmp.contains("enum"))// ou enumeration ? + { + index = tmp.indexOf("enum"); + res.put("type","enum"); + res.put("name",tmp.get(index+1)); + } + //etend + List<String> extend = new LinkedList<String>(); + while(tmp.contains("extends")) + { + index = tmp.indexOf("extends"); + extend.add(tmp.get(index+1)); + tmp.remove(index); + } + res.put("extends",extend); + //implemente + List<String> implement = new LinkedList<String>(); + while(tmp.contains("implements")) + { + index = tmp.indexOf("implements"); + implement.add(tmp.get(index+1)); + tmp.remove(index); + } + res.put("implements",implement); + + return res; + } + + /*public static void parseClass(ArrayList tab) + { + for(Object obj : tab) + { + if(obj instanceof String) + { + if(((String) obj).contains("(") && ((String) obj).contains(")")) + { + parseOperation((String) obj); + } + else + { + parseAttribute((String) obj); + } + } + } + }*/ + + //PAS OK + /*public static List<PairBean<String, String>> parseOperation(String str) + { + LinkedList<String> tmp = new LinkedList<String>(spaceParse(beforeChar(str,'('))); + LinkedList<PairBean<String, String>> res = new LinkedList<PairBean<String, String>>(); + + //statique + if(tmp.contains("static")) + { + res.add(new PairBean<String, String>("static","static")); + } + //abstraite + if(tmp.contains("abstract")) + { + res.add(new PairBean<String, String>("abstract","abstract")); + } + //visibilite + if(tmp.contains("public")) + { + res.add(new PairBean<String, String>("visibility","public")); + } + else if(tmp.contains("protected")) + { + res.add(new PairBean<String, String>("visibility","protected")); + } + else if(tmp.contains("private")) + { + res.add(new PairBean<String, String>("visibility","private")); + } + + return res; + }*/ + + //OK + public static Map<String, Object> parseAttribute(String str) + { + LinkedList<String> tmp = new LinkedList<String>(spaceParse(str)); + Map<String, Object> res = new LinkedHashMap<String, Object>(); + + //statique + if(tmp.contains("static")) + { + res.put("static",true); + } + //visibilite + if(tmp.contains("public")) + { + res.put("visibility","public"); + } + else if(tmp.contains("protected")) + { + res.put("visibility","protected"); + } + else if(tmp.contains("private")) + { + res.put("visibility","private"); + } + // tenir compte de l'ordre :s + res.put("name",tmp.getLast()); + tmp.removeLast(); + res.put("type",tmp.getLast()); + + return res; + } +} Modified: testEugeneUML-YAML/testsnakeyaml/uml3.yaml =================================================================== --- testEugeneUML-YAML/testsnakeyaml/uml3.yaml 2013-04-24 13:33:57 UTC (rev 598) +++ testEugeneUML-YAML/testsnakeyaml/uml3.yaml 2013-04-24 15:55:37 UTC (rev 599) @@ -1,6 +1,6 @@ %YAML 1.1 --- -# syntaxe uml/yaml version 2 +# syntaxe uml/yaml version 3 # http://yaml.org/ # astuce : utiliser la coloration syntaxique sh/bash Added: testEugeneUML-YAML/testsnakeyaml/uml4.yaml =================================================================== --- testEugeneUML-YAML/testsnakeyaml/uml4.yaml (rev 0) +++ testEugeneUML-YAML/testsnakeyaml/uml4.yaml 2013-04-24 15:55:37 UTC (rev 599) @@ -0,0 +1,60 @@ +%YAML 1.1 +--- +# syntaxe uml/yaml version 4 + +# http://yaml.org/ +# astuce : utiliser la coloration syntaxique sh/bash +# attention a l'indentation ! + +# exemple +# objectif de la syntaxe : proche de l'ObjectModel + +# association bidirectionnelle : c'est le mal +# visibilité optionnelle + +class Classe1 <<entity>>: + - String chaine + - Integer entier + - String toString() + - Integer operation1(String input) +# "nom de l'attribut" "multiplicité" {type de lien} "multiplicité" "classe cible" +# exemple syntaxe modsl: +# 0->1(PollCommentVisibility); +# etudier navigabilité : si lien pas navigable, inutile de referencer l'autre classe (fait lors du traitement) +# types de relations : uni-directionnel, bi-directionnel, composition, agregation +# unidirectionnel + - attribut1 --> 1..3 Classe1 + - attribut1 -> 1..3 Classe1 +# bidirectionnel + - attribut2 --- Classe1 + - attribut2 -- Classe1 +# composition + - attribut3 <*>- + - attribut3 *- + - attribut3 <*>-> + - attribut3 *-> +# agregation + - attribut2 <o>- + - attribut2 o- + - attribut2 <o>-> + - attribut2 o-> + +interface Interface1 <<entity>>: + - Integer entier + - String toString() + +enumeration Enumeration1 <<entity>>: + - Integer entier + - String toString() + +# associationClass ou association +association AssociationClasse1: + - int attribut + - String toString() +# puis les classes cibles + - Classe1 + - Classe2 + - Classe3 + +class Classe2 extends Classe1 implements Interface1 + - . \ No newline at end of file
participants (1)
-
agiraudet@users.nuiton.org