Search in sources :

Example 41 with XmlParseException

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

the class SimulationDatabaseDirect method getSimulation.

@Override
public Simulation getSimulation(User user, KeyValue simKey) throws DataAccessException {
    Simulation sim = null;
    BigString simstr = databaseServerImpl.getSimulationXML(user, simKey);
    if (simstr != null) {
        try {
            sim = XmlHelper.XMLToSim(simstr.toString());
        } catch (XmlParseException e) {
            lg.error(e.getMessage(), e);
            throw new DataAccessException(e.getMessage());
        }
    }
    return sim;
}
Also used : Simulation(cbit.vcell.solver.Simulation) XmlParseException(cbit.vcell.xml.XmlParseException) BigString(org.vcell.util.BigString) DataAccessException(org.vcell.util.DataAccessException)

Example 42 with XmlParseException

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

the class ServerDocumentManager method getMathModelXML.

/**
 * Insert the method's description here.
 * Creation date: (3/29/2004 4:04:16 PM)
 * @return java.lang.String
 * @param vType cbit.sql.VersionableType
 * @param vKey cbit.sql.KeyValue
 */
public String getMathModelXML(QueryHashtable dbc, User user, KeyValue mathModelKey, boolean bRegenerateXML) throws DataAccessException {
    String mathModelXML = null;
    try {
        mathModelXML = dbServer.getDBTopLevel().getMathModelXML(user, mathModelKey, true);
        if (mathModelXML != null) {
            if (bRegenerateXML) {
                try {
                    MathModel mathModel = XmlHelper.XMLToMathModel(new XMLSource(mathModelXML));
                    return cbit.vcell.xml.XmlHelper.mathModelToXML(mathModel);
                } catch (XmlParseException e) {
                    e.printStackTrace();
                    throw new DataAccessException(e.getMessage(), e);
                }
            } else {
                return mathModelXML;
            }
        }
    } catch (java.sql.SQLException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException(e.getMessage());
    } catch (ObjectNotFoundException e) {
    // 
    // not stored as XML currently, retrieve traditional way.
    // 
    }
    try {
        MathModel mathModel = getMathModelUnresolved(dbc, user, mathModelKey);
        mathModelXML = cbit.vcell.xml.XmlHelper.mathModelToXML(mathModel);
        dbServer.insertVersionableXML(user, VersionableType.MathModelMetaData, mathModelKey, mathModelXML);
        return mathModelXML;
    } catch (java.sql.SQLException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException(e.getMessage());
    } catch (cbit.vcell.xml.XmlParseException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException(e.getMessage());
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) XmlParseException(cbit.vcell.xml.XmlParseException) XMLSource(cbit.vcell.xml.XMLSource) DataAccessException(org.vcell.util.DataAccessException)

Example 43 with XmlParseException

use of cbit.vcell.xml.XmlParseException 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 44 with XmlParseException

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

the class VCDatabaseScanner method scanBioModels.

/**
 * Insert the method's description here.
 * Creation date: (2/2/01 3:40:29 PM)
 * @throws DataAccessException
 * @throws XmlParseException
 */
public void scanBioModels(VCDatabaseVisitor databaseVisitor, PrintStream logFilePrintStream, User[] users, KeyValue singleModelKey, HashSet<KeyValue> includeHash, HashSet<KeyValue> excludeHash, boolean bAbortOnDataAccessException) throws DataAccessException, XmlParseException {
    if (users == null) {
        users = getAllUsers();
    }
    try {
        // start visiting models and writing log
        logFilePrintStream.println("Start scanning bio-models......");
        logFilePrintStream.println("\n");
        // adapter for verifyMathDescriptionsUnchanged
        PrintWriter logFilePrintWriter = new PrintWriter(logFilePrintStream);
        for (int i = 0; i < users.length; i++) {
            User user = users[i];
            BioModelInfo[] bioModelInfos = dbServerImpl.getBioModelInfos(user, false);
            for (int j = 0; j < bioModelInfos.length; j++) {
                if (singleModelKey != null && !bioModelInfos[j].getVersion().getVersionKey().compareEqual(singleModelKey)) {
                    System.out.println("skipping biomodel, not the single one that we wanted");
                    continue;
                }
                if (excludeHash != null && excludeHash.contains(bioModelInfos[j].getVersion().getVersionKey())) {
                    System.out.println("skipping bioModel with key '" + bioModelInfos[j].getVersion().getVersionKey() + "'");
                    continue;
                }
                if (includeHash != null && !includeHash.contains(bioModelInfos[j].getVersion().getVersionKey())) {
                    System.out.println("not including bioModel with key '" + bioModelInfos[j].getVersion().getVersionKey() + "'");
                    continue;
                }
                if (!databaseVisitor.filterBioModel(bioModelInfos[j])) {
                    continue;
                }
                try {
                    BigString bioModelXML = dbServerImpl.getBioModelXML(user, bioModelInfos[j].getVersion().getVersionKey());
                    BioModel bioModel = cbit.vcell.xml.XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
                    bioModel.refreshDependencies();
                    // + bioModelInfos[j].getVersion().getName() + " -----> ");
                    logFilePrintStream.println("---- " + (j + 1) + " ----> " + bioModel.getName());
                    databaseVisitor.visitBioModel(bioModel, logFilePrintStream);
                // verifyMathDescriptionsUnchanged(bioModel, logFilePrintWriter);
                } catch (Exception e2) {
                    lg.error(e2.getMessage(), e2);
                    logFilePrintStream.println("======= " + e2.getMessage());
                    if (bAbortOnDataAccessException) {
                        throw e2;
                    }
                }
            }
        }
        logFilePrintStream.close();
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("error writing to log file.");
    }
}
Also used : User(org.vcell.util.document.User) BioModel(cbit.vcell.biomodel.BioModel) BioModelInfo(org.vcell.util.document.BioModelInfo) BigString(org.vcell.util.BigString) XMLSource(cbit.vcell.xml.XMLSource) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) RemoteException(java.rmi.RemoteException) PrintWriter(java.io.PrintWriter)

Example 45 with XmlParseException

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

the class VCDatabaseScanner method multiScanBioModels.

/**
 * Insert the method's description here.
 * Creation date: (2/2/01 3:40:29 PM)
 * @throws DataAccessException
 * @throws XmlParseException
 */
public void multiScanBioModels(VCMultiBioVisitor databaseVisitor, Writer writer, User[] users, boolean bAbortOnDataAccessException) throws DataAccessException, XmlParseException {
    assert users != null;
    try {
        PrintWriter printWriter = new PrintWriter(writer);
        // start visiting models and writing log
        printWriter.println("Start scanning bio-models......");
        printWriter.println("\n");
        for (int i = 0; i < users.length; i++) {
            User user = users[i];
            BioModelInfo[] bioModelInfos = dbServerImpl.getBioModelInfos(user, false);
            for (int j = 0; j < bioModelInfos.length; j++) {
                BioModelInfo bmi = bioModelInfos[j];
                if (!databaseVisitor.filterBioModel(bmi)) {
                    continue;
                }
                try {
                    BigString bioModelXML = dbServerImpl.getBioModelXML(user, bmi.getVersion().getVersionKey());
                    BioModel storedModel = cbit.vcell.xml.XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
                    System.out.println(storedModel.getName());
                    if (databaseVisitor.filterBioModel(storedModel)) {
                        storedModel.refreshDependencies();
                        verifyMathDescriptionsUnchanged(storedModel, printWriter);
                        databaseVisitor.setBioModel(storedModel, printWriter);
                        // + bioModelInfos[j].getVersion().getName() + " -----> ");
                        printWriter.println("---- " + (j + 1) + " ----> " + storedModel.getName());
                        for (BioModel bioModel : databaseVisitor) {
                            SimulationContext[] simContexts = bioModel.getSimulationContexts();
                            for (SimulationContext sc : simContexts) {
                                try {
                                    sc.createNewMathMapping().getMathDescription();
                                } catch (Exception e) {
                                    printWriter.println("\t " + bioModel.getName() + " :: " + sc.getName() + " ----> math regeneration failed.s");
                                // e.printStackTrace();
                                }
                            }
                        }
                    }
                } catch (Exception e2) {
                    lg.error(e2.getMessage(), e2);
                    printWriter.println("======= " + e2.getMessage());
                    if (bAbortOnDataAccessException) {
                        throw e2;
                    }
                }
            }
        }
        printWriter.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : User(org.vcell.util.document.User) BioModel(cbit.vcell.biomodel.BioModel) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationContext(cbit.vcell.mapping.SimulationContext) BigString(org.vcell.util.BigString) XMLSource(cbit.vcell.xml.XMLSource) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) RemoteException(java.rmi.RemoteException) PrintWriter(java.io.PrintWriter)

Aggregations

XmlParseException (cbit.vcell.xml.XmlParseException)49 DataAccessException (org.vcell.util.DataAccessException)35 XMLSource (cbit.vcell.xml.XMLSource)19 BigString (org.vcell.util.BigString)18 BioModel (cbit.vcell.biomodel.BioModel)16 KeyValue (org.vcell.util.document.KeyValue)16 SQLException (java.sql.SQLException)14 ExpressionException (cbit.vcell.parser.ExpressionException)12 IOException (java.io.IOException)12 RemoteProxyException (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)11 SimulationContext (cbit.vcell.mapping.SimulationContext)10 PrintWriter (java.io.PrintWriter)9 User (org.vcell.util.document.User)9 MathException (cbit.vcell.math.MathException)8 MathModel (cbit.vcell.mathmodel.MathModel)8 Element (org.jdom.Element)8 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)8 BioModelInfo (org.vcell.util.document.BioModelInfo)7 PropertyVetoException (java.beans.PropertyVetoException)5 File (java.io.File)5