Search in sources :

Example 1 with XMLNamespaces

use of org.sbml.jsbml.xml.XMLNamespaces in project vcell by virtualcell.

the class SBMLAnnotationUtil method writeAnnotation.

public void writeAnnotation(Identifiable identifiable, SBase sBase, Element vcellImportRelatedElement) throws XMLStreamException {
    // Deal with RDF annotation
    XMLNode rootAnnotation = new XMLNode(tripleAnnotation, new XMLAttributes());
    Resource resource = metaData.getRegistry().getEntry(identifiable).getResource();
    Graph rdfChunk = null;
    if (resource != null) {
        rdfChunk = chopper.getChops().get(resource);
    }
    if (identifiable == root && rdfChunk != null) {
        rdfChunk.addAll(chopper.getRemains());
    }
    XMLNode rootRDF = null;
    if (rdfChunk != null && metaData.getBaseURIExtended() != null) {
        Element element = XMLRDFWriter.createElement(rdfChunk, nsSBML);
        XMLNamespaces xmlnss = new XMLNamespaces();
        xmlnss.add(DefaultNameSpaces.RDF.uri, DefaultNameSpaces.RDF.prefix);
        rootRDF = XMLNode.convertStringToXMLNode(XmlUtil.xmlToString(element), xmlnss);
    }
    if (rootRDF != null && rootRDF.getNumChildren() > 0) {
        rootAnnotation.addChild(rootRDF);
    }
    // Deal with the non-RDF; VCell free-text annotations
    // get free text annotation from NonRDFAnnotation (associated with identifiable); create XMLNode
    XMLNode rootVCellInfo = new XMLNode(tripleVCellInfo, new XMLAttributes());
    rootVCellInfo.addNamespace(XMLTags.SBML_VCELL_NS, XMLTags.VCELL_NS_PREFIX);
    String freeTextStr = metaData.getFreeTextAnnotation(identifiable);
    if (freeTextStr != null && freeTextStr.length() > 0) {
        XMLNode contentFreeText = new XMLNode(freeTextStr);
        XMLNode rootFreeText = new XMLNode(tripleFreeText, new XMLAttributes());
        rootFreeText.addChild(contentFreeText);
        rootVCellInfo.addChild(rootFreeText);
    }
    // VCell specific info to be exported to SBML as annotation - used for import, not needed for metadata
    if (vcellImportRelatedElement != null) {
        XMLNode xn = elementToXMLNode(vcellImportRelatedElement);
        if (xn != null) {
            xn.removeNamespace(XMLTags.VCELL_NS_PREFIX);
            rootVCellInfo.addChild(xn);
        }
    }
    if (rootVCellInfo.getNumChildren() > 0) {
        rootAnnotation.addChild(rootVCellInfo);
    }
    // Deal with the non-RDF (other tool-related?) annotation
    Element[] elementsXML = metaData.getXmlAnnotations(identifiable);
    if (elementsXML != null) {
        for (Element elementXML : elementsXML) {
            XMLTriple tripleXML = new XMLTriple(elementXML.getName(), elementXML.getNamespaceURI(), elementXML.getNamespacePrefix());
            XMLNode contentXML = elementToXMLNode(elementXML);
            XMLNode rootXML = new XMLNode(tripleXML, new XMLAttributes());
            rootXML.addChild(contentXML);
            rootAnnotation.addChild(rootXML);
        }
    }
    if (rootAnnotation.getNumChildren() > 0) {
        sBase.setAnnotation(rootAnnotation);
    }
    writeMetaID(identifiable, sBase);
}
Also used : XMLAttributes(org.sbml.jsbml.xml.XMLAttributes) HashGraph(org.sbpax.impl.HashGraph) Graph(org.openrdf.model.Graph) XMLNode(org.sbml.jsbml.xml.XMLNode) Element(org.jdom.Element) Resource(org.openrdf.model.Resource) XMLNamespaces(org.sbml.jsbml.xml.XMLNamespaces) XMLTriple(org.sbml.jsbml.xml.XMLTriple)

Aggregations

Element (org.jdom.Element)1 Graph (org.openrdf.model.Graph)1 Resource (org.openrdf.model.Resource)1 XMLAttributes (org.sbml.jsbml.xml.XMLAttributes)1 XMLNamespaces (org.sbml.jsbml.xml.XMLNamespaces)1 XMLNode (org.sbml.jsbml.xml.XMLNode)1 XMLTriple (org.sbml.jsbml.xml.XMLTriple)1 HashGraph (org.sbpax.impl.HashGraph)1