Search in sources :

Example 1 with XmlReader

use of cbit.vcell.xml.XmlReader in project vcell by virtualcell.

the class TMLPanel method processComparisonResult.

// process events for loading the model displayed in the comparison panel
public VCDocument processComparisonResult() throws Exception {
    try {
        NodeInfo root = (NodeInfo) getTree().getModel().getRoot();
        // if (!isNormal(root)) {
        // displayMessage(this, "Please resolve all tagged elements/attributes before proceeding.");
        // }
        String xmlStr = root.toXmlString();
        // System.out.println(xmlStr);
        Element rootElement = (XmlUtil.stringToXML(xmlStr, null)).getRootElement();
        // ?
        XmlReader reader = new XmlReader(true);
        String rootName = rootElement.getName();
        Document doc = rootElement.getDocument();
        VCDocument vcDoc = null;
        if (rootName.equals(XMLTags.BioModelTag)) {
            String docSoftwareVersion = rootElement.getAttributeValue(XMLTags.SoftwareVersionAttrTag);
            vcDoc = reader.getBioModel(rootElement, (docSoftwareVersion == null ? null : VCellSoftwareVersion.fromString(docSoftwareVersion)));
        } else if (rootName.equals(XMLTags.MathModelTag)) {
            vcDoc = reader.getMathModel(rootElement);
        } else if (rootName.equals(XMLTags.GeometryTag)) {
            vcDoc = reader.getGeometry(rootElement);
        } else {
            throw new Exception("Invalid root for the tree");
        }
        return vcDoc;
    } catch (java.lang.Exception ivjExc) {
        handleException(ivjExc);
        throw ivjExc;
    }
}
Also used : VCDocument(org.vcell.util.document.VCDocument) NodeInfo(cbit.xml.merge.NodeInfo) ChangedNodeInfo(cbit.xml.merge.ChangedNodeInfo) Element(org.jdom.Element) XmlReader(cbit.vcell.xml.XmlReader) VCDocument(org.vcell.util.document.VCDocument) Document(org.jdom.Document)

Example 2 with XmlReader

use of cbit.vcell.xml.XmlReader in project vcell by virtualcell.

the class ModelTable method readRbmElement.

public static void readRbmElement(Connection con, Model model, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException {
    Statement stmt = null;
    try {
        stmt = con.createStatement();
        ResultSet rset = stmt.executeQuery("SELECT * FROM " + ModelTable.table.getTableName() + " WHERE " + ModelTable.table.id.getUnqualifiedColName() + " = " + model.getVersion().getVersionKey().toString());
        if (rset.next()) {
            String rbmXMLStr = DbDriver.varchar2_CLOB_get(rset, ModelTable.table.rbmSmall, ModelTable.table.rbmLarge, dbSyntax);
            rset.close();
            if (rbmXMLStr != null) {
                Element rbmElement = XmlUtil.stringToXML(rbmXMLStr, null).getRootElement();
                XmlReader reader = new XmlReader(false);
                try {
                    reader.getRbmModelContainer(rbmElement, model);
                } catch (ModelException | PropertyVetoException | XmlParseException e) {
                    throw new DataAccessException(e.getMessage(), e);
                }
            }
        }
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ModelException(cbit.vcell.model.ModelException) Statement(java.sql.Statement) Element(org.jdom.Element) ResultSet(java.sql.ResultSet) XmlReader(cbit.vcell.xml.XmlReader) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) ModelException(cbit.vcell.model.ModelException)

Example 3 with XmlReader

use of cbit.vcell.xml.XmlReader in project vcell by virtualcell.

the class ModelTable method getModel.

/**
 * This method was created in VisualAge.
 * @return Model
 * @param rset ResultSet
 * @param log SessionLog
 */
public Model getModel(ResultSet rset, Connection con) throws SQLException, DataAccessException {
    java.math.BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
    Version version = getVersion(rset, DbDriver.getGroupAccessFromGroupID(con, groupid));
    ModelUnitSystem modelUnitSystem = ModelUnitSystem.createDefaultVCModelUnitSystem();
    String unitSystemXML = rset.getString(ModelTable.table.unitSystemXML.toString());
    if (!rset.wasNull()) {
        unitSystemXML = org.vcell.util.TokenMangler.getSQLRestoredString(unitSystemXML);
        XmlReader xmlReader = new XmlReader(false);
        modelUnitSystem = xmlReader.getUnitSystem(XmlUtil.stringToXML(unitSystemXML, null).getRootElement());
    }
    return new Model(version, modelUnitSystem);
}
Also used : Version(org.vcell.util.document.Version) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) Model(cbit.vcell.model.Model) XmlReader(cbit.vcell.xml.XmlReader) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 4 with XmlReader

use of cbit.vcell.xml.XmlReader in project vcell by virtualcell.

the class SimContextTable method readAppComponents.

/**
 * readAppComponents : reads the additional simContext components like bioevents/application related flags (for stochastic, at the moment), if present, and sets them on simContext.
 * @param con
 * @param simContext
 * @return
 * @throws SQLException
 * @throws DataAccessException
 * @throws PropertyVetoException
 */
public void readAppComponents(Connection con, SimulationContext simContext, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException, PropertyVetoException {
    try {
        Element appComponentsElement = getAppComponentsElement(con, simContext.getVersion().getVersionKey(), dbSyntax);
        if (appComponentsElement != null) {
            Element appRelatedFlags = appComponentsElement.getChild(XMLTags.ApplicationSpecificFlagsTag);
            if (appRelatedFlags != null) {
                // for now, only reading the 'randomizeInitCondition' attribute, since 'isStoch' and 'isUsingconcentration' are read in by other means; so not messing with those fields of simContext.
                boolean bRandomizeInitCondition = false;
                if ((appRelatedFlags.getAttributeValue(XMLTags.RandomizeInitConditionTag) != null) && (appRelatedFlags.getAttributeValue(XMLTags.RandomizeInitConditionTag).equals("true"))) {
                    bRandomizeInitCondition = true;
                }
                simContext.setRandomizeInitConditions(bRandomizeInitCondition);
            }
            if ((appComponentsElement.getAttributeValue(XMLTags.InsufficientIterationsTag) != null) && (appComponentsElement.getAttributeValue(XMLTags.InsufficientIterationsTag).equals("true"))) {
                simContext.setInsufficientIterations(true);
            } else {
                simContext.setInsufficientIterations(false);
            }
            if ((appComponentsElement.getAttributeValue(XMLTags.InsufficientMaxMoleculesTag) != null) && (appComponentsElement.getAttributeValue(XMLTags.InsufficientMaxMoleculesTag).equals("true"))) {
                simContext.setInsufficientMaxMolecules(true);
            } else {
                simContext.setInsufficientMaxMolecules(false);
            }
            XmlReader xmlReader = new XmlReader(false);
            NetworkConstraints nc = null;
            Element ncElement = appComponentsElement.getChild(XMLTags.RbmNetworkConstraintsTag);
            if (ncElement != null) {
                // one network constraint element
                nc = xmlReader.getAppNetworkConstraints(ncElement, simContext.getModel());
            }
            simContext.setNetworkConstraints(nc);
            // get spatial objects
            Element spatialObjectsElement = appComponentsElement.getChild(XMLTags.SpatialObjectsTag);
            if (spatialObjectsElement != null) {
                SpatialObject[] spatialObjects = xmlReader.getSpatialObjects(simContext, spatialObjectsElement);
                simContext.setSpatialObjects(spatialObjects);
            }
            // get application parameters
            Element appParamsElement = appComponentsElement.getChild(XMLTags.ApplicationParametersTag);
            if (appParamsElement != null) {
                SimulationContextParameter[] appParams = xmlReader.getSimulationContextParams(appParamsElement, simContext);
                simContext.setSimulationContextParameters(appParams);
            }
            // get bioEvents
            Element bioEventsElement = appComponentsElement.getChild(XMLTags.BioEventsTag);
            if (bioEventsElement != null) {
                BioEvent[] bioEvents = xmlReader.getBioEvents(simContext, bioEventsElement);
                simContext.setBioEvents(bioEvents);
            }
            // get spatial processes
            Element spatialProcessesElement = appComponentsElement.getChild(XMLTags.SpatialProcessesTag);
            if (spatialProcessesElement != null) {
                SpatialProcess[] spatialProcesses = xmlReader.getSpatialProcesses(simContext, spatialProcessesElement);
                simContext.setSpatialProcesses(spatialProcesses);
            }
            // get microscope measurements
            Element element = appComponentsElement.getChild(XMLTags.MicroscopeMeasurement);
            if (element != null) {
                xmlReader.getMicroscopeMeasurement(element, simContext);
            }
            // get rate rules
            Element rateRulesElement = appComponentsElement.getChild(XMLTags.RateRulesTag);
            if (rateRulesElement != null) {
                RateRule[] rateRules = xmlReader.getRateRules(simContext, rateRulesElement);
                simContext.setRateRules(rateRules);
            }
            // get reaction rule specs
            Element reactionRuleSpecsElement = appComponentsElement.getChild(XMLTags.ReactionRuleSpecsTag);
            if (reactionRuleSpecsElement != null) {
                ReactionRuleSpec[] reactionRuleSpecs = xmlReader.getReactionRuleSpecs(simContext, reactionRuleSpecsElement);
                simContext.getReactionContext().setReactionRuleSpecs(reactionRuleSpecs);
            }
        }
    } catch (XmlParseException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException("Error retrieving bioevents : " + e.getMessage());
    }
}
Also used : ReactionRuleSpec(cbit.vcell.mapping.ReactionRuleSpec) Element(org.jdom.Element) XmlReader(cbit.vcell.xml.XmlReader) XmlParseException(cbit.vcell.xml.XmlParseException) SimulationContextParameter(cbit.vcell.mapping.SimulationContext.SimulationContextParameter) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) RateRule(cbit.vcell.mapping.RateRule) BioEvent(cbit.vcell.mapping.BioEvent) DataAccessException(org.vcell.util.DataAccessException) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 5 with XmlReader

use of cbit.vcell.xml.XmlReader in project vcell by virtualcell.

the class SubVolumeTable method getAnalyticOrCompartmentSubVolume.

/**
 * This method was created in VisualAge.
 * @return Model
 * @param rset ResultSet
 * @param log SessionLog
 */
public SubVolume getAnalyticOrCompartmentSubVolume(KeyValue key, ResultSet rset) throws SQLException, ExpressionException, DataAccessException {
    // KeyValue key = new KeyValue(rset.getBigDecimal(id.toString(),0));
    String svName = rset.getString(name.toString());
    int handleValue = rset.getInt(handle.toString());
    String expString = rset.getString(expression.toString());
    if (rset.wasNull()) {
        return new CompartmentSubVolume(key, handleValue);
    } else {
        try {
            if (expString.startsWith("<") && expString.endsWith(">")) {
                String xmlStr = TokenMangler.getSQLRestoredString(expString);
                XmlReader xmlReader = new XmlReader(true);
                Element csgObjElement = (XmlUtil.stringToXML(xmlStr, null)).getRootElement();
                try {
                    CSGObject csgObject = xmlReader.getCSGObject(csgObjElement, key);
                    return csgObject;
                } catch (Exception e1) {
                    e1.printStackTrace(System.out);
                    throw new DataAccessException(e1.getMessage(), e1);
                }
            }
            Expression exp = new Expression(expString);
            return new AnalyticSubVolume(key, svName, exp, handleValue);
        } catch (Exception e) {
            e.printStackTrace(System.out);
            throw new DataAccessException(e.getMessage(), e);
        }
    }
}
Also used : CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) Expression(cbit.vcell.parser.Expression) Element(org.jdom.Element) XmlReader(cbit.vcell.xml.XmlReader) CSGObject(cbit.vcell.geometry.CSGObject) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

XmlReader (cbit.vcell.xml.XmlReader)8 Element (org.jdom.Element)7 DataAccessException (org.vcell.util.DataAccessException)4 SQLException (java.sql.SQLException)3 XmlParseException (cbit.vcell.xml.XmlParseException)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 BioModel (cbit.vcell.biomodel.BioModel)1 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)1 CSGObject (cbit.vcell.geometry.CSGObject)1 CompartmentSubVolume (cbit.vcell.geometry.CompartmentSubVolume)1 BioEvent (cbit.vcell.mapping.BioEvent)1 RateRule (cbit.vcell.mapping.RateRule)1 ReactionRuleSpec (cbit.vcell.mapping.ReactionRuleSpec)1 SimulationContextParameter (cbit.vcell.mapping.SimulationContext.SimulationContextParameter)1 SpatialObject (cbit.vcell.mapping.spatial.SpatialObject)1 SpatialProcess (cbit.vcell.mapping.spatial.processes.SpatialProcess)1 Model (cbit.vcell.model.Model)1 ModelException (cbit.vcell.model.ModelException)1 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)1