1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package th.co.edge.jseq.argouml;
24
25 import java.util.LinkedList;
26 import java.util.List;
27
28 import javax.xml.parsers.DocumentBuilder;
29 import javax.xml.parsers.DocumentBuilderFactory;
30 import javax.xml.parsers.ParserConfigurationException;
31
32 import org.w3c.dom.DOMImplementation;
33 import org.w3c.dom.Document;
34 import org.w3c.dom.DocumentType;
35 import org.w3c.dom.Element;
36
37 import ru.novosoft.uml.model_management.MModel;
38
39 import th.co.edge.jseq.Activation;
40 import th.co.edge.jseq.ActivationList;
41 import th.co.edge.jseq.Diagram;
42 import th.co.edge.jseq.argouml.util.MModelUtil;
43
44
45
46
47
48
49 public class ArgoUMLGenerator {
50 private static final String ARGO_PUBLIC_ID = null;
51 private static final String ARGO_SYSTEM_ID = "argo.dtd";
52 private static final String ARGO_NAMESPACE = null;
53 private static final String ARGOUML_VERSION = "0.12";
54
55 private DocumentBuilder builder;
56 private List<SequenceDiagram> sequenceDiagrams =
57 new LinkedList<SequenceDiagram>();
58
59
60
61
62
63
64
65
66 public ArgoUMLGenerator() throws ParserConfigurationException {
67 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
68 this.builder = factory.newDocumentBuilder();
69 }
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 public Diagram generate(ActivationList activationList)
86 throws ParserConfigurationException {
87 MModel model = MModelUtil.createMModel("untitledModel");
88 for (Activation activation : activationList) {
89 SequenceDiagram sequenceDiagram =
90 MModelUtil.addSequenceDiagram(model, activation);
91 sequenceDiagrams.add(sequenceDiagram);
92 }
93 Document argo = createArgoDocument(sequenceDiagrams);
94 return new ArgoUMLDiagram(argo, model, sequenceDiagrams);
95 }
96
97 private Document createArgoDocument(List<SequenceDiagram> diagrams) {
98 DOMImplementation impl = builder.getDOMImplementation();
99 DocumentType docType =
100 impl.createDocumentType("argo", ARGO_PUBLIC_ID, ARGO_SYSTEM_ID);
101 Document doc = impl.createDocument(ARGO_NAMESPACE, "argo", docType);
102 Element root = doc.getDocumentElement();
103 root.appendChild(createDocumentationNode(doc, ARGOUML_VERSION));
104 root.appendChild(createMemberNode(doc, "Untitled.xmi", "xmi"));
105 for (int i = 0; i < diagrams.size(); i++) {
106 String name = "SequenceDiagram" + (i++) + ".pgml";
107 root.appendChild(createMemberNode(doc, name, "pgml"));
108 }
109 return doc;
110 }
111
112 private Element createDocumentationNode(Document doc, String version) {
113 Element documentationNode = doc.createElement("documentation");
114 Element versionNode = doc.createElement("version");
115 documentationNode.appendChild(versionNode);
116 versionNode.appendChild(doc.createTextNode(version));
117 return documentationNode;
118 }
119
120 private Element createMemberNode(Document doc, String name, String type) {
121 Element member = doc.createElement("member");
122 member.setAttribute("type", type);
123 member.setAttribute("name", name);
124 return member;
125 }
126 }