1 /* $Id: PNXmlParser.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.parser.xml.pnschema;
4 import java.util.Stack;
6 import org.xml.sax.Attributes;
7 import org.xml.sax.InputSource;
8 import org.xml.sax.SAXException;
9 import org.xml.sax.SAXParseException;
11 import dol.datamodel.XmlTag;
12 import dol.datamodel.pn.ProcessNetwork;
13 import dol.parser.xml.XmlParser;
16 * Parse processnetwork XML file.
18 public class PNXmlParser extends XmlParser {
23 public PNXmlParser() {
25 _stack = new Stack<Object>();
26 _xml2PN = new Xml2PN();
30 * Do the parsing of an XML file describing a processnetwork.
32 * @param url input XML file
33 * @return the processnetwork
35 public ProcessNetwork doParse(String url) {
36 ProcessNetwork pn = null;
37 System.out.println("Read process network from XML file");
40 String uri = _makeAbsoluteURL(url);
41 _ui.printlnVerbose("-- processing XML file: " + uri);
42 _ui.printlnVerbose("-- read XML file: ");
44 _parser.parse(new InputSource(uri));
45 pn = (ProcessNetwork) _stack.pop();
46 _ui.printlnVerbose(" [DONE] ");
47 } catch (SAXParseException err) {
48 System.out.println("** Parsing error, line "
49 + err.getLineNumber() + ", uri " + err.getSystemId());
50 System.out.println(" " + err.getMessage());
51 } catch (SAXException e) {
53 } catch (Throwable t) {
58 pn.fillPortPeerInfo();
59 } catch (Exception e) {
60 System.out.println("Exception\n " + e.getMessage());
61 e.printStackTrace(System.out);
64 System.out.println(" -- Process network model from XML "
72 * Action to be done while parsing a start element of an XML.
76 * @param elementName name of element
77 * @param attributes attributes of element
78 * @exception SAXException thrown when a parsing error occurs
80 public void startElement(String namespaceURI, String localName,
81 String elementName, Attributes attributes)
85 if (elementName.equals(_xt.getPNTag())) {
86 val = _xml2PN.processPN(attributes);
87 } else if (elementName.equals(_xt.getVariableTag())) {
88 val = _xml2PN.processVariable(attributes);
89 } else if (elementName.equals(_xt.getProcessTag())) {
90 val = _xml2PN.processProcess(attributes);
91 } else if (elementName.equals(_xt.getSWChannelTag())) {
92 val = _xml2PN.processChannel(attributes);
93 } else if (elementName.equals(_xt.getConnectionTag())) {
94 val = _xml2PN.processConnection(attributes);
95 } else if (elementName.equals(_xt.getOriginTag())) {
96 val = _xml2PN.processOrigin(attributes);
97 } else if (elementName.equals(_xt.getTargetTag())) {
98 val = _xml2PN.processTarget(attributes);
99 } else if (elementName.equals(_xt.getPortTag())) {
100 val = _xml2PN.processPort(attributes);
101 } else if (elementName.equals(_xt.getSourceTag())) {
102 val = _xml2PN.processSource(attributes);
103 } else if (elementName.equals(_xt.getProfilingTag())) {
104 val = _xml2PN.processProfiling(attributes);
105 } else if (elementName.equals(_xt.getConfigurationTag())) {
106 val = _xml2PN.processConfiguration(attributes);
108 System.out.println("--Warning, DOL doesn't "
109 + "understand tag <" + elementName + "> ");
118 * Action to be done while parsing an end element of an XML.
120 * @param elementName Description of the Parameter
121 * @exception SAXException MyException If such and such occurs
123 public void endElement(String namespaceURI, String localName,
124 String elementName) throws SAXException {
125 if (elementName.equals(_xt.getPNTag())) {
126 _xml2PN.processPN(_stack);
127 } else if (elementName.equals(_xt.getVariableTag())) {
128 _xml2PN.processVariable(_stack);
129 } else if (elementName.equals(_xt.getProcessTag())) {
130 _xml2PN.processProcess(_stack);
131 } else if (elementName.equals(_xt.getSWChannelTag())) {
132 _xml2PN.processChannel(_stack);
133 } else if (elementName.equals(_xt.getConnectionTag())) {
134 _xml2PN.processConnection(_stack);
135 } else if (elementName.equals(_xt.getOriginTag())) {
136 _xml2PN.processOrigin(_stack);
137 } else if (elementName.equals(_xt.getTargetTag())) {
138 _xml2PN.processTarget(_stack);
139 } else if (elementName.equals(_xt.getSourceTag())) {
140 _xml2PN.processSource(_stack);
141 } else if (elementName.equals(_xt.getProfilingTag())) {
142 _xml2PN.processProfiling(_stack);
143 } else if (elementName.equals(_xt.getConfigurationTag())) {
144 _xml2PN.processConfiguration(_stack);
145 } else if (elementName.equals(_xt.getPortTag())) {
146 _xml2PN.processPort(_stack);
150 /** stack containing the generated objects */
151 protected Stack<Object> _stack;
153 /** actions to be taken while parsing every XML element */
154 protected Xml2PN _xml2PN;
157 protected XmlTag _xt = XmlTag.getInstance();