Package org.sbml.jsbml.xml.parsers

Examples of org.sbml.jsbml.xml.parsers.ReadingParser


    initializePackageParsers();

    XMLEvent event;
    StartElement startElement = null;
    ReadingParser parser = null;
    Stack<Object> sbmlElements = new Stack<Object>();
    QName currentNode = null;
    boolean isNested = false;
    boolean isText = false;
    boolean isHTML = false;
    boolean isRDFSBMLSpecificAnnotation = false;
    boolean isInsideAnnotation = false;
    boolean isInsideNotes = false;
    int rdfDescriptionIndex = -1;
    int annotationDeepness = -1;
    int level = -1, version = -1;
    Object lastElement = null;
   
    Logger logger = Logger.getLogger(SBMLReader.class);
   
    // Read all the elements of the file
    while (xmlEventReader.hasNext()) {
      event = (XMLEvent2) xmlEventReader.nextEvent();

      // StartDocument
      if (event.isStartDocument()) {
        @SuppressWarnings("unused")
        StartDocument startDocument = (StartDocument) event;
        // nothing to do
      }
      // EndDocument
      else if (event.isEndDocument()) {
        @SuppressWarnings("unused")
        EndDocument endDocument = (EndDocument) event;
        // nothing to do?
      }
      // StartElement
      else if (event.isStartElement()) {
       
        startElement = event.asStartElement();
        currentNode = startElement.getName();
        isNested = false;
        isText = false;
       
        addAnnotationParsers(startElement);

        // If the XML element is the sbml element, creates the
        // necessary ReadingParser instances.
        // Creates an empty SBMLDocument instance and pushes it on
        // the SBMLElements stack.
        if (currentNode.getLocalPart().equals("sbml")) {

          SBMLDocument sbmlDocument = new SBMLDocument();

          // the output of the change listener is activated or not via log4j.properties
          sbmlDocument.addTreeNodeChangeListener(listener == null
              ? new SimpleTreeNodeChangeListener() : listener);

          for (@SuppressWarnings("unchecked")
              Iterator<Attribute> iterator = startElement.getAttributes(); iterator.hasNext();)
          {
            Attribute attr = iterator.next();
            if (attr.getName().toString().equals("level")) {
              level = StringTools.parseSBMLInt(attr.getValue());
              sbmlDocument.setLevel(level);
            } else if (attr.getName().toString().equals("version")) {
              version = StringTools.parseSBMLInt(attr.getValue());
              sbmlDocument.setVersion(version);
            }
          }
          sbmlElements.push(sbmlDocument);
        }
        else if (lastElement == null) // We are probably reading some 'free' XML, mathML or HTML
        {
          // We put a fake Constraint element in the stack that can take either math, notes or message.
          // This a hack to be able to read some mathMl or notes by themselves.
          // If the parent container is set in this SBMLReader, we use it instead.
         
          if (currentNode.getLocalPart().equals("notes") || currentNode.getLocalPart().equals("message"))
          {
            initializedParsers.put("", sbmlCoreParser);
           
          } else if (currentNode.getLocalPart().equals("math"))
          {
            initializedParsers.put("", new MathMLStaxParser());
            initializedParsers.put(ASTNode.URI_MATHML_DEFINITION, new MathMLStaxParser());
            currentNode = new QName(ASTNode.URI_MATHML_DEFINITION, "math");           
          }
         
          // TODO: will not work with arbitrary SBML part
          // TODO: we need to be able, somehow, to set the Model element in the Constraint
          // to be able to have a fully functional parsing. Without it the functionDefinition, for examples, are
          // not properly recognized.
          if (astNodeParent != null)
          {
            sbmlElements.push(astNodeParent);
          }
          else
          {
            Constraint constraint = new Constraint(3,1);
            sbmlElements.push(constraint);
          }
         
        } else if (currentNode.getLocalPart().equals("annotation")) {

          // get the sbml namespace as some element can have similar names in different namespaces
          SBMLDocument sbmlDoc = (SBMLDocument) sbmlElements.firstElement();
          String sbmlNamespace = sbmlDoc.getSBMLDocumentNamespaces().get("xmlns");

          if (currentNode.getNamespaceURI().equals(sbmlNamespace)) {
            if (isInsideAnnotation) {
              logger.warn("Starting to read a new annotation element while the previous annotation element is not finished.");
            }
            isInsideAnnotation = true;
            annotationDeepness++;
          }
         
        } else if (isInsideAnnotation) {
          // Count the number of open elements to know how deep we are in the annotation
          // We should only parse the RDF is annotationDeepness == 1 && rdfDescriptionIndex == 0
          annotationDeepness++;
        }
        else if (currentNode.getLocalPart().equals("notes"))
        {
          // get the sbml namespace as some element can have similar names in different namespaces
          SBase firstElement = (SBase) sbmlElements.firstElement();
         
          if (firstElement instanceof SBMLDocument) {
            SBMLDocument sbmlDoc = (SBMLDocument) firstElement;
            String sbmlNamespace = sbmlDoc.getSBMLDocumentNamespaces().get("xmlns");

            if (currentNode.getNamespaceURI().equals(sbmlNamespace)) {
              isInsideNotes = true;
            }
          } else if (firstElement instanceof Constraint) { // we are reading a partial document from SBMLReader#readNotes for example
            isInsideNotes = true;
          }
        }
       
        // setting isRDFSBMLSpecificAnnotation
        if (currentNode.getLocalPart().equals("RDF") && currentNode.getNamespaceURI().equals(Annotation.URI_RDF_SYNTAX_NS) && annotationDeepness == 1) {
          isRDFSBMLSpecificAnnotation = true;
        } else if (currentNode.getLocalPart().equals("RDF") && currentNode.getNamespaceURI().equals(Annotation.URI_RDF_SYNTAX_NS)) {
          isRDFSBMLSpecificAnnotation = false;
          rdfDescriptionIndex = -1;
        }

        if (currentNode.getLocalPart().equals("Description") && currentNode.getNamespaceURI().equals(Annotation.URI_RDF_SYNTAX_NS) && isRDFSBMLSpecificAnnotation) {
          rdfDescriptionIndex++;
        }

        if (isInsideAnnotation && logger.isDebugEnabled()) {
          logger.debug("startElement: local part = " + currentNode.getLocalPart());
          logger.debug("startElement: annotation deepness = " + annotationDeepness);
          logger.debug("startElement: rdf description index = " + rdfDescriptionIndex);
          logger.debug("startElement: isRDFSBMLSpecificAnnotation = " + isRDFSBMLSpecificAnnotation);
        }

        parser = processStartElement(startElement, currentNode, isHTML,  sbmlElements,
            isInsideNotes, annotationDeepness, isRDFSBMLSpecificAnnotation);
        lastElement = sbmlElements.peek();

      }
      // Characters
      else if (event.isCharacters()) {
        Characters characters = event.asCharacters();

        if (!characters.isWhiteSpace()) {
          isText = true; // the characters are not only 'white spaces'
        }
        if (sbmlElements.peek() instanceof XMLNode || isInsideNotes) {
          isText = true; // We want to keep the whitespace/formatting when reading html block
        }

        // process the text of a XML element.
        if ((parser != null) && !sbmlElements.isEmpty()  && (isText || isInsideAnnotation)) {
         
          if (isInsideNotes) {
            parser = initializedParsers.get(JSBML.URI_XHTML_DEFINITION);
          }
//          else if (isInsideAnnotation) {
//            parser = initializedParsers.get("anyAnnotation");
//          }
         
          if (logger.isDebugEnabled()) {
            logger.debug(" Parser = " + parser.getClass().getName());
            logger.debug(" Characters = @" + characters.getData() + "@");
          }
         
          if (currentNode != null) {
           
            // logger.debug("isCharacter: elementName = " + currentNode.getLocalPart());
           
            parser.processCharactersOf(currentNode.getLocalPart(),
                characters.getData(), sbmlElements.peek());
          } else {
            parser.processCharactersOf(null, characters.getData(),
                sbmlElements.peek());
          }
        } else if (isText) {
          logger.warn(MessageFormat.format("Some characters cannot be read: {0}", characters.getData()));
          if (logger.isDebugEnabled()) {
View Full Code Here


  private ReadingParser processStartElement(StartElement startElement, QName currentNode,
      Boolean isHTML, Stack<Object> sbmlElements, boolean isInsideNotes,
      int annotationDeepness, boolean isRDFSBMLspecificAnnotation)
  {   
    Logger logger = Logger.getLogger(SBMLReader.class);   
    ReadingParser parser = null;

    String elementNamespace = currentNode.getNamespaceURI();

    if (logger.isDebugEnabled()) {
      logger.debug("processStartElement: " + currentNode.getLocalPart() + ", " + elementNamespace);
    }
   
    // To be able to parse all the SBML file, the sbml node
    // should have been read first.
    if (!sbmlElements.isEmpty() && (initializedParsers != null)) {

      // All the element should have a namespace.
      if (elementNamespace != null) {
       
        parser = initializedParsers.get(elementNamespace);
        // if the current node is a notes or message element
        // and the matching ReadingParser is a StringParser,
        // we need to set the typeOfNotes variable of the
        // StringParser instance.
        if (currentNode.getLocalPart().equals("notes")
            || currentNode.getLocalPart().equals("message"))
        {
          ReadingParser sbmlparser = initializedParsers.get(JSBML.URI_XHTML_DEFINITION);

          if (sbmlparser instanceof StringParser) {
            StringParser notesParser = (StringParser) sbmlparser;
            notesParser.setTypeOfNotes(currentNode.getLocalPart());
          }
View Full Code Here

   */
  private void processNamespaces(Iterator<Namespace> nam, QName currentNode,
      Stack<Object> sbmlElements,  ReadingParser parser, boolean hasAttributes)
  {
    Logger logger = Logger.getLogger(SBMLReader.class);
    ReadingParser namespaceParser = null;

    while (nam.hasNext()) {
      Namespace namespace = (Namespace) nam.next();
      boolean isLastNamespace = !nam.hasNext();
      namespaceParser = initializedParsers.get(namespace.getNamespaceURI());
     
      logger.debug("processNamespaces: " + namespace.getNamespaceURI());
     
      // Calling the currentNode parser to store all the declared namespaces
      parser.processNamespace(currentNode.getLocalPart(),
          namespace.getNamespaceURI(),
          namespace.getName().getPrefix(),
          namespace.getName().getLocalPart(),
          hasAttributes, isLastNamespace,
          sbmlElements.peek());
     
      // Calling each corresponding parser, in case they want to initialize things for the currentNode
      if ((namespaceParser != null) && !namespaceParser.getClass().equals(parser.getClass())) {
       
        logger.debug("processNamespaces 2e parser: " + namespaceParser);
       
        namespaceParser.processNamespace(currentNode.getLocalPart(),
            namespace.getNamespaceURI(),
            namespace.getName().getPrefix(),
            namespace.getName().getLocalPart(),
            hasAttributes, isLastNamespace,
            sbmlElements.peek());
View Full Code Here

  private void processAttributes(Iterator<Attribute> att, QName currentNode,
      Stack<Object> sbmlElements, ReadingParser parser, boolean hasAttributes,
      boolean isInsideNotes, int annotationDeepness, boolean isRDFSBMLSpecificAnnotation)
  {
    Logger logger = Logger.getLogger(SBMLReader.class);
    ReadingParser attributeParser = null;

    while (att.hasNext()) {

      Attribute attribute = (Attribute) att.next();
      boolean isLastAttribute = !att.hasNext();
      QName attributeName = attribute.getName();

      if (attribute.getName().getNamespaceURI().length() > 0) {
        String attributeNamespaceURI = attribute.getName().getNamespaceURI();

        if ((attributeNamespaceURI.equals(Annotation.URI_RDF_SYNTAX_NS)
            || attributeNamespaceURI.equals(JSBML.URI_PURL_ELEMENTS)
            || attributeNamespaceURI.equals(JSBML.URI_PURL_TERMS)
            || attributeNamespaceURI.equals(Creator.URI_RDF_VCARD_NS)
            || attributeNamespaceURI.equals(ModelQualifierParser.getNamespaceURI())
            || attributeNamespaceURI.equals(BiologicalQualifierParser.getNamespaceURI()))
            && !isRDFSBMLSpecificAnnotation)
        {
          attributeParser = initializedParsers.get("anyAnnotation");
        }
        else if ((annotationDeepness > 0) && attributeNamespaceURI.equals(JSBML.URI_XHTML_DEFINITION))
        {
          attributeParser = initializedParsers.get("anyAnnotation");
        }
        else if ((annotationDeepness > 0) && attributeNamespaceURI.startsWith("http://www.sbml.org/sbml/level"))
        {
          // This is probably a mistake in the annotation
          // Sending it to the any parser
          attributeParser = initializedParsers.get("anyAnnotation");
        }
        else if (isInsideNotes)
        {
          attributeParser = initializedParsers.get(JSBML.URI_XHTML_DEFINITION);
        }
        else
        {
          attributeParser = initializedParsers.get(attributeNamespaceURI);
        }
       
      } else {
        attributeParser = parser;
      }

      if (attributeParser != null) {
        attributeParser.processAttribute(
            currentNode.getLocalPart(),
            attributeName.getLocalPart(),
            attribute.getValue(), attributeName.getPrefix(),
            isLastAttribute, sbmlElements.peek());
      } else {
View Full Code Here

      // the matching ReadingParser is a StringParser, we need
      // to reset the typeOfNotes variable of the
      // StringParser instance.
      if (currentNode.getLocalPart().equals("notes")
          || currentNode.getLocalPart().equals("message")) {
        ReadingParser sbmlparser = initializedParsers.get(JSBML.URI_XHTML_DEFINITION);
        if (sbmlparser instanceof StringParser) {
          StringParser notesParser = (StringParser) sbmlparser;
          notesParser.setTypeOfNotes(currentNode.getLocalPart());
        }
      }
      // process the end of the element.
      if (!sbmlElements.isEmpty() && (parser != null)) {

        if (logger.isDebugEnabled()) {
          logger.debug("event.isEndElement: calling parser.processEndElement " + parser.getClass());
        }

        boolean popElementFromTheStack = parser.processEndElement(currentNode.getLocalPart(),
                currentNode.getPrefix(), isNested, sbmlElements.peek());
        // remove the top of the SBMLElements stack at the
        // end of an element if this element is not the sbml
        // element.
        if (!currentNode.getLocalPart().equals("sbml")) {
          if (popElementFromTheStack) {
            sbmlElements.pop();
          }

          // System.out.println("SBMLReader: event.isEndElement: new stack.size = "
          // + SBMLElements.size());

        } else {
         
          logger.debug("event.isEndElement: sbml element found");
         
          // process the end of the document and return
          // the final SBMLDocument
          if (sbmlElements.peek() instanceof SBMLDocument) {
            SBMLDocument sbmlDocument = (SBMLDocument) sbmlElements.peek();
           
            Iterator<Entry<String, ReadingParser>> iterator = initializedParsers.entrySet().iterator();           
            List<String> readingParserClasses = new ArrayList<String>();

            // Calling endDocument for all parsers           
            while (iterator.hasNext()) {
              Entry<String, ReadingParser> entry = iterator.next();
              ReadingParser sbmlParser = entry.getValue();
             
              if (!readingParserClasses.contains(sbmlParser.getClass().getCanonicalName())) {

                readingParserClasses.add(sbmlParser.getClass().getCanonicalName());

                logger.debug("event.isEndElement: EndDocument found: parser = " + sbmlParser.getClass());

                sbmlParser.processEndDocument(sbmlDocument);

                // call endDocument only on the parser associated with the namespaces
                // declared on the sbml document ??.
              }
            }
View Full Code Here

    initializePackageParsers();

    XMLEvent event;
    StartElement startElement = null;
    ReadingParser parser = null;
    Stack<Object> sbmlElements = new Stack<Object>();
    QName currentNode = null;
    boolean isNested = false;
    boolean isText = false;
    boolean isHTML = false;
    boolean isRDFSBMLSpecificAnnotation = false;
    boolean isInsideAnnotation = false;
    boolean isInsideNotes = false;
    int rdfDescriptionIndex = -1;
    int annotationDeepness = -1;
    int level = -1, version = -1;
    Object lastElement = null;
   
    Logger logger = Logger.getLogger(SBMLReader.class);
   
    // Read all the elements of the file
    while (xmlEventReader.hasNext()) {
      event = (XMLEvent2) xmlEventReader.nextEvent();

      // StartDocument
      if (event.isStartDocument()) {
        @SuppressWarnings("unused")
        StartDocument startDocument = (StartDocument) event;
        // nothing to do
      }
      // EndDocument
      else if (event.isEndDocument()) {
        @SuppressWarnings("unused")
        EndDocument endDocument = (EndDocument) event;
        // nothing to do?
      }
      // StartElement
      else if (event.isStartElement()) {
       
        startElement = event.asStartElement();
        currentNode = startElement.getName();
        isNested = false;
        isText = false;
       
        addAnnotationParsers(startElement);

        // If the XML element is the sbml element, creates the
        // necessary ReadingParser instances.
        // Creates an empty SBMLDocument instance and pushes it on
        // the SBMLElements stack.
        if (currentNode.getLocalPart().equals("sbml")) {

          SBMLDocument sbmlDocument = new SBMLDocument();

          // the output of the change listener is activated or not via log4j.properties
          sbmlDocument.addTreeNodeChangeListener(listener == null
            ? new SimpleTreeNodeChangeListener() : listener);

          for (@SuppressWarnings("unchecked")
              Iterator<Attribute> iterator = startElement.getAttributes(); iterator.hasNext();)
          {
            Attribute attr = iterator.next();
            if (attr.getName().toString().equals("level")) {
              level = StringTools.parseSBMLInt(attr.getValue());
              sbmlDocument.setLevel(level);
            } else if (attr.getName().toString().equals("version")) {
              version = StringTools.parseSBMLInt(attr.getValue());
              sbmlDocument.setVersion(version);
            }
          }
          sbmlElements.push(sbmlDocument);
        } else if (lastElement == null) {
          // We put a fake Constraint element in the stack that can take either math, notes or message.
          // This a hack to be able to read some mathMl or notes by themselves.

          if (currentNode.getLocalPart().equals("notes") || currentNode.getLocalPart().equals("message")) {
           
            initializedParsers.put("", new SBMLCoreParser());
           
          } else if (currentNode.getLocalPart().equals("math")) {
           
            initializedParsers.put("", new MathMLStaxParser());
            initializedParsers.put(ASTNode.URI_MATHML_DEFINITION, new MathMLStaxParser());
            currentNode = new QName(ASTNode.URI_MATHML_DEFINITION, "math");
           
          }
         
          // TODO : will not work with arbitrary SBML part
          // TODO : we need to be able, somehow, to set the Model element in the Constraint
          // to be able to have a fully functional parsing. Without it the functionDefinition, for examples, are
          // not properly recognized.
          Constraint constraint = new Constraint(3,1);
          sbmlElements.push(constraint);
         
        } else if (currentNode.getLocalPart().equals("annotation")) {

          // get the sbml namespace as some element can have similar names in different namespaces
          SBMLDocument sbmlDoc = (SBMLDocument) sbmlElements.firstElement();
          String sbmlNamespace = sbmlDoc.getSBMLDocumentNamespaces().get("xmlns");

          if (currentNode.getNamespaceURI().equals(sbmlNamespace)) {
            if (isInsideAnnotation) {
              logger.warn("Starting to read a new annotation element while the previous annotation element is not finished.");
            }
            isInsideAnnotation = true;
            annotationDeepness++;
          }
         
        } else if (isInsideAnnotation) {
          // Count the number of open elements to know how deep we are in the annotation
          // We should only parse the RDF is annotationDeepness == 1 && rdfDescriptionIndex == 0
          annotationDeepness++;
        }
        else if (currentNode.getLocalPart().equals("notes"))
        {
          // get the sbml namespace as some element can have similar names in different namespaces
          SBMLDocument sbmlDoc = (SBMLDocument) sbmlElements.firstElement();
          String sbmlNamespace = sbmlDoc.getSBMLDocumentNamespaces().get("xmlns");

          if (currentNode.getNamespaceURI().equals(sbmlNamespace)) {
            isInsideNotes = true;
          }
        }
       
        // setting isRDFSBMLSpecificAnnotation
        if (currentNode.getLocalPart().equals("RDF") && currentNode.getNamespaceURI().equals(Annotation.URI_RDF_SYNTAX_NS) && annotationDeepness == 1) {
          isRDFSBMLSpecificAnnotation = true;
        } else if (currentNode.getLocalPart().equals("RDF") && currentNode.getNamespaceURI().equals(Annotation.URI_RDF_SYNTAX_NS)) {
          isRDFSBMLSpecificAnnotation = false;
          rdfDescriptionIndex = -1;
        }

        if (currentNode.getLocalPart().equals("Description") && currentNode.getNamespaceURI().equals(Annotation.URI_RDF_SYNTAX_NS) && isRDFSBMLSpecificAnnotation) {
          rdfDescriptionIndex++;
        }

        if (isInsideAnnotation) {
          logger.debug("startElement : local part = " + currentNode.getLocalPart());
          logger.debug("startElement : annotation deepness = " + annotationDeepness);
          logger.debug("startElement : rdf description index = " + rdfDescriptionIndex);
          logger.debug("startElement : isRDFSBMLSpecificAnnotation = " + isRDFSBMLSpecificAnnotation);
        }

        parser = processStartElement(startElement, currentNode, isHTML,  sbmlElements, isInsideAnnotation, isRDFSBMLSpecificAnnotation);
        lastElement = sbmlElements.peek();

      }
      // Characters
      else if (event.isCharacters()) {
        Characters characters = event.asCharacters();

        if (!characters.isWhiteSpace()) {
          isText = true; // the characters are not only 'white spaces'
        }
        if (sbmlElements.peek() instanceof XMLNode || isInsideNotes) {
          isText = true; // We want to keep the whitespace/formatting when reading html block
        }

        // process the text of a XML element.
        if ((parser != null) && !sbmlElements.isEmpty()  && (isText || isInsideAnnotation)) {
         
          if (isInsideNotes) {
            parser = initializedParsers.get(JSBML.URI_XHTML_DEFINITION);
          }
//          else if (isInsideAnnotation) {
//            parser = initializedParsers.get("anyAnnotation");
//          }
         
          logger.debug(" Parser = " + parser.getClass().getName());
          logger.debug(" Characters = @" + characters.getData() + "@");
         
          if (currentNode != null) {
           
            // logger.debug("isCharacter : elementName = " + currentNode.getLocalPart());
           
            parser.processCharactersOf(currentNode.getLocalPart(),
                characters.getData(), sbmlElements.peek());
          } else {
            parser.processCharactersOf(null, characters.getData(),
                sbmlElements.peek());
          }
        } else if (isText) {
          logger.warn(String.format("Some characters cannot be read: %s", characters.getData()));
          if (logger.isDebugEnabled()) {
View Full Code Here

   */
  private ReadingParser processStartElement(StartElement startElement, QName currentNode,
      Boolean isHTML, Stack<Object> sbmlElements, boolean isInsideAnnotation, boolean isRDFSBMLspecificAnnotation)
  {   
    Logger logger = Logger.getLogger(SBMLReader.class);   
    ReadingParser parser = null;

    String elementNamespace = currentNode.getNamespaceURI();

    logger.debug("processStartElement : " + currentNode.getLocalPart() + ", " + elementNamespace);
   
    // To be able to parse all the SBML file, the sbml node
    // should have been read first.
    if (!sbmlElements.isEmpty() && (initializedParsers != null)) {

      // All the element should have a namespace.
      if (elementNamespace != null) {
       
        parser = initializedParsers.get(elementNamespace);
        // if the current node is a notes or message element
        // and the matching ReadingParser is a StringParser,
        // we need to set the typeOfNotes variable of the
        // StringParser instance.
        if (currentNode.getLocalPart().equals("notes")
            || currentNode.getLocalPart().equals("message"))
        {
          ReadingParser sbmlparser = initializedParsers.get(JSBML.URI_XHTML_DEFINITION);

          if (sbmlparser instanceof StringParser) {
            StringParser notesParser = (StringParser) sbmlparser;
            notesParser.setTypeOfNotes(currentNode.getLocalPart());
          }
View Full Code Here

   */
  private void processNamespaces(Iterator<Namespace> nam, QName currentNode,
      Stack<Object> sbmlElements,  ReadingParser parser, boolean hasAttributes)
  {
    Logger logger = Logger.getLogger(SBMLReader.class);
    ReadingParser namespaceParser = null;

    while (nam.hasNext()) {
      Namespace namespace = (Namespace) nam.next();
      boolean isLastNamespace = !nam.hasNext();
      namespaceParser = initializedParsers.get(namespace.getNamespaceURI());
     
      logger.debug("processNamespaces : " + namespace.getNamespaceURI());
     
      // Calling the currentNode parser to store all the declared namespaces
      parser.processNamespace(currentNode.getLocalPart(),
          namespace.getNamespaceURI(),
          namespace.getName().getPrefix(),
          namespace.getName().getLocalPart(),
          hasAttributes, isLastNamespace,
          sbmlElements.peek());
     
      // Calling each corresponding parser, in case they want to initialize things for the currentNode
      if ((namespaceParser != null) && !namespaceParser.getClass().equals(parser.getClass())) {
       
        logger.debug("processNamespaces 2e parser : " + namespaceParser);
       
        namespaceParser.processNamespace(currentNode.getLocalPart(),
            namespace.getNamespaceURI(),
            namespace.getName().getPrefix(),
            namespace.getName().getLocalPart(),
            hasAttributes, isLastNamespace,
            sbmlElements.peek());
View Full Code Here

  private void processAttributes(Iterator<Attribute> att, QName currentNode,
      Stack<Object> sbmlElements, ReadingParser parser, boolean hasAttributes,
      boolean isInsideAnnotation, boolean isRDFSBMLSpecificAnnotation)
  {
    Logger logger = Logger.getLogger(SBMLReader.class);
    ReadingParser attributeParser = null;

    while (att.hasNext()) {

      Attribute attribute = (Attribute) att.next();
      boolean isLastAttribute = !att.hasNext();
      QName attributeName = attribute.getName();

      if (attribute.getName().getNamespaceURI().length() > 0) {
        String attributeNamespaceURI = attribute.getName().getNamespaceURI();

        if ((attributeNamespaceURI.equals(Annotation.URI_RDF_SYNTAX_NS)
            || attributeNamespaceURI.equals(JSBML.URI_PURL_ELEMENTS)
            || attributeNamespaceURI.equals(JSBML.URI_PURL_TERMS)
            || attributeNamespaceURI.equals(ModelQualifierParser.getNamespaceURI())
            || attributeNamespaceURI.equals(BiologicalQualifierParser.getNamespaceURI()))
            && !isRDFSBMLSpecificAnnotation)
        {
          attributeParser = initializedParsers.get("anyAnnotation");
        }
        else if (isInsideAnnotation && attributeNamespaceURI.equals(JSBML.URI_XHTML_DEFINITION))
        {
          attributeParser = initializedParsers.get("anyAnnotation");
        }
        else
        {
          attributeParser = initializedParsers.get(attributeNamespaceURI);
        }
       
      } else {
        attributeParser = parser;
      }

      if (attributeParser != null) {
        attributeParser.processAttribute(
            currentNode.getLocalPart(),
            attributeName.getLocalPart(),
            attribute.getValue(), attributeName.getPrefix(),
            isLastAttribute, sbmlElements.peek());
      } else {
View Full Code Here

      // the matching ReadingParser is a StringParser, we need
      // to reset the typeOfNotes variable of the
      // StringParser instance.
      if (currentNode.getLocalPart().equals("notes")
          || currentNode.getLocalPart().equals("message")) {
        ReadingParser sbmlparser = initializedParsers.get(JSBML.URI_XHTML_DEFINITION);
        if (sbmlparser instanceof StringParser) {
          StringParser notesParser = (StringParser) sbmlparser;
          notesParser.setTypeOfNotes(currentNode.getLocalPart());
        }
      }
      // process the end of the element.
      if (!sbmlElements.isEmpty() && (parser != null)) {
        logger.debug("event.isEndElement : calling parser.processEndElement " + parser.getClass());

        boolean popElementFromTheStack = parser.processEndElement(currentNode.getLocalPart(),
                currentNode.getPrefix(), isNested, sbmlElements.peek());
        // remove the top of the SBMLElements stack at the
        // end of an element if this element is not the sbml
        // element.
        if (!currentNode.getLocalPart().equals("sbml")) {
          if (popElementFromTheStack) {
            sbmlElements.pop();
          }

          // System.out.println("SBMLReader : event.isEndElement : new stack.size = "
          // + SBMLElements.size());

        } else {
         
          logger.debug("event.isEndElement : sbml element found");
         
          // process the end of the document and return
          // the final SBMLDocument
          if (sbmlElements.peek() instanceof SBMLDocument) {
            SBMLDocument sbmlDocument = (SBMLDocument) sbmlElements.peek();
           
            Iterator<Entry<String, ReadingParser>> iterator = initializedParsers.entrySet().iterator();           
            ArrayList<String> readingParserClasses = new ArrayList<String>();

            // Calling endDocument for all parsers           
            while (iterator.hasNext()) {
              Entry<String, ReadingParser> entry = iterator.next();
              ReadingParser sbmlParser = entry.getValue();
             
              if (!readingParserClasses.contains(sbmlParser.getClass().getCanonicalName())) {

                readingParserClasses.add(sbmlParser.getClass().getCanonicalName());

                logger.debug("event.isEndElement : EndDocument found : parser = " + sbmlParser.getClass());

                sbmlParser.processEndDocument(sbmlDocument);

                // call endDocument only on the parser associated with the namespaces
                // declared on the sbml document ??.
              }
            }
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.xml.parsers.ReadingParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.