Author: agiraudet Date: 2013-06-07 17:58:50 +0200 (Fri, 07 Jun 2013) New Revision: 1268 Url: http://nuiton.org/projects/eugene/repository/revisions/1268 Log: am?\195?\169lioration du parser de la syntaxe "user friendly" () am?\195?\169lioration du template PlantUML Modified: trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/PlantumlTemplatesGenerator.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/KeyWords.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/Parser.java Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/KeyWords.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/KeyWords.java 2013-06-07 09:30:56 UTC (rev 1267) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/KeyWords.java 2013-06-07 15:58:50 UTC (rev 1268) @@ -49,6 +49,7 @@ public static final String TRANSIENT = "transient"; public static final String TYPE = "type"; public static final String UNIQUE = "unique"; + public static final String UNORDERED = "unordered"; public static final String VERSION = "version"; public static final String VISIBILITY = "visibility"; public static final String ELEMENT = "element"; Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/Parser.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/Parser.java 2013-06-07 09:30:56 UTC (rev 1267) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/Parser.java 2013-06-07 15:58:50 UTC (rev 1268) @@ -359,11 +359,131 @@ // public void parseAssociationClass(String key, Object value, YamlObject associationClassYAMLO)//declarer participant attribut ? { - parseClass(key,value,associationClassYAMLO);//non fonctionnel (remplacer CLASS par ASSOCIATION_CLASS) + // - //degolass' + /* + FACTORISER LE CODE ! + */ + List<String> classPARSE = YamlUtil.charParseIgnore(key,' ','<','>'); + if(classPARSE.contains(ASSOCIATION_CLASS)) + { + classPARSE.remove(classPARSE.indexOf(ASSOCIATION_CLASS)); + } + if(classPARSE.contains(ABSTRACT)) + { + associationClassYAMLO.addStringToMap(ABSTRACT, String.valueOf(true)); + classPARSE.remove(classPARSE.indexOf(ABSTRACT)); + } + if(classPARSE.contains(STATIC)) + { + associationClassYAMLO.addStringToMap(STATIC, String.valueOf(true)); + classPARSE.remove(classPARSE.indexOf(STATIC)); + } + if(classPARSE.contains(EXTERN)) + { + associationClassYAMLO.addStringToMap(EXTERN, String.valueOf(true)); + classPARSE.remove(classPARSE.indexOf(EXTERN)); + } + if(classPARSE.contains(INNER)) + { + associationClassYAMLO.addStringToMap(INNER, String.valueOf(true)); + classPARSE.remove(classPARSE.indexOf(INNER)); + } + if(classPARSE.contains(PUBLIC)) + { + associationClassYAMLO.addStringToMap(VISIBILITY, PUBLIC); + classPARSE.remove(classPARSE.indexOf(PUBLIC)); + } + else if(classPARSE.contains(PRIVATE)) + { + associationClassYAMLO.addStringToMap(VISIBILITY, PRIVATE); + classPARSE.remove(classPARSE.indexOf(PRIVATE)); + } + else if(classPARSE.contains(PROTECTED)) + { + associationClassYAMLO.addStringToMap(VISIBILITY, PROTECTED); + classPARSE.remove(classPARSE.indexOf(PROTECTED)); + } + + for(String tmp1 : classPARSE) + { + if(tmp1.contains("<<") && tmp1.contains(">>")) + { + List<Character> targets = new LinkedList<Character>(); + targets.add('<'); + targets.add('>'); + String tmp2 = YamlUtil.removeMultiChar(tmp1, targets); + targets = new LinkedList<Character>(); + targets.add(' '); + targets.add(','); + List<String> tmp3 = YamlUtil.multiCharParse(tmp2, targets); + for(String tmp4 : tmp3) + { + associationClassYAMLO.addStringToMap(STEREOTYPES, tmp4); + log("stereotype="+tmp4); + } + } + } + if(classPARSE.size() > 0)//prend compte de l'ordre : nom avant stereotypes + { + associationClassYAMLO.addStringToMap(NAME, classPARSE.get(0)); + log("name="+classPARSE.get(0)); + } + if(value instanceof Map) { + for(Object entry : ((Map) value).entrySet()) + { + if(entry instanceof Map.Entry) + { + String keyP = String.valueOf(((Map.Entry) entry).getKey()); + Object valueP = ((Map.Entry) entry).getValue(); + + if(keyP.equals(SUPER_CLASSES)) + { + if(valueP instanceof List) + { + for(Object superClass : (List) valueP) + { + //TODO: superClasses sur une ligne + associationClassYAMLO.addStringToMap(SUPER_CLASSES, String.valueOf(superClass)); + } + } + } + else if(keyP.equals(SUPER_INTERFACES)) + { + if(valueP instanceof List) + { + for(Object superInterface : (List) valueP) + { + //TODO: superInterfaces sur une ligne + associationClassYAMLO.addStringToMap(SUPER_INTERFACES, String.valueOf(superInterface)); + } + } + } + else + { + if(keyP.contains("(") && keyP.contains(")")) + { + YamlObject operationYAMLO = new YamlObject(); + parseOperation(keyP,valueP,operationYAMLO); + associationClassYAMLO.addYamlObjectToMap(OPERATION, operationYAMLO); + } + else + { + YamlObject attributeYAMLO = new YamlObject(); + parseAttribute(keyP,valueP,attributeYAMLO); + associationClassYAMLO.addYamlObjectToMap(ATTRIBUTE, attributeYAMLO); + } + } + } + } + } + /* + FACTORISER LE CODE ! + */ + if(value instanceof Map) + { if(((Map) value).containsKey(PARTICIPANT)) { if(((Map) value).get(PARTICIPANT) instanceof Map) @@ -372,14 +492,36 @@ { if(entry instanceof Map.Entry) { - //name: attribute + //name attribute "value": + + List<String> participantPARSE = YamlUtil.charParse(String.valueOf(((Map.Entry) entry).getKey()),' '); YamlObject participantYAMLO = new YamlObject(); + if(participantPARSE.contains("\""+YamlUtil.extract('"',String.valueOf(((Map.Entry) entry).getKey()))+"\"")) + { + String label = YamlUtil.extract('"',String.valueOf(((Map.Entry) entry).getKey())); + + participantYAMLO.addStringToMap(LABEL,label); + + participantPARSE.remove("\""+YamlUtil.extract('"',String.valueOf(((Map.Entry) entry).getKey()))+"\""); + } + + if(participantPARSE.size() > 0)//ajout type + { + participantYAMLO.addStringToMap(NAME,participantPARSE.get(0)); + } + if(participantPARSE.size() > 1)//ajout name + { + participantYAMLO.addStringToMap(ATTRIBUTE,participantPARSE.get(1)); + } + associationClassYAMLO.addYamlObjectToMap(PARTICIPANT,participantYAMLO); + + /*YamlObject participantYAMLO = new YamlObject(); participantYAMLO.addStringToMap(NAME, String.valueOf(((Map.Entry) entry).getKey())); if(((Map.Entry) entry).getValue() != null) { participantYAMLO.addStringToMap(ATTRIBUTE,String.valueOf(((Map.Entry) entry).getValue())); } - associationClassYAMLO.addYamlObjectToMap(PARTICIPANT,participantYAMLO); + associationClassYAMLO.addYamlObjectToMap(PARTICIPANT,participantYAMLO);*/ } } } @@ -482,8 +624,53 @@ attributePARSE.remove(attributePARSE.indexOf(PUBLIC)); } - for(String tmp1 : attributePARSE) + if(attributePARSE.contains(ORDERED)) { + attributeYAMLO.addStringToMap(ORDERING,ORDERED); + attributePARSE.remove(attributePARSE.indexOf(ORDERED)); + } + else if(attributePARSE.contains(UNORDERED)) + { + attributeYAMLO.addStringToMap(ORDERING,UNORDERED); + attributePARSE.remove(attributePARSE.indexOf(UNORDERED)); + } + + if(attributePARSE.contains("\""+YamlUtil.extract('"',key)+"\"")) + { + String label = YamlUtil.extract('"',key); + attributeYAMLO.addStringToMap(LABEL,label); + attributePARSE.remove("\""+YamlUtil.extract('"',key)+"\""); + } + + if(attributePARSE.contains("["+YamlUtil.extract('[',']',key)+"]")) + { + String multiplicity = YamlUtil.extract('[',']',key); + if(multiplicity.equals("*")) + { + attributeYAMLO.addStringToMap(MIN_MULTIPLICITY,"0"); + attributeYAMLO.addStringToMap(MAX_MULTIPLICITY,"-1"); + } + else if(multiplicity.contains("..")) + { + String min = YamlUtil.beforeChar(multiplicity,'.'); + String max = YamlUtil.afterChar(multiplicity, '.'); + if(min.equals("*")) + { + min = "-1"; + } + if(max.equals("*")) + { + max = "-1"; + } + attributeYAMLO.addStringToMap(MIN_MULTIPLICITY,min); + attributeYAMLO.addStringToMap(MAX_MULTIPLICITY,max); + } + attributePARSE.remove("["+YamlUtil.extract('[',']',key)+"]"); + } + + //extraire directement car pas de suppression + /*for(String tmp1 : attributePARSE) + { log("tmp1="+tmp1); if(tmp1.contains("\""))//tester deux occurrences ?//remplacer label par reverseMultiplicity si lien unidirectionnel { @@ -517,29 +704,29 @@ } //attributePARSE.remove(tmp1); } - } - + }*/ + //name: type ? if(attributePARSE.size() > 0)//ajout type { attributeYAMLO.addStringToMap(TYPE,attributePARSE.get(0)); } - /*if(attributePARSE.size() > 1)//ajout name + if(attributePARSE.size() > 1)//ajout name { attributeYAMLO.addStringToMap(NAME,attributePARSE.get(1)); - }*/ + } - if(value != null) + /*if(value != null)//defaultValue { //attributeYAMLO.addStringToMap(DEFAULT_VALUE,String.valueOf(value)); - attributeYAMLO.addStringToMap(NAME,String.valueOf(value)); - } + attributeYAMLO.addStringToMap(TYPE,String.valueOf(value)); + }*/ //on parcours le reste on recherche les [] (multiplicity) et les "" (label) } //OK, fonctionnel : yeah ninja flex - //TODO: return Parameter après les : (value) ? + //TODO: return Parameter après les : (value) ? name: value public void parseOperation(String key, Object value, YamlObject operationYAMLO) { log("operation=" + key); @@ -576,31 +763,40 @@ operationYAMLO.addStringToMap(VISIBILITY,PRIVATE); operationPARSE.remove(operationPARSE.indexOf(PRIVATE)); } - if(operationPARSE.size() > 1) + + for(String tmp : operationPARSE) { - YamlObject returnParameterYAMLO = new YamlObject(); - returnParameterYAMLO.addStringToMap(TYPE,operationPARSE.get(0)); - operationYAMLO.addYamlObjectToMap(RETURN_PARAMETER,returnParameterYAMLO); - - for(String tmp : operationPARSE) + if(tmp.contains("(") && tmp.contains(")")) { - if(tmp.contains("(") && tmp.contains(")")) + operationYAMLO.addStringToMap(NAME,YamlUtil.beforeChar(tmp,'(')); + for(String tmp1 : YamlUtil.charParseIgnore(YamlUtil.extract('(', ')', tmp), ',', '<', '>')) { - operationYAMLO.addStringToMap(NAME,YamlUtil.beforeChar(tmp,'(')); - for(String tmp1 : YamlUtil.charParseIgnore(YamlUtil.extract('(', ')', tmp), ',', '<', '>')) + List<String> tmp2 = YamlUtil.charParse(tmp1,' '); + if(tmp2.size() == 2) { - List<String> tmp2 = YamlUtil.charParse(tmp1,' '); - if(tmp2.size() == 2) - { - YamlObject parameterYAMLO = new YamlObject(); - parameterYAMLO.addStringToMap(TYPE, tmp2.get(0)); - parameterYAMLO.addStringToMap(NAME, tmp2.get(1)); - operationYAMLO.addYamlObjectToMap(PARAMETER, parameterYAMLO); - } + YamlObject parameterYAMLO = new YamlObject(); + parameterYAMLO.addStringToMap(TYPE, tmp2.get(0)); + parameterYAMLO.addStringToMap(NAME, tmp2.get(1)); + operationYAMLO.addYamlObjectToMap(PARAMETER, parameterYAMLO); } } + //operationPARSE.remove(tmp); } } + + /*if(operationPARSE.size() > 1) + { + YamlObject returnParameterYAMLO = new YamlObject(); + returnParameterYAMLO.addStringToMap(TYPE,operationPARSE.get(0)); + operationYAMLO.addYamlObjectToMap(RETURN_PARAMETER,returnParameterYAMLO); + }*/ + + if(value != null) + { + YamlObject returnParameterYAMLO = new YamlObject(); + returnParameterYAMLO.addStringToMap(TYPE,String.valueOf(value)); + operationYAMLO.addYamlObjectToMap(RETURN_PARAMETER,returnParameterYAMLO); + } } public static void resolveImports(YamlObject modelYAMLO) @@ -725,9 +921,18 @@ } } } - if(importable.containsKeyMapStringListString(PARTICIPANT)) + if(importable.containsKeyYamlMapStringListYamlObject(PARTICIPANT)) { - ;//TODO + log("0"); + for(YamlObject participantYAMLO : importable.getMapStringListYamlObject(PARTICIPANT)) + { + log("1"); + if(participantYAMLO.containsKeyMapStringListString(NAME)) + { + log("2"); + participantYAMLO.setMapStringListString(NAME,participantYAMLO.getFirstMapStringListString(NAME),resolveType(participantYAMLO.getFirstMapStringListString(NAME),imports)); + } + } } } } @@ -736,7 +941,6 @@ //OK public static String browseType(String type, Map<String,String> imports) { - //List<Map<String,List<Integer>>> StringBuilder res = new StringBuilder(); boolean first = true; for(String tmp : YamlUtil.charParseIgnore(type,',','<','>')) @@ -793,7 +997,7 @@ //recuperer toyus les attributs dans une seule liste au lieu d'aller les chercher a chaque fois public static void resolveLabels(YamlObject modelYAMLO)//reverseAttribute + Labels { - //test + //test variable global Map<String,String> imports = new LinkedHashMap<String, String>(); String packageM = null; if(modelYAMLO.containsKeyMapStringListString(PACKAGE)) @@ -894,17 +1098,14 @@ attribute.addStringToMap(REVERSE_ATTRIBUTE_NAME,reverseAttribute.getFirstMapStringListString(NAME)); } } - //methode getReverseAttribute(mode,type,label) - //recuperer le reverse attribute - //TODO - //modelYAMLO.getFirstMapStringListYamlObject(YamlUtil.afterChar(type,'.')).get - //for() } else//unidirectionnel { + log("unidirectionnel"); YamlObject reverseObject = getReverseObject(modelYAMLO,YamlUtil.afterChar(type,'.')); if(reverseObject != null) { + log("reverseObject != null"); YamlObject reverseAttribute = new YamlObject(); reverseAttribute.addStringToMap(NAVIGABLE,String.valueOf(false)); reverseAttribute.addStringToMap(TYPE,imports.get(labelisable.getFirstMapStringListString(NAME))); @@ -916,6 +1117,13 @@ { reverseAttribute.addStringToMap(REVERSE_ATTRIBUTE_NAME,attribute.getFirstMapStringListString(NAME)); } + if(attribute.containsKeyMapStringListString(ORDERING)) + { + reverseAttribute.addStringToMap(ORDERING,attribute.getFirstMapStringListString(ORDERING)); + } + reverseObject.addYamlObjectToMap(ATTRIBUTE,reverseAttribute); + + attribute.addStringToMap(NAVIGABLE,String.valueOf(true)); } } } @@ -930,6 +1138,37 @@ } } } + if(labelisable.containsKeyYamlMapStringListYamlObject(PARTICIPANT)) + { + log("0"); + for(YamlObject participant : labelisable.getMapStringListYamlObject(PARTICIPANT)) + { + if(participant.containsKeyMapStringListString(NAME)) + { + log("1"); + String name = participant.getFirstMapStringListString(NAME); + if(importsI.contains(name))//refClassifier + { + log("2"); + if(participant.containsKeyMapStringListString(LABEL)) + { + log("3"); + String label = participant.getFirstMapStringListString(LABEL); + YamlObject reverseAttribute = getReverseAttribute(modelYAMLO,YamlUtil.afterChar(name,'.'),label); + if(reverseAttribute != null) + { + log("4"); + if(labelisable.containsKeyMapStringListString(NAME)) + { + log("5"); + reverseAttribute.addStringToMap(ASSOCIATION_CLASS_NAME,labelisable.getFirstMapStringListString(NAME)); + } + } + } + } + } + } + } } } } @@ -992,7 +1231,7 @@ imports.put("Map","java.util.Map"); String type = "Map<List<String>,List<String>>"; System.out.println(resolveType(type,imports));*/ - List<String> test = new LinkedList<String>(); + /*List<String> test = new LinkedList<String>(); test.add("test1"); test.add("test2"); test.add("\"test3\""); @@ -1000,6 +1239,6 @@ for(String str : test) { System.out.println(str); - } + }*/ } } 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-06-07 09:30:56 UTC (rev 1267) +++ trunk/eugene-plantuml-templates/src/main/java/org/nuiton/eugene/plantuml/PlantumlTemplatesGenerator.java 2013-06-07 15:58:50 UTC (rev 1268) @@ -1,65 +1,24 @@ package org.nuiton.eugene.plantuml; -/* - * #%L - * EUGene :: PlantUML templates - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - import net.sourceforge.plantuml.GeneratedImage; import net.sourceforge.plantuml.SourceFileReader; -import org.nuiton.eugene.models.object.ObjectModel; -import org.nuiton.eugene.models.object.ObjectModelAttribute; -import org.nuiton.eugene.models.object.ObjectModelClass; -import org.nuiton.eugene.models.object.ObjectModelClassifier; -import org.nuiton.eugene.models.object.ObjectModelEnumeration; -import org.nuiton.eugene.models.object.ObjectModelGenerator; -import org.nuiton.eugene.models.object.ObjectModelInterface; -import org.nuiton.eugene.models.object.ObjectModelOperation; -import org.nuiton.eugene.models.object.ObjectModelParameter; +import org.nuiton.eugene.models.object.*; +import org.nuiton.eugene.models.object.xml.ObjectModelAssociationClassImpl; +import org.nuiton.eugene.models.object.xml.ObjectModelClassImpl; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.io.*; +import java.util.*; -/** - * TODO - * - * @author agiraudet - * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.plantuml.PlantumlTemplatesGenerator" - * @since 2.6.3 - */ +// http://maven-site.nuiton.org/eugene/objectmodel/ObjectModel_Interfaces.png +//TODO : Plexus ? + public class PlantumlTemplatesGenerator extends ObjectModelGenerator { private boolean _loginit = true; - private void log(String str) { try { FileWriter log; - String path = "/tmp/log.yaml.txt"; + String path = "/tmp/log.plantuml.txt"; if (_loginit) { log = new FileWriter(path, false); @@ -69,9 +28,7 @@ log = new FileWriter(path, true); log.write("[LOG] " + str + "\n"); log.close(); - } catch (IOException e) { - ; - } + } catch (IOException e) {;} } @Override @@ -81,167 +38,263 @@ // utiliser le systeme de templates a l'avenir - Map<ObjectModelAttribute, ObjectModelClassifier> linksOME = new LinkedHashMap<ObjectModelAttribute, ObjectModelClassifier>(); + 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 + for(ObjectModelClass class_tmp : input.getClasses()) + { String classStereotype = ""; - if (class_tmp.getStereotypes().size() > 0) { + if(class_tmp.getStereotypes().size()>0) + { classStereotype = "<<"; boolean first = true; - for (String str : class_tmp.getStereotypes()) { - if (first) { - classStereotype = classStereotype + str; + for(String str : class_tmp.getStereotypes()) + { + if(first) + { + classStereotype = classStereotype+str; first = false; - } else { - classStereotype = classStereotype + " ," + str; } + else + { + classStereotype = classStereotype+" ,"+str; + } } - classStereotype = classStereotype + ">>"; + 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"); + output.write("class "+className+classStereotype+" {\n"); // parcours des attributs de la classe - for (ObjectModelAttribute attribute_tmp : class_tmp.getAttributes()) { + 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()) { + if(attribute_tmp.referenceClassifier()) + { // ajout du lien - linksOME.put(attribute_tmp, class_tmp); - } else { + linksOME.put(attribute_tmp,class_tmp); + } + else + { // ajout de l'attribut - output.write(" -" + attributeName + " : " + attributeType + "\n"); + output.write(" -"+attributeName+" : "+attributeType+"\n"); } } // parcours des operations - for (ObjectModelOperation operation_tmp : class_tmp.getOperations()) { + 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 + "("); + output.write(" +"+operationName+"("); // parcours des parametres boolean first = true; - for (ObjectModelParameter param : operation_tmp.getParameters()) { + for(ObjectModelParameter param : operation_tmp.getParameters()) + { String parameterName = param.getName(); //String parameterType = afterLastPoint(param.getType()); String parameterType = param.getType(); - if (first) { + if(first) + { first = false; - } else { + } + else + { output.write(", "); } // ajout du parametre - output.write(parameterName + " : " + parameterType); + output.write(parameterName+" : "+parameterType); } // ajout du type de retour - output.write(") : " + operationReturnType + "\n");// attention aux listes ! + output.write(") : "+operationReturnType+"\n");// attention aux listes ! } output.write("}\n\n"); } // parcours des enumerations - for (ObjectModelEnumeration enumeration_tmp : input.getEnumerations()) { + for(ObjectModelEnumeration enumeration_tmp : input.getEnumerations()) + { String enumerationName = enumeration_tmp.getName(); String enumerationStereotype = ""; - if (enumeration_tmp.getStereotypes().contains("entity")) { - enumerationStereotype = " <<entity>>"; + if(enumeration_tmp.getStereotypes().size()>0) + { + enumerationStereotype = "<<"; + boolean first = true; + for(String str : enumeration_tmp.getStereotypes()) + { + if(first) + { + enumerationStereotype = enumerationStereotype+str; + first = false; + } + else + { + enumerationStereotype = enumerationStereotype+" ,"+str; + } + } + enumerationStereotype = enumerationStereotype+">>"; } // ajout de l'enumeration - output.write("enum " + enumerationName + enumerationStereotype + " {\n"); + output.write("enum "+enumerationName+enumerationStereotype+" {\n"); + for(String literalOM : enumeration_tmp.getLiterals()) + { + output.write(" "+literalOM.toUpperCase()+"\n"); + } output.write("}\n\n"); } // parcours des interfaces - for (ObjectModelInterface interface_tmp : input.getInterfaces()) { + for(ObjectModelInterface interface_tmp : input.getInterfaces()) + { String interfaceName = interface_tmp.getName(); String interfaceStereotype = ""; - if (interface_tmp.getStereotypes().contains("entity")) { - interfaceStereotype = " <<entity>>"; + if(interface_tmp.getStereotypes().size()>0) + { + interfaceStereotype = "<<"; + boolean first = true; + for(String str : interface_tmp.getStereotypes()) + { + if(first) + { + interfaceStereotype = interfaceStereotype+str; + first = false; + } + else + { + interfaceStereotype = interfaceStereotype+" ,"+str; + } + } + interfaceStereotype = interfaceStereotype+">>"; } // ajout de l'interface - output.write("interface " + interfaceName + interfaceStereotype + " {\n"); + 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 + for(ObjectModelAttribute attribute_tmp : linksOME.keySet()) + { + //if(attribute_tmp.isNavigable()) { - 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 + 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"); + } + } + } + + /*//test + for(ObjectModelClassifier class_tmp : input.getClassifiers()) + { + log("name="+class_tmp.getName()); + for(ObjectModelDependency dependency : class_tmp.getDependencies()) { - 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"); + log("dependency="+dependency.getName()+" client="+ dependency.getClient().getName()+" supplier="+dependency.getSupplier().getName()); } + if(class_tmp.getDeclaringElement() != null) + { + log("declaringElement="+class_tmp.getDeclaringElement().getName()); + } } + *///test //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()) { + 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)) { + if(associationClass.containsKey(key)) + { associationClass.get(key).add(value); - } else { - associationClass.put(key, new LinkedList<String>()); + } + else + { + associationClass.put(key,new LinkedList<String>()); associationClass.get(key).add(value); } } } } - for (Map.Entry<String, LinkedList<String>> entry : associationClass.entrySet()) { + for(Map.Entry<String,LinkedList<String>> entry : associationClass.entrySet()) + { boolean first = true; output.write("("); - for (String value : entry.getValue()) { - if (first) { + for(String value : entry.getValue()) + { + if(first) + { output.write(value); first = false; - } else { - output.write(", " + value); + }else + { + output.write(", "+value); } } - output.write(") .. " + entry.getKey() + "\n"); + output.write(") .. "+entry.getKey()+"\n"); } //extensions/generalisations (heritage) - for (ObjectModelClass classOM : input.getClasses()) { - for (ObjectModelClass superClassOM : classOM.getSuperclasses()) { - output.write(superClassOM.getName() + " <|-- " + classOM.getName()); + for(ObjectModelClass classOM : input.getClasses()) + { + for(ObjectModelClass superClassOM : classOM.getSuperclasses()) + { + output.write(superClassOM.getName()+" <|-- "+classOM.getName()+"\n"); } } + //realisations + for(ObjectModelClass classOM : input.getClasses()) + { + for(ObjectModelInterface superInterfaceOM : classOM.getInterfaces()) + { + output.write(superInterfaceOM.getName()+" <|.. "+classOM.getName()+"\n"); + } + } + // fin du fichier output.write("\n@enduml"); } // exemple : afterLastPoint("org.nuiton.testeugene.generator") return "generator" - public static String afterLastPoint(String input) { + public static String afterLastPoint(String input) + { String str = new StringBuffer(input).reverse().toString(); String res = ""; - for (Character car : str.toCharArray()) { - if (car.equals('.')) { + for(Character car : str.toCharArray()) + { + if(car.equals('.')) + { return res; - } else { - res = car.toString() + res; } + else + { + res = car.toString()+res; + } } return res; } @@ -250,10 +303,10 @@ public void applyTemplate(ObjectModel model, File destDir) throws IOException { super.applyTemplate(model, destDir); try { - File plantuml = new File(destDir + File.separator + this.getFilenameForModel(model)); + File plantuml = new File(destDir+File.separator+this.getFilenameForModel(model)); SourceFileReader reader = new SourceFileReader(plantuml); List<GeneratedImage> lst = reader.getGeneratedImages(); - new File(lst.get(0).getPngFile(), destDir + File.separator + model.getName() + ".png"); + new File(lst.get(0).getPngFile(), destDir+File.separator+model.getName()+".png"); } catch (InterruptedException e) { e.printStackTrace(); } @@ -261,6 +314,6 @@ @Override public String getFilenameForModel(ObjectModel model) { - return model.getName() + ".plantuml"; + return model.getName()+".plantuml"; } }