Search in sources :

Example 6 with Xmlproducer

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);
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Xmlproducer(cbit.vcell.xml.Xmlproducer) DataAccessException(org.vcell.util.DataAccessException)

Example 7 with Xmlproducer

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();
}
Also used : Xmlproducer(cbit.vcell.xml.Xmlproducer) ProfileDataElement(org.vcell.optimization.ProfileDataElement) Element(org.jdom.Element) BufferedOutputStream(java.io.BufferedOutputStream)

Example 8 with Xmlproducer

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;
}
Also used : Xmlproducer(cbit.vcell.xml.Xmlproducer) ReactionRuleSpec(cbit.vcell.mapping.ReactionRuleSpec) Element(org.jdom.Element) XmlParseException(cbit.vcell.xml.XmlParseException) SimulationContextParameter(cbit.vcell.mapping.SimulationContext.SimulationContextParameter) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) RateRule(cbit.vcell.mapping.RateRule) BioEvent(cbit.vcell.mapping.BioEvent) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 9 with Xmlproducer

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;
}
Also used : Xmlproducer(cbit.vcell.xml.Xmlproducer) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) Element(org.jdom.Element) Document(org.jdom.Document)

Aggregations

Xmlproducer (cbit.vcell.xml.Xmlproducer)9 Element (org.jdom.Element)4 DataAccessException (org.vcell.util.DataAccessException)3 XmlParseException (cbit.vcell.xml.XmlParseException)2 BufferedOutputStream (java.io.BufferedOutputStream)2 KeyValue (org.vcell.util.document.KeyValue)2 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)1 BioModel (cbit.vcell.biomodel.BioModel)1 ChildWindowManager (cbit.vcell.client.ChildWindowManager)1 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)1 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)1 CSGObject (cbit.vcell.geometry.CSGObject)1 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)1 BioEvent (cbit.vcell.mapping.BioEvent)1 RateRule (cbit.vcell.mapping.RateRule)1 ReactionRuleSpec (cbit.vcell.mapping.ReactionRuleSpec)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 MathMappingCallback (cbit.vcell.mapping.SimulationContext.MathMappingCallback)1 SimulationContextParameter (cbit.vcell.mapping.SimulationContext.SimulationContextParameter)1 SpatialObject (cbit.vcell.mapping.spatial.SpatialObject)1