Package org.sbml.jsbml

Examples of org.sbml.jsbml.Annotation


      }

      log4jLogger.debug("processNamespace: " + prefix + " = " + URI);
    }
    else if (contextObject instanceof Annotation) {
      Annotation sbase = (Annotation) contextObject;
      sbase.addAnnotationNamespace(localName, prefix, URI);
     
      log4jLogger.debug("processNamespace: " + prefix + " = " + URI);
    }
  }
View Full Code Here


          SBase sbase = (SBase) contextObject;
          sbase.setNotes(new XMLNode(new XMLTriple("notes", null, null), new XMLAttributes()));
        } else if (elementName.equals("annotation")
            && (contextObject instanceof SBase)) {
          SBase sbase = (SBase) contextObject;
          Annotation annotation = (Annotation) newContextObject;
          sbase.setAnnotation(annotation);

          return annotation;
        } else if (contextObject instanceof SBMLDocument) {
          SBMLDocument sbmlDocument = (SBMLDocument) contextObject;
View Full Code Here

          packageNamespaces.add(sbaseNamespace);
        }
      }

    } else if (object instanceof Annotation) {
      Annotation annotation = (Annotation) object;
      packageNamespaces = annotation.getNamespaces();
    } else {
      logger.warn("getInitializedParsers: I don't know what to do with " + object);
    }
   
    List<WritingParser> sbmlParsers = new ArrayList<WritingParser>();
View Full Code Here

    // create the sbmlNamespace variable
    String sbmlNamespace = JSBML.getNamespaceFrom(sbase.getLevel(), sbase.getVersion());
    SMNamespace namespace = element.getContext().getNamespace(sbmlNamespace);
    namespace.setPreferredPrefix("");

    Annotation annotation = sbase.getAnnotation();
    SMOutputElement annotationElement;
    String whiteSpaces = createIndentationString(indent);
   
    if (xmlFragment) {
      annotationElement = element.addElement("annotation");
    } else {
      element.addCharacters("\n");
      element.setIndentation(whiteSpaces, indent, indentCount);   
      annotationElement = element.addElement(namespace, "annotation");
    }
    annotationElement.setIndentation(whiteSpaces, indent, indentCount);

    if ((annotation.getNonRDFannotation() != null)
        && (annotation.getNonRDFannotation().length() > 0)) {
      StringBuffer annotationBeginning = StringTools.concat(whiteSpaces,
          "<annotation");

      // Adding the name spaces of the annotation element
      Map<String, String> otherNamespaces = annotation
          .getAnnotationNamespaces();

      for (String namespacePrefix : otherNamespaces.keySet()) {
        StringTools.append(annotationBeginning, " ", namespacePrefix,
            "=\"", otherNamespaces.get(namespacePrefix), "\"");
        annotationElement.addAttribute(namespacePrefix, otherNamespaces.get(namespacePrefix));
      }
           
      boolean allNamespacesDefined = true;
     
      // Adding the name spaces of the sbml element
      if (sbase.getSBMLDocument() != null) {
        Map<String, String> sbmlDocumentNamespaces = sbase.getSBMLDocument().getSBMLDocumentNamespaces();

        for (String namespacePrefix : sbmlDocumentNamespaces.keySet()) {
         
          // Checking if the namespace declaration is not done twice
          // in the SBMLDocument and the annotation element.
          if (otherNamespaces.get(namespacePrefix) == null) {
            StringTools.append(annotationBeginning, " ", namespacePrefix,
                "=\"", sbmlDocumentNamespaces.get(namespacePrefix), "\"");
          }
        }

      } else {       
        // Can happen when displaying the annotation from an SBase object
        // that is not  yet linked to a SBMLDocument.
        allNamespacesDefined = false;
      }
      // TODO: to be able to write broken annotations where the namespace declaration is missing
      // we need to add dummy namespace here !! Or remove the namespace awareness on the writer !!
       
      StringTools.append(annotationBeginning, Character.valueOf('>'),
          Character.valueOf('\n'), annotation.getNonRDFannotation(),
          whiteSpaces, "</annotation>", Character.valueOf('\n'));

      DOMConverter converter = new DOMConverter();
     
      String annotationString = annotationBeginning.toString()
          .replaceAll("&", "&amp;");
      // here indent gets lost.
      Document domDocument = null;
      boolean domConversionDone = false;

      try {
        domDocument = JAXPFacade.getInstance().create(
            new BufferedReader(new StringReader(annotationString)),  allNamespacesDefined);
        domConversionDone = true;
      } catch (SAXException e) {
        e.printStackTrace();
        // TODO: log error or send SBMLException

        logger.warn("Cannot parse the following XML\n@" + annotationString + "@");
        logger.warn("NonRDFannotation =\n@" + annotation.getNonRDFannotation() + "@");
       
        // trying to read the XML without namespace awareness as the XML can be wrong and we still want to
        // write it back as it is.
        if (allNamespacesDefined) {
         
          try {
            domDocument = JAXPFacade.getInstance().create(
                new BufferedReader(new StringReader(annotationString))false);
            domConversionDone = true;
          } catch (SAXException e2) {
            e.printStackTrace();
            // TODO: log error or send SBMLException
          }
        }
      } finally {
        if (domConversionDone) { 
          converter.writeFragment(domDocument.getFirstChild()
              .getChildNodes(), writer);
        }
      }
    } else {
      writer.writeCharacters("\n");
    }

    // if the given SBase is not a model and the level is smaller than 3,
    // no history can be written.
    // Annotation cannot be written without metaid tag.

    if (sbase.getAnnotation().isSetRDFannotation()) {
      if (sbase.isSetMetaId()) {
        if (!annotation.isSetAbout()) {
          // add required missing tag
          annotation.setAbout('#' + sbase.getMetaId());
        }
        writeRDFAnnotation(annotation, annotationElement, writer, indent
            + indentCount);
      } else {
        /*
 
View Full Code Here

    // The namespace of this parser should be declared in a 'RDF' subNode of
    // an annotation.
    // Sets the namespace to the RDFAnnotationNamespaces HashMap of
    // annotation.
    if (elementName.equals("RDF") && contextObject instanceof Annotation) {
      Annotation annotation = (Annotation) contextObject;

      annotation.addRDFAnnotationNamespace(localName, prefix, URI);
    }
  }
View Full Code Here

    logger.debug("processStartElement : " + elementName);
   
    // When this parser read a starting element tag, it can modify a
    // contextObject which is an Annotation instance.
    if (contextObject instanceof Annotation) {
      Annotation annotation = (Annotation) contextObject;

      if (!annotation.isSetHistory()) {
        annotation.setHistory(new History());
      }
     
      if (annotation.isSetHistory()) {
        History history = annotation.getHistory();

        // If the localName of the node is 'created' and if it has not
        // been read yet,
        // the previousElement of this parser is set to 'created' and
        // hasReadCreated is set
View Full Code Here

    // The namespace of this parser should be declared in the RDF subnode of
    // the annotation.
    // Adds the namespace to the RDFAnnotationNamespaces HashMap of
    // annotation.
    if (elementName.equals("RDF") && contextObject instanceof Annotation) {
      Annotation annotation = (Annotation) contextObject;

      annotation.addRDFAnnotationNamespace(localName, prefix, URI);
    }
  }
View Full Code Here

    // A BiologicalQualifierParser can only modify a contextObject which is
    // an instance of Annotation.
    // That will probably change in SBML level 3 with the Annotation package
    if (contextObject instanceof Annotation) {
      Annotation annotation = (Annotation) contextObject;

      // This parser can parse only biological Miriam qualifiers. This
      // element should not have attributes or namespace declarations.
      // Creates a new CVTerm and
      // sets the qualifierType and biologicalQualifierType of this
      // CVTerm. Then, adds the
      // initialized CVTerm to annotation.
      if (biologicalQualifierMap.containsKey(elementName)
          && !hasAttributes && !hasNamespaces) {
        CVTerm cvTerm = new CVTerm();
        cvTerm.setQualifierType(Type.BIOLOGICAL_QUALIFIER);
        cvTerm.setBiologicalQualifierType(biologicalQualifierMap
            .get(elementName));

        annotation.addCVTerm(cvTerm);
        return cvTerm;
      } else {
        // TODO : SBML syntax error, log an error
      }
    } else {
View Full Code Here

    // an AnnotationParser can only be used for the annotations of a SBML
    // component. If the contextObject is not
    // an Annotation instance, this parser doesn't process any XML
    // attributes.
    if (contextObject instanceof Annotation) {
      Annotation annotation = (Annotation) contextObject;

      // If there is a prefix, the AnnotationParser will also store the
      // prefix within the key
      // and appends the attribute to the 'otherAnnotation' String of
      // annotation.
      if (!prefix.equals("")) {
        annotation.appendNoRDFAnnotation(" " + prefix + ":"
            + attributeName + "=\"" + value + "\"");
      } else {
        annotation.appendNoRDFAnnotation(" " + attributeName + "=\""
            + value + "\"");
      }

      // If the attribute is the last attribute of its element, we need to
      // close the element tag.
      if (isLastAttribute) {
        annotation.appendNoRDFAnnotation(">");
      }
    } else {
      // There is a syntax error, the attribute can't be read?
      // TODO : log the problem
    }
View Full Code Here

    // an AnnotationParser can only be used for the annotations of a SBML
    // component. If the contextObject is not
    // an Annotation instance, this parser doesn't process any texts.
    if (contextObject instanceof Annotation) {
      Annotation annotation = (Annotation) contextObject;
      annotation.appendNoRDFAnnotation(characters);

    } else {
      // There is a syntax error, the text can't be read?
      logger.warn("some characters migth be lost !! (element name = " + elementName + ", characters = " + characters);
    }
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.Annotation

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.