use of cbit.vcell.xml.Xmlproducer in project vcell by virtualcell.
the class ApplicationMathTable method saveOutputFunctions.
private void saveOutputFunctions(Connection con, KeyValue mathModelRef, KeyValue simContextRef, ArrayList<AnnotatedFunction> outputFunctionsList, DatabaseSyntax dbSyntax, KeyFactory keyFactory) throws SQLException, DataAccessException {
if (outputFunctionsList == null || outputFunctionsList.size() == 0) {
return;
}
if (mathModelRef == null && simContextRef == null) {
throw new DataAccessException("must have either mathmodel or simcontext reference for saving OutputFunctions");
}
if (mathModelRef != null && simContextRef != null) {
throw new DataAccessException("OutputFunctions can be saved to either a mathmodel or simcontext, not both");
}
String outputFunctionsXML = XmlUtil.xmlToString((new Xmlproducer(false)).getXML(outputFunctionsList));
String tableValues = null;
if (DbDriver.varchar2_CLOB_is_Varchar2_OK(outputFunctionsXML)) {
tableValues = "null" + "," + DbDriver.INSERT_VARCHAR2_HERE;
} else {
tableValues = DbDriver.INSERT_CLOB_HERE + "," + "null";
}
KeyValue newKey = keyFactory.getNewKey(con);
String sql = "INSERT INTO " + ApplicationMathTable.table.getTableName() + " VALUES (" + newKey.toString() + "," + (simContextRef != null ? simContextRef.toString() : "NULL") + "," + tableValues + "," + (mathModelRef != null ? mathModelRef.toString() : "NULL") + ")";
DbDriver.varchar2_CLOB_update(con, sql, outputFunctionsXML, ApplicationMathTable.table, newKey, ApplicationMathTable.table.outputFuncLarge, ApplicationMathTable.table.outputFuncSmall, dbSyntax);
}
use of cbit.vcell.xml.Xmlproducer in project vcell by virtualcell.
the class MicroscopyXmlproducer method writeXMLFile.
public static void writeXMLFile(FRAPStudy frapStudy, File outputFile, boolean bPrintKeys, ClientTaskStatusSupport progressListener, boolean bSaveCompressed) throws Exception {
Xmlproducer vcellXMLProducer = new Xmlproducer(bPrintKeys);
Element root = MicroscopyXmlproducer.getXML(frapStudy, vcellXMLProducer, progressListener, bSaveCompressed);
java.io.FileOutputStream fileOutStream = new java.io.FileOutputStream(outputFile);
BufferedOutputStream bufferedStream = new BufferedOutputStream(fileOutStream);
XmlUtil.writeXmlToStream(root, true, bufferedStream);
fileOutStream.flush();
fileOutStream.close();
}
use of cbit.vcell.xml.Xmlproducer in project vcell by virtualcell.
the class SimContextTable method getAppComponentsForDatabase.
/**
* getXMLStringForDatabase : this returns the XML string for the container element <AppComponents> for application-related protocols
* and other extra specifications. For now, BioEvents falls under this category, so the BioEvents element (list of bioevents)
* is obtained from the simContext (via the XMLProducer) and added as content to <AppComponents> element. The <AppComponents>
* element is converted to XML string which is the return value of this method. This string is stored in the database in the
* SimContextTable. Instead of creating new fields for each possible application component, it is convenient to store them
* all under a blanket XML element <AppComponents>.
* @param simContext
* @return
*/
public static String getAppComponentsForDatabase(SimulationContext simContext) {
Element appComponentsElement = new Element(XMLTags.ApplicationComponents);
// for now, create the element only if application is stochastic. Can change it later.
if (simContext.isStoch()) {
// add 'randomizeInitCondition' flag only if simContext is non-spatial
if (simContext.getGeometry().getDimension() == 0) {
Element appRelatedFlagsElement = new Element(XMLTags.ApplicationSpecificFlagsTag);
if (simContext.isRandomizeInitCondition()) {
appRelatedFlagsElement.setAttribute(XMLTags.RandomizeInitConditionTag, "true");
} else {
appRelatedFlagsElement.setAttribute(XMLTags.RandomizeInitConditionTag, "false");
}
appComponentsElement.addContent(appRelatedFlagsElement);
}
}
if (simContext.isInsufficientIterations()) {
appComponentsElement.setAttribute(XMLTags.InsufficientIterationsTag, "true");
} else {
appComponentsElement.setAttribute(XMLTags.InsufficientIterationsTag, "false");
}
if (simContext.isInsufficientMaxMolecules()) {
appComponentsElement.setAttribute(XMLTags.InsufficientMaxMoleculesTag, "true");
} else {
appComponentsElement.setAttribute(XMLTags.InsufficientMaxMoleculesTag, "false");
}
Xmlproducer xmlProducer = new Xmlproducer(false);
NetworkConstraints constraints = simContext.getNetworkConstraints();
if (constraints != null) {
appComponentsElement.addContent(xmlProducer.getXML(constraints));
}
// first fill in bioevents from simContext
BioEvent[] bioEvents = simContext.getBioEvents();
if (bioEvents != null && bioEvents.length > 0) {
try {
Element bioEventsElement = xmlProducer.getXML(bioEvents);
appComponentsElement.addContent(bioEventsElement);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error generating XML for bioevents : " + e.getMessage());
}
}
SimulationContextParameter[] appParams = simContext.getSimulationContextParameters();
if (appParams != null && appParams.length > 0) {
try {
Element appParamsElement = xmlProducer.getXML(appParams);
appComponentsElement.addContent(appParamsElement);
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error generating XML for application parameters : " + e.getMessage());
}
}
SpatialObject[] spatialObjects = simContext.getSpatialObjects();
if (spatialObjects != null && spatialObjects.length > 0) {
try {
Element spatialObjectsElement = xmlProducer.getXML(spatialObjects);
appComponentsElement.addContent(spatialObjectsElement);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error generating XML for spatialObjects : " + e.getMessage());
}
}
SpatialProcess[] spatialProcesses = simContext.getSpatialProcesses();
if (spatialProcesses != null && spatialProcesses.length > 0) {
try {
Element spatialProcessesElement = xmlProducer.getXML(spatialProcesses);
appComponentsElement.addContent(spatialProcessesElement);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error generating XML for spatialProcesses : " + e.getMessage());
}
}
// microscope measurements
Element element = xmlProducer.getXML(simContext.getMicroscopeMeasurement());
appComponentsElement.addContent(element);
// rate rules
RateRule[] rateRules = simContext.getRateRules();
if (rateRules != null && rateRules.length > 0) {
try {
Element rateRulesElement = xmlProducer.getXML(rateRules);
appComponentsElement.addContent(rateRulesElement);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error generating XML for bioevents : " + e.getMessage());
}
}
// ReactionRuleSpecs
ReactionRuleSpec[] reactionRuleSpecs = simContext.getReactionContext().getReactionRuleSpecs();
if (reactionRuleSpecs != null && reactionRuleSpecs.length > 0) {
Element reactionRuleSpecsElement = xmlProducer.getXML(reactionRuleSpecs);
appComponentsElement.addContent(reactionRuleSpecsElement);
}
String appComponentsXMLStr = null;
if (appComponentsElement.getContent() != null) {
appComponentsXMLStr = XmlUtil.xmlToString(appComponentsElement);
}
return appComponentsXMLStr;
}
use of cbit.vcell.xml.Xmlproducer in project vcell by virtualcell.
the class ModelTable method getRbmForDatabase.
public static String getRbmForDatabase(Model model) {
// add the rbmModelContainer elements
RbmModelContainer rbmModelContainer = model.getRbmModelContainer();
if (rbmModelContainer != null && !rbmModelContainer.isEmpty()) {
Xmlproducer xmlProducer = new Xmlproducer(false);
Element rbmModelContainerElement = xmlProducer.getXML(rbmModelContainer);
Document doc = new Document();
Element clone = (Element) rbmModelContainerElement.clone();
doc.setRootElement(clone);
String xmlString = XmlUtil.xmlToString(doc, false);
return xmlString;
// System.out.println(xmlString);
}
return null;
}
Aggregations