X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fxml%2FMapXmlVisitor.java;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fxml%2FMapXmlVisitor.java;h=564715af665dadf89422ae87b275312424a330b2;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/visitor/xml/MapXmlVisitor.java b/dol/src/dol/visitor/xml/MapXmlVisitor.java new file mode 100644 index 0000000..564715a --- /dev/null +++ b/dol/src/dol/visitor/xml/MapXmlVisitor.java @@ -0,0 +1,193 @@ +/* $Id: MapXmlVisitor.java 1 2010-02-24 13:03:05Z haidw $ */ +package dol.visitor.xml; + +import dol.datamodel.XmlTag; +import dol.datamodel.mapping.CommunicationBinding; +import dol.datamodel.mapping.ComputationBinding; +import dol.datamodel.mapping.Configuration; +import dol.datamodel.mapping.Mapping; +import dol.datamodel.mapping.Schedule; +import dol.datamodel.mapping.ScheduleEntry; +import dol.datamodel.mapping.SchedulingPolicy; +import dol.datamodel.mapping.Variable; +import dol.util.CodePrintString; +import dol.visitor.MapVisitor; + +public class MapXmlVisitor extends MapVisitor { + + /** + * Constructor. + * + * @param stringBuffer buffer where the result is stored + */ + public MapXmlVisitor(StringBuffer stringBuffer) { + _ps = new CodePrintString(stringBuffer); + } + + /** + * + * @param x mapping that needs to be rendered. + */ + public void visitComponent(Mapping x) { + String xmlns = dol.util.SchemaLocation. + getMappingNamespace(); + String xsiLocation = dol.util.SchemaLocation. + getMappingSchemaLocation(); + + _ps.println(""); + _ps.printOpeningTag(_xt.getMappingTag()); + _ps.println(" xmlns=\"" + xmlns + + "\" xmlns:xsi=\"http://www.w3.org/2001/" + + "XMLSchema-instance\"" + + System.getProperty("line.separator") + + " xsi:schemaLocation=\"" + + xmlns + " " + xsiLocation + "\" name=\"" + + x.getName() + "\">"); + + // Visit variables + for(Variable v : x.getVarList()) { + v.accept(this); + } + + // Visit computation bindings + for(ComputationBinding b : x.getCompBindList()) { + b.accept(this); + } + + // Visit communication bindings + for(CommunicationBinding b : x.getCommBindList()) { + b.accept(this); + } + + // Visit schedules + for(Schedule s : x.getScheduleList()) { + s.accept(this); + } + + _ps.printClosingTag(_xt.getMappingTag()); + } + + /** + * + */ + public void visitComponent(ComputationBinding x) { + _ps.printOpeningTag(_xt.getBindingTag()); + _ps.println(" name=\"" + x.getName() + + "\" xsi:type=\"computation\">"); + + // Process + _ps.printPrefix(); + String s = "<" + _xt.getProcessTag() + + " name=\"" + x.getProcess().getName() + "\"/>"; + _ps.println(s); + + // Processor + _ps.printPrefix(); + s = "<" + _xt.getProcessorTag() + + " name=\"" + x.getProcessor().getName() + "\"/>"; + _ps.println(s); + _ps.printClosingTag(_xt.getBindingTag()); + } + + /** + * + */ + public void visitComponent(CommunicationBinding x) { + _ps.printOpeningTag(_xt.getBindingTag()); + _ps.println(" name=\"" + x.getName() + + "\" xsi:type=\"communication\">"); + + // SW channel + _ps.printPrefix(); + String s = "<" + _xt.getSWChannelTag() + + " name=\"" + x.getChannel().getName() + "\"/>"; + _ps.println(s); + + // Write path + _ps.printPrefix(); + s = "<" + _xt.getWritePathTag() + + " name=\"" + x.getWritePath().getName() + "\"/>"; + _ps.println(s); + + // Read path + _ps.printPrefix(); + s = "<" + _xt.getReadPathTag() + + " name=\"" + x.getReadPath().getName() + "\"/>"; + _ps.println(s); + + _ps.printClosingTag(_xt.getBindingTag()); + } + + /** + * + */ + public void visitComponent(Schedule x) { + _ps.printOpeningTag(_xt.getScheduleTag()); + _ps.println(" name=\"" + x.getName() + + "\" type=\"" + + SchedulingPolicy.toString(x.getSchedPolicy()) + "\">"); + + // Resource + _ps.printPrefix(); + String s = "<" + _xt.getResourceTag() + + " name=\"" + x.getResource().getName() + "\"/>"; + _ps.println(s); + + // Scheduler table entries + for (ScheduleEntry p : x.getEntryList()) { + p.accept(this); + } + + // Configuration of schedule + for (Configuration c : x.getCfgList()) { + c.accept(this); + } + + _ps.printClosingTag(_xt.getScheduleTag()); + } + + /** + * + */ + public void visitComponent(ScheduleEntry x) { + if (x.getCfgList().size() == 0) { + _ps.printPrefixln("<" + _xt.getOriginTag() + " name=\"" + + x.getName() + "\"/>"); + } else { + _ps.printOpeningTag(_xt.getOriginTag()); + _ps.println(" name=\"" + x.getName() + "\">"); + + // Configuration of the scheduler entry + for (Configuration c : x.getCfgList()) { + c.accept(this); + } + + _ps.printClosingTag(_xt.getOriginTag()); + } + } + + /** + * + */ + public void visitComponent(Variable x) { + _ps.printPrefix(); + String s = "<" + _xt.getVariableTag() + + " name=\"" + x.getName() + "\"" + + " value=\"" + Integer.toString(x.getValue()) + "\"/>"; + _ps.println(s); + } + + /** + * + */ + public void visitComponent(Configuration x) { + _ps.printPrefix(); + String s = "<" + _xt.getConfigurationTag() + + " name=\"" + x.getName() + "\"" + + " value=\"" + x.getValue() + "\"/>"; + _ps.println(s); + } + + protected CodePrintString _ps = null; + protected XmlTag _xt = XmlTag.getInstance(); +}