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;
}
}
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();
}
}
}
}
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);
}
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());
}
}
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);
}
}
}
Aggregations