1 /* $Id: PNXmlVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.visitor.xml;
4 import dol.datamodel.XmlTag;
5 import dol.datamodel.pn.Channel;
6 import dol.datamodel.pn.Configuration;
7 import dol.datamodel.pn.Connection;
8 import dol.datamodel.pn.Port;
9 import dol.datamodel.pn.Process;
10 import dol.datamodel.pn.ProcessNetwork;
11 import dol.datamodel.pn.ProfilingConfiguration;
12 import dol.datamodel.pn.SourceCode;
13 import dol.util.CodePrintString;
14 import dol.visitor.PNVisitor;
17 * This is a class for a visitor that is used to generate
18 * a schema compatible XML for process network.
20 public class PNXmlVisitor extends PNVisitor {
25 * @param stringBuffer buffer where the result is stored
27 public PNXmlVisitor(StringBuffer stringBuffer) {
28 _ps = new CodePrintString(stringBuffer);
33 * @param x process network that needs to be rendered.
35 public void visitComponent(ProcessNetwork x) {
36 String xmlns = dol.util.SchemaLocation.
37 getProcessNetworkNamespace();
38 String xsiLocation = dol.util.SchemaLocation.
39 getProcessNetworkSchemaLocation();
42 _ps.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
43 _ps.printOpeningTag(_xt.getPNTag());
44 _ps.println(" xmlns=\"" + xmlns
45 + "\" xmlns:xsi=\"http://www.w3.org/2001/"
46 + "XMLSchema-instance\""
47 + System.getProperty("line.separator")
48 + " xsi:schemaLocation=\""
49 + xmlns + " " + xsiLocation + "\" name=\""
50 + x.getName() + "_annotated" + "\">");
53 for (Process p : x.getProcessList()) {
59 for (Channel c : x.getChannelList()) {
64 //visit all connections
65 for (Connection n : x.getConnectionList()) {
69 _ps.printClosingTag(_xt.getPNTag());
73 * Print a line for the process in the correct format for XML.
75 * @param x process that needs to be rendered
77 public void visitComponent(Process x) {
78 _ps.printOpeningTag(_xt.getProcessTag());
79 _ps.println(" name=\"" + x.getName()
80 + "\" basename=\"" + x.getBasename()
81 + "\" range=\"" + x.getRange()
84 for (Port p : x.getPortList()) {
88 for (SourceCode s : x.getSrcList()) {
92 for (Configuration c : x.getCfgList()) {
96 for (ProfilingConfiguration c : x.getProfilingList()) {
100 _ps.printClosingTag(_xt.getProcessTag());
104 * Print a line for the channel in the correct format for XML.
106 * @param x channel that needs to be rendered
108 public void visitComponent(Channel x) {
109 _ps.printOpeningTag(_xt.getSWChannelTag());
110 _ps.println(" name=\"" + x.getName()
111 + "\" basename=\"" + x.getBasename()
112 + "\" type=\"" + x.getType()
113 + "\" size=\"" + x.getSize()
116 for (Port p : x.getPortList()) {
120 for (Configuration c : x.getCfgList()) {
124 for (ProfilingConfiguration c : x.getProfilingList()) {
128 _ps.printClosingTag(_xt.getSWChannelTag());
132 * Print a line for the connection in the correct format for XML.
134 * @param x channel that needs to be rendered
136 public void visitComponent(Connection x) {
137 _ps.printOpeningTag(_xt.getConnectionTag());
138 _ps.println(" name=\"" + x.getName() + "\">");
141 _ps.printOpeningTag("origin");
142 _ps.println(" name=\"" + x.getOrigin().getName() + "\">");
143 _ps.println(" <port name=\""
144 + x.getOriginPort().getName() + "\"/>");
145 _ps.printClosingTag("origin");
148 _ps.printOpeningTag("target");
149 _ps.println(" name=\"" + x.getTarget().getName() + "\">");
150 _ps.println(" <port name=\""
151 + x.getTargetPort().getName() + "\"/>");
152 _ps.printClosingTag("target");
153 _ps.printClosingTag("connection");
157 * Print a line for the port in the correct format for XML.
159 * @param x port that needs to be rendered
161 public void visitComponent(Port x) {
163 String s = "<" + _xt.getPortTag()
164 + " name=\"" + x.getName()
165 + "\" basename=\"" + x.getBasename()
166 + "\" range=\"" + x.getRange()
168 if (!x.getType().equals(""))
169 s += " type=\"" + x.getType() + "\"";
176 * Print a line for the source code in the correct format for XML.
178 * @param x source that needs to be rendered
180 public void visitComponent(SourceCode x) {
182 _ps.println("<" + _xt.getSourceTag()
183 + " type=\"" + x.getType()
184 + "\" location=\"" + x.getLocality()
189 * Print a line for the configuration in the correct format for XML.
191 * @param x configuration that needs to be rendered
193 public void visitComponent(Configuration x) {
195 _ps.println("<" + _xt.getConfigurationTag()
196 + " name=\"" + x.getName()
197 + "\" value=\"" + x.getValue()
202 * Print a line for the profiling configuration in the correct format for XML.
204 * @param x configuration that needs to be rendered
206 public void visitComponent(ProfilingConfiguration x) {
208 _ps.println("<" + _xt.getProfilingTag()
209 + " name=\"" + x.getName()
210 + "\" value=\"" + x.getValue()
214 protected CodePrintString _ps = null;
216 protected XmlTag _xt = XmlTag.getInstance();