Author: agiraudet Date: 2013-04-19 10:15:38 +0200 (Fri, 19 Apr 2013) New Revision: 591 Url: http://nuiton.org/projects/sandbox/repository/revisions/591 Log: affichage des liens de composition dans le diagramme plantuml Modified: testEugeneUML-YAML/testeugene/testgenerator/src/main/java/org/nuiton/testeugene/generator/PlantumlGenerator.java Modified: testEugeneUML-YAML/testeugene/testgenerator/src/main/java/org/nuiton/testeugene/generator/PlantumlGenerator.java =================================================================== --- testEugeneUML-YAML/testeugene/testgenerator/src/main/java/org/nuiton/testeugene/generator/PlantumlGenerator.java 2013-04-18 13:28:56 UTC (rev 590) +++ testEugeneUML-YAML/testeugene/testgenerator/src/main/java/org/nuiton/testeugene/generator/PlantumlGenerator.java 2013-04-19 08:15:38 UTC (rev 591) @@ -4,88 +4,71 @@ import net.sourceforge.plantuml.SourceFileReader; import org.nuiton.eugene.models.object.*; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.io.*; +import java.util.*; // voir org.nuiton.eugene.java.JavaGenerator -// afficher seulement les "entity" +// lien indispensable : http://maven-site.nuiton.org/eugene/objectmodel/ObjectModel_Interfaces.png public class PlantumlGenerator extends ObjectModelGenerator { @Override public void generateFromModel(Writer output, ObjectModel input) throws IOException { - List<String> namesEntity = new LinkedList<String>(); - Map<String,LinkedList<String>> linksEntity = new HashMap<String,LinkedList<String>>(); + /*//log + FileWriter log = new FileWriter(File.separator+"tmp"+File.separator+"PlantumlGenerator.log"); + log.close(); + *///log - // preparation des noms des classes et interfaces pour les liaisons - for(ObjectModelElement OME : input.getClassifiers()) - { - //if(OME.getStereotypes().contains("entity")) - namesEntity.add(OME.getName()); - } - // preparation des noms des enumerations pour les liaisons - for(ObjectModelElement OME : input.getEnumerations()) - { - //if(OME.getStereotypes().contains("")) - namesEntity.add(OME.getName()); - } - // 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 clazz : input.getClasses()) + for(ObjectModelClass class_tmp : input.getClasses()) { - //String classStereotype = clazz.getStereotypes().toString(); - //if(classStereotype.contains("entity")) - String className = clazz.getName(); + String classStereotype = ""; + if(class_tmp.getStereotypes().contains("entity")) + { + classStereotype = " <<entity>>"; + } + String className = class_tmp.getName(); // ajout de la classe - output.write("class "+className+" {\n"); + output.write("class "+className+classStereotype+" {\n"); // parcours des attributs de la classe - for(ObjectModelAttribute attr : clazz.getAttributes()) + for(ObjectModelAttribute attribute_tmp : class_tmp.getAttributes()) { - String attributeName = attr.getName(); - String attributeType = afterLastPoint(attr.getType()); - // ajout d'un lien - if(namesEntity.contains(attributeType)) + 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(linksEntity.containsKey(className)) - { - linksEntity.get(className).add(attributeType); - } - else - { - linksEntity.put(className,new LinkedList<String>()); - linksEntity.get(className).add(attributeType); - } + // ajout du lien + linksOME.put(attribute_tmp,class_tmp); } else { // ajout de l'attribut output.write(" -"+attributeName+" : "+attributeType+"\n"); - //output.write(attr.getVisibility()+"\n");//test } } // parcours des operations - for(ObjectModelOperation oper : clazz.getOperations()) + for(ObjectModelOperation operation_tmp : class_tmp.getOperations()) { - String operationName = oper.getName(); - String operationReturnType = afterLastPoint(oper.getReturnType()); + 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 : oper.getParameters()) + for(ObjectModelParameter param : operation_tmp.getParameters()) { String parameterName = param.getName(); - String parameterType = afterLastPoint(param.getType()); + //String parameterType = afterLastPoint(param.getType()); + String parameterType = param.getType(); if(first) { first = false; @@ -105,31 +88,40 @@ } // parcours des enumerations - for(ObjectModelEnumeration enumer : input.getEnumerations()) + for(ObjectModelEnumeration enumeration_tmp : input.getEnumerations()) { - String enumerationName = enumer.getName(); + String enumerationName = enumeration_tmp.getName(); + String enumerationStereotype = ""; + if(enumeration_tmp.getStereotypes().contains("entity")) + { + enumerationStereotype = " <<entity>>"; + } // ajout de l'enumeration - output.write("enum "+enumerationName+" {\n"); + output.write("enum "+enumerationName+enumerationStereotype+" {\n"); output.write("}\n\n"); } // parcours des interfaces - for(ObjectModelInterface inter : input.getInterfaces()) + for(ObjectModelInterface interface_tmp : input.getInterfaces()) { - String interfaceName = inter.getName(); + String interfaceName = interface_tmp.getName(); + String interfaceStereotype = ""; + if(interface_tmp.getStereotypes().contains("entity")) + { + interfaceStereotype = " <<entity>>"; + } // ajout de l'interface - output.write("interface "+interfaceName+" {\n"); + output.write("interface "+interfaceName+interfaceStereotype+" {\n"); // ajout des methodes output.write("}\n\n"); } //liaisons - //voir isComposite/isAgregate... - for(String keyOME : linksEntity.keySet()) + for(ObjectModelAttribute attribute_tmp : linksOME.keySet()) { - for(String nameOME : linksEntity.get(keyOME)) + if(attribute_tmp.isComposite() && attribute_tmp.referenceClassifier()) { - output.write(keyOME+" -- "+nameOME+"\n"); + output.write(linksOME.get(attribute_tmp).getName()+" *-- "+attribute_tmp.getClassifier().getName()+"\n"); } } @@ -162,8 +154,7 @@ try { File plantuml = new File(destDir+File.separator+this.getFilenameForModel(model)); SourceFileReader reader = new SourceFileReader(plantuml); - List<GeneratedImage> lst = null; - lst = reader.getGeneratedImages(); + List<GeneratedImage> lst = reader.getGeneratedImages(); File diagram = new File(destDir+File.separator+model.getName()+".png"); diagram = lst.get(0).getPngFile(); } catch (InterruptedException e) {