X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fxml%2FPNXmlVisitor.java;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fxml%2FPNXmlVisitor.java;h=19666e0850ef2e3bb93b2b00fbef3aeacd249932;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git
diff --git a/dol/src/dol/visitor/xml/PNXmlVisitor.java b/dol/src/dol/visitor/xml/PNXmlVisitor.java
new file mode 100644
index 0000000..19666e0
--- /dev/null
+++ b/dol/src/dol/visitor/xml/PNXmlVisitor.java
@@ -0,0 +1,217 @@
+/* $Id: PNXmlVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.visitor.xml;
+
+import dol.datamodel.XmlTag;
+import dol.datamodel.pn.Channel;
+import dol.datamodel.pn.Configuration;
+import dol.datamodel.pn.Connection;
+import dol.datamodel.pn.Port;
+import dol.datamodel.pn.Process;
+import dol.datamodel.pn.ProcessNetwork;
+import dol.datamodel.pn.ProfilingConfiguration;
+import dol.datamodel.pn.SourceCode;
+import dol.util.CodePrintString;
+import dol.visitor.PNVisitor;
+
+/**
+ * This is a class for a visitor that is used to generate
+ * a schema compatible XML for process network.
+ */
+public class PNXmlVisitor extends PNVisitor {
+
+ /**
+ * Constructor.
+ *
+ * @param stringBuffer buffer where the result is stored
+ */
+ public PNXmlVisitor(StringBuffer stringBuffer) {
+ _ps = new CodePrintString(stringBuffer);
+ }
+
+ /**
+ *
+ * @param x process network that needs to be rendered.
+ */
+ public void visitComponent(ProcessNetwork x) {
+ String xmlns = dol.util.SchemaLocation.
+ getProcessNetworkNamespace();
+ String xsiLocation = dol.util.SchemaLocation.
+ getProcessNetworkSchemaLocation();
+
+
+ _ps.println("");
+ _ps.printOpeningTag(_xt.getPNTag());
+ _ps.println(" xmlns=\"" + xmlns
+ + "\" xmlns:xsi=\"http://www.w3.org/2001/"
+ + "XMLSchema-instance\""
+ + System.getProperty("line.separator")
+ + " xsi:schemaLocation=\""
+ + xmlns + " " + xsiLocation + "\" name=\""
+ + x.getName() + "_annotated" + "\">");
+
+ //visit all processes
+ for (Process p : x.getProcessList()) {
+ p.accept(this);
+ }
+ _ps.println();
+
+ //visit all channels
+ for (Channel c : x.getChannelList()) {
+ c.accept(this);
+ }
+ _ps.println();
+
+ //visit all connections
+ for (Connection n : x.getConnectionList()) {
+ n.accept(this);
+ }
+
+ _ps.printClosingTag(_xt.getPNTag());
+ }
+
+ /**
+ * Print a line for the process in the correct format for XML.
+ *
+ * @param x process that needs to be rendered
+ */
+ public void visitComponent(Process x) {
+ _ps.printOpeningTag(_xt.getProcessTag());
+ _ps.println(" name=\"" + x.getName()
+ + "\" basename=\"" + x.getBasename()
+ + "\" range=\"" + x.getRange()
+ + "\">");
+
+ for (Port p : x.getPortList()) {
+ p.accept(this);
+ }
+
+ for (SourceCode s : x.getSrcList()) {
+ s.accept(this);
+ }
+
+ for (Configuration c : x.getCfgList()) {
+ c.accept(this);
+ }
+
+ for (ProfilingConfiguration c : x.getProfilingList()) {
+ c.accept(this);
+ }
+
+ _ps.printClosingTag(_xt.getProcessTag());
+ }
+
+ /**
+ * Print a line for the channel in the correct format for XML.
+ *
+ * @param x channel that needs to be rendered
+ */
+ public void visitComponent(Channel x) {
+ _ps.printOpeningTag(_xt.getSWChannelTag());
+ _ps.println(" name=\"" + x.getName()
+ + "\" basename=\"" + x.getBasename()
+ + "\" type=\"" + x.getType()
+ + "\" size=\"" + x.getSize()
+ + "\">");
+
+ for (Port p : x.getPortList()) {
+ p.accept(this);
+ }
+
+ for (Configuration c : x.getCfgList()) {
+ c.accept(this);
+ }
+
+ for (ProfilingConfiguration c : x.getProfilingList()) {
+ c.accept(this);
+ }
+
+ _ps.printClosingTag(_xt.getSWChannelTag());
+ }
+
+ /**
+ * Print a line for the connection in the correct format for XML.
+ *
+ * @param x channel that needs to be rendered
+ */
+ public void visitComponent(Connection x) {
+ _ps.printOpeningTag(_xt.getConnectionTag());
+ _ps.println(" name=\"" + x.getName() + "\">");
+
+ //origin
+ _ps.printOpeningTag("origin");
+ _ps.println(" name=\"" + x.getOrigin().getName() + "\">");
+ _ps.println(" ");
+ _ps.printClosingTag("origin");
+
+ //target
+ _ps.printOpeningTag("target");
+ _ps.println(" name=\"" + x.getTarget().getName() + "\">");
+ _ps.println(" ");
+ _ps.printClosingTag("target");
+ _ps.printClosingTag("connection");
+ }
+
+ /**
+ * Print a line for the port in the correct format for XML.
+ *
+ * @param x port that needs to be rendered
+ */
+ public void visitComponent(Port x) {
+ _ps.printPrefix();
+ String s = "<" + _xt.getPortTag()
+ + " name=\"" + x.getName()
+ + "\" basename=\"" + x.getBasename()
+ + "\" range=\"" + x.getRange()
+ + "\"";
+ if (!x.getType().equals(""))
+ s += " type=\"" + x.getType() + "\"";
+ s += " />";
+
+ _ps.println(s);
+ }
+
+ /**
+ * Print a line for the source code in the correct format for XML.
+ *
+ * @param x source that needs to be rendered
+ */
+ public void visitComponent(SourceCode x) {
+ _ps.printPrefix();
+ _ps.println("<" + _xt.getSourceTag()
+ + " type=\"" + x.getType()
+ + "\" location=\"" + x.getLocality()
+ + "\" />");
+ }
+
+ /**
+ * Print a line for the configuration in the correct format for XML.
+ *
+ * @param x configuration that needs to be rendered
+ */
+ public void visitComponent(Configuration x) {
+ _ps.printPrefix();
+ _ps.println("<" + _xt.getConfigurationTag()
+ + " name=\"" + x.getName()
+ + "\" value=\"" + x.getValue()
+ + "\" />");
+ }
+
+ /**
+ * Print a line for the profiling configuration in the correct format for XML.
+ *
+ * @param x configuration that needs to be rendered
+ */
+ public void visitComponent(ProfilingConfiguration x) {
+ _ps.printPrefix();
+ _ps.println("<" + _xt.getProfilingTag()
+ + " name=\"" + x.getName()
+ + "\" value=\"" + x.getValue()
+ + "\" />");
+ }
+
+ protected CodePrintString _ps = null;
+
+ protected XmlTag _xt = XmlTag.getInstance();
+}