--- /dev/null
+/* $Id: ArchiXmlParser.java 1 2010-02-24 13:03:05Z haidw $ */\r
+package dol.parser.xml.archischema;\r
+\r
+import java.util.Stack;\r
+\r
+import org.xml.sax.Attributes;\r
+import org.xml.sax.InputSource;\r
+import org.xml.sax.SAXException;\r
+import org.xml.sax.SAXParseException;\r
+\r
+import dol.datamodel.XmlTag;\r
+import dol.datamodel.architecture.Architecture;\r
+import dol.parser.xml.XmlParser;\r
+\r
+/**\r
+ * Parse architecture XML file.\r
+ */\r
+public class ArchiXmlParser extends XmlParser {\r
+\r
+ /**\r
+ * Constructor.\r
+ */\r
+ public ArchiXmlParser() {\r
+ super();\r
+ _stack = new Stack<Object>();\r
+ _xml2Archi = new Xml2Archi();\r
+ }\r
+\r
+ /**\r
+ * Do the parsing of an XML file describing an architecture.\r
+ *\r
+ * @param url The input XML file\r
+ * @return the architecture\r
+ */\r
+ public Architecture doParse(String url) {\r
+ Architecture architecture = null;\r
+ System.out.println("Read architecture from XML file");\r
+\r
+ try {\r
+ String uri = _makeAbsoluteURL(url);\r
+ _ui.printlnVerbose("-- processing XML file: " + uri);\r
+ _ui.printlnVerbose("-- read XML file: ");\r
+ _stack.clear();\r
+ _parser.parse(new InputSource(uri));\r
+ architecture = (Architecture) _stack.pop();\r
+ _ui.printlnVerbose(" [DONE] ");\r
+ } catch (SAXParseException err) {\r
+ System.out.println("** Parsing error, line "\r
+ + err.getLineNumber() + ", uri " + err.getSystemId());\r
+ System.out.println(" " + err.getMessage());\r
+ } catch (SAXException e) {\r
+ e.printStackTrace();\r
+ } catch (Throwable t) {\r
+ t.printStackTrace();\r
+ }\r
+\r
+ architecture.computePaths();\r
+\r
+ System.out.println(" -- Architecture model from XML "\r
+ + "[Finished]");\r
+ System.out.println();\r
+\r
+ return architecture;\r
+ }\r
+\r
+ /**\r
+ * Action to be done while parsing a start element of an XML.\r
+ *\r
+ * @param elementName Description of the Parameter\r
+ * @param attributes Description of the Parameter\r
+ * @exception SAXException MyException If such and such occurs\r
+ */\r
+ public void startElement(String namespaceURI, String localName,\r
+ String elementName, Attributes attributes)\r
+ throws SAXException {\r
+ Object val = null;\r
+\r
+ if (elementName.equals(_xt.getArchiTag())) {\r
+ val = _xml2Archi.processArchitecture(attributes);\r
+ } else if (elementName.equals(_xt.getVariableTag())) {\r
+ val = _xml2Archi.processVariable(attributes);\r
+ } else if (elementName.equals(_xt.getProcessorTag())) {\r
+ val = _xml2Archi.processProcessor(attributes);\r
+ } else if (elementName.equals(_xt.getMemoryTag())) {\r
+ val = _xml2Archi.processMemory(attributes);\r
+ } else if (elementName.equals(_xt.getHWChannelTag())) {\r
+ val = _xml2Archi.processHWChannel(attributes);\r
+ } else if (elementName.equals(_xt.getConfigurationTag())) {\r
+ val = _xml2Archi.processConfiguration(attributes);\r
+ // simplified architecture\r
+ } else if (elementName.equals(_xt.getConnectionTag())) {\r
+ val = _xml2Archi.processConnection(attributes);\r
+ } else if (elementName.equals(_xt.getOriginTag())) {\r
+ val = _xml2Archi.processOrigin(attributes);\r
+ } else if (elementName.equals(_xt.getTargetTag())) {\r
+ val = _xml2Archi.processTarget(attributes);\r
+ } else if (elementName.equals(_xt.getNodeTag())) {\r
+ val = _xml2Archi.processNode(attributes);\r
+ } else if (elementName.equals(_xt.getPortTag())) {\r
+ val = _xml2Archi.processPort(attributes);\r
+ } else if (elementName.equals(_xt.getInPortTag())) {\r
+ val = _xml2Archi.processInputPort(attributes);\r
+ } else if (elementName.equals(_xt.getOutPortTag())) {\r
+ val = _xml2Archi.processOutputPort(attributes);\r
+ } else if (elementName.equals(_xt.getDuplexPortTag())) {\r
+ val = _xml2Archi.processInOutPort(attributes);\r
+ // detailed architecture\r
+ } else if (elementName.equals(_xt.getReadPathTag())) {\r
+ val = _xml2Archi.processReadPath(attributes);\r
+ } else if (elementName.equals(_xt.getWritePathTag())) {\r
+ val = _xml2Archi.processWritePath(attributes);\r
+ } else if (elementName.equals(_xt.getTXBufTag())) {\r
+ val = _xml2Archi.processTXBuf(attributes);\r
+ } else if (elementName.equals(_xt.getRXBufTag())) {\r
+ val = _xml2Archi.processRXBuf(attributes);\r
+ } else if (elementName.equals(_xt.getCHBufTag())) {\r
+ val = _xml2Archi.processCHBuf(attributes);\r
+ } else {\r
+ System.out.println("--Warning, DOL doesn't "\r
+ + "understand tag <" + elementName + "> ");\r
+ }\r
+\r
+ if (val != null) {\r
+ _stack.push(val);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Action to be done while parsing an end element of an XML.\r
+ *\r
+ * @param elementName Description of the Parameter\r
+ * @exception SAXException MyException If such and such occurs\r
+ */\r
+ public void endElement(String namespaceURI, String localName,\r
+ String elementName) throws SAXException {\r
+ if (elementName.equals(_xt.getArchiTag())) {\r
+ _xml2Archi.processArchitecture(_stack);\r
+ } else if (elementName.equals(_xt.getVariableTag())) {\r
+ _xml2Archi.processVariable(_stack);\r
+ } else if (elementName.equals(_xt.getProcessorTag())) {\r
+ _xml2Archi.processProcessor(_stack);\r
+ } else if (elementName.equals(_xt.getMemoryTag())) {\r
+ _xml2Archi.processMemory(_stack);\r
+ } else if (elementName.equals(_xt.getHWChannelTag())) {\r
+ _xml2Archi.processHWChannel(_stack);\r
+ } else if (elementName.equals(_xt.getConfigurationTag())) {\r
+ _xml2Archi.processConfiguration(_stack);\r
+ // simplified architecture\r
+ } else if (elementName.equals(_xt.getConnectionTag())) {\r
+ _xml2Archi.processConnection(_stack);\r
+ } else if (elementName.equals(_xt.getOriginTag())) {\r
+ _xml2Archi.processOrigin(_stack);\r
+ } else if (elementName.equals(_xt.getTargetTag())) {\r
+ _xml2Archi.processTarget(_stack);\r
+ } else if (elementName.equals(_xt.getNodeTag())) {\r
+ _xml2Archi.processNode(_stack);\r
+ } else if (elementName.equals(_xt.getPortTag())) {\r
+ _xml2Archi.processPort(_stack);\r
+ } else if (elementName.equals(_xt.getInPortTag())) {\r
+ _xml2Archi.processInputPort(_stack);\r
+ } else if (elementName.equals(_xt.getOutPortTag())) {\r
+ _xml2Archi.processOutputPort(_stack);\r
+ } else if (elementName.equals(_xt.getDuplexPortTag())) {\r
+ _xml2Archi.processInOutPort(_stack);\r
+ // detailed architecture\r
+ } else if (elementName.equals(_xt.getReadPathTag())) {\r
+ _xml2Archi.processReadPath(_stack);\r
+ } else if (elementName.equals(_xt.getWritePathTag())) {\r
+ _xml2Archi.processWritePath(_stack);\r
+ } else if (elementName.equals(_xt.getTXBufTag())) {\r
+ _xml2Archi.processTXBuf(_stack);\r
+ } else if (elementName.equals(_xt.getRXBufTag())) {\r
+ _xml2Archi.processRXBuf(_stack);\r
+ } else if (elementName.equals(_xt.getCHBufTag())) {\r
+ _xml2Archi.processCHBuf(_stack);\r
+ }\r
+ }\r
+\r
+ /** stack containing the generated objects */\r
+ protected Stack<Object> _stack;\r
+\r
+ /** actions to be taken while parsing every XML element */\r
+ protected Xml2Archi _xml2Archi;\r
+\r
+ /** */\r
+ protected XmlTag _xt = XmlTag.getInstance();\r
+}\r