Search in sources :

Example 41 with Namespace

use of org.jdom.Namespace in project vcell by virtualcell.

the class XMLUtils method getElementNamespaces.

/**
 * Finds all namespaces, and returns a hashmap where keys are namespaces,
 * and values are the elements where the namespace first appears in the
 * document
 *
 * @param doc
 * @return poss empty but non-null hash.q
 */
public Map<Namespace, Element> getElementNamespaces(Document doc) {
    Iterator it = doc.getDescendants(new ElementFilter());
    Map<Namespace, Element> nss = new HashMap<Namespace, Element>();
    while (it.hasNext()) {
        Element el = (Element) it.next();
        Namespace ns = el.getNamespace();
        if (ns != null && nss.get(ns) == null) {
            nss.put(ns, el);
        }
    }
    return nss;
}
Also used : HashMap(java.util.HashMap) ElementFilter(org.jdom.filter.ElementFilter) Element(org.jdom.Element) Iterator(java.util.Iterator) Namespace(org.jdom.Namespace)

Example 42 with Namespace

use of org.jdom.Namespace in project vcell by virtualcell.

the class SimSpec method fromSBML.

public static SimSpec fromSBML(String sbmlText) throws IOException, SbmlException {
    Element rootSBML = SBMLUtils.readXML(new StringReader(sbmlText));
    Namespace sbmlNamespace = rootSBML.getNamespace();
    // Namespace sbmlNamespace = Namespace.getNamespace("http://www.sbml.org/sbml/level2");
    Element sbmlModelElement = rootSBML.getChild("model", sbmlNamespace);
    // 
    // collect names of Species to compare
    // 
    Vector<String> varNames = new Vector<String>();
    Element listOfSpeciesElement = sbmlModelElement.getChild("listOfSpecies", sbmlNamespace);
    if (listOfSpeciesElement != null) {
        @SuppressWarnings("unchecked") List<Element> speciesElementList = listOfSpeciesElement.getChildren("species", sbmlNamespace);
        for (Element speciesElement : speciesElementList) {
            varNames.add(speciesElement.getAttributeValue("id"));
        }
    } else {
        System.out.println("NO species in SBML model (parameters only) ... must be rate-rules only");
    }
    // 
    // Specify simulation task.
    // 
    String[] varsToTest = varNames.toArray(new String[varNames.size()]);
    float duration = 10f;
    int numTimeSteps = 100;
    SimSpec simSpec = new SimSpec(varsToTest, duration, numTimeSteps);
    return simSpec;
}
Also used : Element(org.jdom.Element) StringReader(java.io.StringReader) Vector(java.util.Vector) Namespace(org.jdom.Namespace)

Example 43 with Namespace

use of org.jdom.Namespace in project vcell by virtualcell.

the class PathwayReaderBiopax3 method addObjectXref.

private Xref addObjectXref(Element element) {
    Namespace bp = Namespace.getNamespace("bp", "http://www.biopax.org/release/biopax-level3.owl#");
    if (element.getChild("UnificationXref", bp) != null) {
        UnificationXref xref = addObjectUnificationXref(element.getChild("UnificationXref", bp));
        return xref;
    }
    if (element.getChild("RelationshipXref", bp) != null) {
        RelationshipXref xref = addObjectRelationshipXref(element.getChild("RelationshipXref", bp));
        return xref;
    }
    if (element.getChild("PublicationXref", bp) != null) {
        PublicationXref xref = addObjectPublicationXref(element.getChild("PublicationXref", bp));
        return xref;
    }
    if (element.getChildren().size() == 0) {
        XrefProxy xref = new XrefProxy();
        addAttributes(xref, element);
        pathwayModel.add(xref);
        return xref;
    } else {
        for (Object child : element.getChildren()) {
            if (child instanceof Element) {
                Element childElement = (Element) child;
                showUnexpected(childElement);
            }
        }
        Xref xref = new Xref();
        pathwayModel.add(xref);
        System.out.println("should never happen");
        return xref;
    }
}
Also used : Xref(org.vcell.pathway.Xref) PublicationXref(org.vcell.pathway.PublicationXref) UnificationXref(org.vcell.pathway.UnificationXref) RelationshipXref(org.vcell.pathway.RelationshipXref) PublicationXref(org.vcell.pathway.PublicationXref) UnificationXref(org.vcell.pathway.UnificationXref) Element(org.jdom.Element) GroupObject(org.vcell.pathway.GroupObject) BioPaxObject(org.vcell.pathway.BioPaxObject) Namespace(org.jdom.Namespace) RelationshipXref(org.vcell.pathway.RelationshipXref) XrefProxy(org.vcell.pathway.persistence.BiopaxProxy.XrefProxy)

Example 44 with Namespace

use of org.jdom.Namespace in project vcell by virtualcell.

the class Xmlproducer method getXML.

private Element getXML(PathwayModel pathwayModel, RDFXMLContext context) {
    Element pathwayElement = new Element(XMLTags.PathwayModelTag);
    String biopaxVersion = "3.0";
    // create root element of rdf for BioPAX level 3
    Namespace rdf = Namespace.getNamespace("rdf", DefaultNameSpaces.RDF.uri);
    Element rootElement = new Element("RDF", rdf);
    rootElement.setAttribute("version", biopaxVersion);
    // get element from producer and add it to root element
    PathwayProducerBiopax3 xmlProducer = new PathwayProducerBiopax3(context);
    // here is work done
    xmlProducer.getXML(pathwayModel, rootElement);
    pathwayElement.addContent(rootElement);
    return pathwayElement;
}
Also used : Element(org.jdom.Element) PathwayProducerBiopax3(org.vcell.pathway.persistence.PathwayProducerBiopax3) Namespace(org.jdom.Namespace)

Example 45 with Namespace

use of org.jdom.Namespace in project vcell by virtualcell.

the class XmlHelper method XMLToSim.

public static Simulation XMLToSim(String xmlString) throws XmlParseException {
    Simulation sim = null;
    Namespace ns = Namespace.getNamespace(XMLTags.VCML_NS);
    try {
        if (xmlString == null || xmlString.length() == 0) {
            throw new XmlParseException("Invalid xml for Simulation: " + xmlString);
        }
        // default parser and no validation
        Element root = (XmlUtil.stringToXML(xmlString, null)).getRootElement();
        Element simElement = root.getChild(XMLTags.SimulationTag, ns);
        Element mdElement = root.getChild(XMLTags.MathDescriptionTag, ns);
        Element geomElement = root.getChild(XMLTags.GeometryTag, ns);
        XmlReader reader = new XmlReader(true, ns);
        Geometry geom = null;
        if (geomElement != null) {
            geom = reader.getGeometry(geomElement);
        }
        MathDescription md = reader.getMathDescription(mdElement, geom);
        sim = reader.getSimulation(simElement, md);
    } catch (Exception pve) {
        pve.printStackTrace();
        throw new XmlParseException("Unable to parse simulation string.", pve);
    }
    sim.refreshDependencies();
    return sim;
}
Also used : Geometry(cbit.vcell.geometry.Geometry) MathDescription(cbit.vcell.math.MathDescription) Element(org.jdom.Element) Namespace(org.jdom.Namespace) XMLStreamException(javax.xml.stream.XMLStreamException) SbmlException(org.vcell.sbml.SbmlException) SBMLException(org.sbml.jsbml.SBMLException) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

Namespace (org.jdom.Namespace)102 Element (org.jdom.Element)85 IOException (java.io.IOException)24 XConfiguration (org.apache.oozie.util.XConfiguration)19 StringReader (java.io.StringReader)15 Configuration (org.apache.hadoop.conf.Configuration)15 JDOMException (org.jdom.JDOMException)15 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)13 ArrayList (java.util.ArrayList)12 Path (org.apache.hadoop.fs.Path)11 Document (org.jdom.Document)11 List (java.util.List)9 File (java.io.File)7 HashMap (java.util.HashMap)6 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)6 SAXBuilder (org.jdom.input.SAXBuilder)6 XMLOutputter (org.jdom.output.XMLOutputter)6 Writer (java.io.Writer)5 Attribute (org.jdom.Attribute)5 Format (org.jdom.output.Format)5