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