use of cbit.vcell.model.Diagram in project vcell by virtualcell.
the class Xmlproducer method getXML.
/**
* Outputs a XML version of a Model object
* Creation date: (2/15/2001 11:39:27 AM)
* @return Element
* @param param cbit.vcell.model.Model
*/
private Element getXML(Model param) throws XmlParseException /*, cbit.vcell.parser.ExpressionException */
{
Element modelnode = new Element(XMLTags.ModelTag);
String versionName = (param.getName() != null) ? mangle(param.getName()) : "unnamed_model";
// get Attributes
modelnode.setAttribute(XMLTags.NameAttrTag, versionName);
// modelnode.setAttribute(XMLTags.AnnotationAttrTag, this.mangle(param.getDescription()));
if (param.getDescription() != null && param.getDescription().length() > 0) {
Element annotationElem = new Element(XMLTags.AnnotationTag);
annotationElem.setText(mangle(param.getDescription()));
modelnode.addContent(annotationElem);
}
// get global parameters
ModelParameter[] modelGlobals = param.getModelParameters();
if (modelGlobals != null && modelGlobals.length > 0) {
modelnode.addContent(getXML(modelGlobals));
}
// Get Species
Species[] array = param.getSpecies();
for (int i = 0; i < array.length; i++) {
modelnode.addContent(getXML(array[i]));
}
// Get Structures(Features and Membranes). Add them in an ordered fashion, but it does not matter who comes first.
try {
ArrayList<Element> list = new ArrayList<Element>();
Structure[] structarray = param.getStructures();
for (int i = 0; i < structarray.length; i++) {
Element structure = getXML(structarray[i], param);
if (structarray[i] instanceof Feature)
modelnode.addContent(structure);
else
list.add(structure);
}
for (int i = 0; i < list.size(); i++) {
modelnode.addContent((Element) list.get(i));
}
} catch (XmlParseException e) {
e.printStackTrace();
throw new XmlParseException("An error occurred while procesing a Structure for the model " + versionName, e);
}
// Process SpeciesContexts
SpeciesContext[] specarray = param.getSpeciesContexts();
for (int i = 0; i < specarray.length; i++) {
modelnode.addContent(getXML(specarray[i]));
}
// Get reaction Steps(Simple Reactions and Fluxtep)
ReactionStep[] reactarray = param.getReactionSteps();
for (int i = 0; i < reactarray.length; i++) {
modelnode.addContent(getXML(reactarray[i]));
}
// add the rbmModelContainer elements
RbmModelContainer rbmModelContainer = param.getRbmModelContainer();
if (rbmModelContainer != null && !rbmModelContainer.isEmpty()) {
Element rbmModelContainerElement = getXML(rbmModelContainer);
{
// for testing purposes only
Document doc = new Document();
Element clone = (Element) rbmModelContainerElement.clone();
doc.setRootElement(clone);
String xmlString = XmlUtil.xmlToString(doc, false);
System.out.println(xmlString);
}
modelnode.addContent(rbmModelContainerElement);
}
// // Add rate rules
// if (param.getRateRuleVariables()!=null && param.getRateRuleVariables().length>0){
// modelnode.addContent( getXML(param.getRateRuleVariables()) );
// }
// Get Diagrams
Diagram[] diagarray = param.getDiagrams();
for (int i = 0; i < diagarray.length; i++) {
modelnode.addContent(getXML(diagarray[i]));
}
// Add Metadata information
if (param.getVersion() != null) {
modelnode.addContent(getXML(param.getVersion(), param));
}
// add model UnitSystem
ModelUnitSystem unitSystem = param.getUnitSystem();
if (unitSystem != null) {
modelnode.addContent(getXML(unitSystem));
}
return modelnode;
}
use of cbit.vcell.model.Diagram in project vcell by virtualcell.
the class DiagramTable method getDiagram.
/**
* This method was created in VisualAge.
* @return Model
* @param rset ResultSet
* @param log SessionLog
*/
public Diagram getDiagram(ResultSet rset, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException {
KeyValue key = new KeyValue(rset.getBigDecimal(id.toString()));
String mName = rset.getString(name.toString());
Diagram diagram = new Diagram(null, mName);
String languageString = DbDriver.varchar2_CLOB_get(rset, DiagramTable.table.diagramSmall, DiagramTable.table.diagramLarge, dbSyntax);
if (languageString == null || languageString.length() == 0) {
throw new DataAccessException("no data stored for Diagram");
}
// Is this needed?
// if (languageString.endsWith(";}\n")){
// StringBuffer buffer = new StringBuffer(languageString.substring(0,languageString.length()-2));
// buffer.append("\n}\n");
// languageString = buffer.toString();
// }
org.vcell.util.CommentStringTokenizer tokens = new org.vcell.util.CommentStringTokenizer(languageString);
try {
diagram.fromTokens(tokens);
} catch (Exception e) {
lg.error(e.getMessage(), e);
throw new DataAccessException(e.getMessage());
}
return diagram;
}
use of cbit.vcell.model.Diagram in project vcell by virtualcell.
the class ModelDbDriver method insertModel.
/**
* This method was created in VisualAge.
* @param model cbit.vcell.model.Model
*/
private void insertModel(InsertHashtable hash, Connection con, User user, Model model, Version newVersion) throws SQLException, DataAccessException, RecordChangedException {
//
// insert model record
//
insertModelSQL(con, user, model, newVersion);
hash.put(model, newVersion.getVersionKey());
//
// make sure all species are in the database and the hashtable
//
StructureTopology structureTopology = model.getStructureTopology();
ElectricalTopology electricalTopology = model.getElectricalTopology();
Species[] speciesArray = model.getSpecies();
for (int i = 0; i < speciesArray.length; i++) {
// speciesArray[i].getKey();
KeyValue speciesKey = null;
// if (speciesKey == null) {
speciesKey = reactStepDB.insertSpecies(hash, con, speciesArray[i], user);
// throw new DataAccessException("Database error: species "+species.getName()+" has null key");
// }else if (speciesArray[i].getOwnerKey()!=null && speciesArray[i].getOwnerKey()==user.getID()){
// reactStepDB.updateSpecies(con,speciesArray[i],user);
// }
// if (hash.getDatabaseKey(speciesArray[i])==null){
hash.put(speciesArray[i], speciesKey);
// }
}
//
// make sure all structures are in the database and the hashtable (add entry to link table)
// this does not populate the parent, negativeFeature, and positiveFeature columns ... done later with updateStructureKeys()
//
Structure[] structures = model.getStructures();
for (int i = 0; i < structures.length; i++) {
Structure structure = (Structure) structures[i];
KeyValue structureKey = null;
if (hash.getDatabaseKey(structure) == null) {
structureKey = reactStepDB.insertStructure(hash, con, structure);
}
KeyValue linkKey = keyFactory.getNewKey(con);
insertModelStructLinkSQL(con, linkKey, newVersion.getVersionKey(), /*modelKey*/
hash.getDatabaseKey(structure));
}
//
for (Structure structure : structures) {
KeyValue structKey = hash.getDatabaseKey(structure);
KeyValue parentKey = null;
Structure parentStruct = structureTopology.getParentStructure(structure);
if (parentStruct != null) {
parentKey = hash.getDatabaseKey(parentStruct);
}
KeyValue negKey = null;
KeyValue posKey = null;
if (structure instanceof Membrane) {
Membrane membrane = (Membrane) structure;
Feature negFeature = electricalTopology.getNegativeFeature(membrane);
if (negFeature != null) {
negKey = hash.getDatabaseKey(negFeature);
}
Feature posFeature = electricalTopology.getPositiveFeature(membrane);
if (posFeature != null) {
posKey = hash.getDatabaseKey(posFeature);
}
}
StructureKeys structureKeys = new StructureKeys(structKey, parentKey, posKey, negKey);
reactStepDB.updateStructureKeys(con, structureKeys);
}
//
// make sure all speciesContexts are in database and the hashtable
//
SpeciesContext[] speciesContexts = model.getSpeciesContexts();
for (int i = 0; i < speciesContexts.length; i++) {
SpeciesContext sc = speciesContexts[i];
if (hash.getDatabaseKey(sc) == null) {
insertSpeciesContextSQL(hash, con, keyFactory.getNewKey(con), sc, newVersion.getVersionKey());
}
}
//
// insert all reactionSteps
//
ReactionStep[] reactionSteps = model.getReactionSteps();
for (int i = 0; i < reactionSteps.length; i++) {
ReactionStep rs = reactionSteps[i];
if (hash.getDatabaseKey(rs) == null) {
reactStepDB.insertReactionStep(hash, con, user, rs, newVersion.getVersionKey());
}
}
//
// insert diagrams
//
Diagram[] diagrams = model.getDiagrams();
for (int i = 0; i < diagrams.length; i++) {
Diagram diagram = diagrams[i];
KeyValue key = keyFactory.getNewKey(con);
KeyValue structKey = hash.getDatabaseKey(diagram.getStructure());
if (structKey != null) {
insertDiagramSQL(con, key, diagram, newVersion.getVersionKey(), /*modelKey*/
hash.getDatabaseKey(diagram.getStructure()));
} else {
if (lg.isWarnEnabled())
lg.warn("ModelDbDriver.insertModel(), diagram " + diagram.toString() + " is orphaned, check Model logic");
}
}
//
// insert GlobalModelParameters
//
// //-----------------testing remove
// try{
// Model.ModelParameter testParam = model.new ModelParameter("test",new Expression("1.0"),Model.ROLE_UserDefined,VCUnitDefinition.UNIT_molecules);
// model.setModelParameters(new Model.ModelParameter[] {testParam});
// }catch(Exception e){
// e.printStackTrace();
// }
// //-----------------
GlobalModelParameterTable.table.insertModelParameters(con, keyFactory, model.getModelParameters(), newVersion.getVersionKey());
}
use of cbit.vcell.model.Diagram in project vcell by virtualcell.
the class ModelDbDriver method getDiagram.
/**
* This method was created in VisualAge.
* @return cbit.vcell.model.Diagram
* @param rset java.sql.ResultSet
*/
private Diagram getDiagram(QueryHashtable dbc, Connection con, ResultSet rset, StructureTopology structureTopology) throws SQLException, DataAccessException {
KeyValue structKey = new KeyValue(rset.getBigDecimal(diagramTable.structRef.toString()));
Diagram diagram = diagramTable.getDiagram(rset, dbSyntax);
diagram.setStructure(reactStepDB.getStructure(dbc, con, structKey));
return diagram;
}
use of cbit.vcell.model.Diagram in project vcell by virtualcell.
the class ModelDbDriver method getDiagramsFromModel.
/**
* getModels method comment.
*/
private cbit.vcell.model.Diagram[] getDiagramsFromModel(QueryHashtable dbc, Connection con, KeyValue modelKey, StructureTopology structureTopology, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException {
// log.print("ModelDbDriver.getDiagramsFromModel(modelKey=" + modelKey + ")");
String sql;
switch(dbSyntax) {
case ORACLE:
{
sql = " SELECT *" + " FROM " + diagramTable.getTableName() + "," + SoftwareVersionTable.table.getTableName() + " WHERE " + diagramTable.modelRef + " = " + modelKey + " AND " + diagramTable.modelRef + " = " + SoftwareVersionTable.table.versionableRef.getUnqualifiedColName() + "(+)" + " ORDER BY " + diagramTable.id.getQualifiedColName();
break;
}
case POSTGRES:
{
sql = " SELECT *" + " FROM " + diagramTable.getTableName() + " LEFT OUTER JOIN " + SoftwareVersionTable.table.getTableName() + " ON " + diagramTable.modelRef + " = " + SoftwareVersionTable.table.versionableRef.getUnqualifiedColName() + " WHERE " + diagramTable.modelRef + " = " + modelKey + // " AND " + diagramTable.modelRef + " = " + SoftwareVersionTable.table.versionableRef.getUnqualifiedColName() +"(+)" +
" ORDER BY " + diagramTable.id.getQualifiedColName();
break;
}
default:
{
throw new RuntimeException("unexpected DatabaseSyntax " + dbSyntax);
}
}
Statement stmt = con.createStatement();
Vector<Diagram> diagramList = new Vector<Diagram>();
String softwareVersion = null;
try {
ResultSet rset = stmt.executeQuery(sql);
//
while (rset.next()) {
Diagram diagram = getDiagram(dbc, con, rset, structureTopology);
diagramList.addElement(diagram);
softwareVersion = rset.getString(SoftwareVersionTable.table.softwareVersion.getUnqualifiedColName());
if (rset.wasNull()) {
softwareVersion = null;
}
}
} finally {
// Release resources include resultset
stmt.close();
}
//
// put results in an array
//
Diagram[] diagramArray = new Diagram[diagramList.size()];
diagramList.copyInto(diagramArray);
VCellSoftwareVersion vCellSoftwareVersion = VCellSoftwareVersion.fromString(softwareVersion);
XmlReader.reorderDiagramsInPlace_UponRead(vCellSoftwareVersion, diagramArray, structureTopology);
// //----------------------------------------
return diagramArray;
}
Aggregations