use of cbit.vcell.parser.ExpressionBindingException in project vcell by virtualcell.
the class Model method propertyChange.
/**
* This method gets called when a bound property is changed.
* @param evt A PropertyChangeEvent object describing the event source
* and the property that has changed.
*/
public void propertyChange(java.beans.PropertyChangeEvent evt) {
if (evt.getSource() instanceof ReactionStep && evt.getPropertyName().equals("kinetics")) {
Kinetics oldKinetics = (Kinetics) evt.getOldValue();
Kinetics newKinetics = (Kinetics) evt.getNewValue();
if (oldKinetics != null) {
oldKinetics.removePropertyChangeListener(this);
oldKinetics.removeVetoableChangeListener(this);
}
if (newKinetics != null) {
newKinetics.addPropertyChangeListener(this);
newKinetics.addVetoableChangeListener(this);
}
}
if (evt.getSource() instanceof SpeciesContext && evt.getPropertyName().equals("name")) {
for (int i = 0; i < fieldDiagrams.length; i++) {
fieldDiagrams[i].renameNode((String) evt.getOldValue(), (String) evt.getNewValue());
}
}
if (evt.getSource() instanceof ReactionStep && evt.getPropertyName().equals("name")) {
for (int i = 0; i < fieldDiagrams.length; i++) {
fieldDiagrams[i].renameNode((String) evt.getOldValue(), (String) evt.getNewValue());
}
}
// if we can't find any candidate or we find too many candidates we wisely (and silently) do nothing
if (evt.getSource() instanceof MolecularType && evt.getPropertyName().equals("name")) {
List<RbmObservable> candidates = new ArrayList<RbmObservable>();
String oldName = (String) evt.getOldValue();
String newName = (String) evt.getNewValue();
for (RbmObservable candidate : getRbmModelContainer().getObservableList()) {
if (candidate.getName().contains(oldName) && candidate.getName().startsWith("O") && candidate.getName().endsWith("_tot")) {
candidates.add(candidate);
}
}
if (candidates.isEmpty()) {
System.out.println("no candidates to rename");
} else if (candidates.size() > 1) {
System.out.println("too many candidates to rename");
} else {
RbmObservable candidate = candidates.get(0);
System.out.println("renaming --- " + candidate.getName());
try {
String prefix = candidate.getName().substring(0, candidate.getName().indexOf("_"));
candidate.setName(prefix + "_" + newName + "_tot");
} catch (PropertyVetoException e) {
System.out.println("Cannot rename observable " + candidate.getName() + ", " + e.getMessage());
e.printStackTrace();
}
}
}
//
if ((evt.getSource() instanceof ModelParameter || evt.getSource() instanceof SpeciesContext || evt.getSource() instanceof RbmObservable || evt.getSource() instanceof MembraneVoltage || evt.getSource() instanceof StructureSize) && evt.getPropertyName().equals("name")) {
for (int i = 0; i < fieldModelParameters.length; i++) {
try {
Expression exp = fieldModelParameters[i].getExpression();
Expression renamedExp = exp.renameBoundSymbols(getNameScope());
if (!renamedExp.compareEqual(exp)) {
fieldModelParameters[i].setExpression(renamedExp);
}
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
}
}
}
use of cbit.vcell.parser.ExpressionBindingException in project vcell by virtualcell.
the class SimulationContextDbDriver method assignStructureMappingsSQL.
/**
* This method was created in VisualAge.
* @param simContext cbit.vcell.mapping.SimulationContext
*/
private void assignStructureMappingsSQL(QueryHashtable dbc, Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
String sql;
sql = " SELECT " + "*" + " FROM " + structureMappingTable.getTableName() + " WHERE " + structureMappingTable.simContextRef + " = " + simContextKey;
Statement stmt = con.createStatement();
try {
// log.print(sql);
ResultSet rset = stmt.executeQuery(sql);
while (rset.next()) {
BigDecimal subvolumeRefBigDecimal = rset.getBigDecimal(structureMappingTable.subVolumeRef.toString());
KeyValue subVolumeRef = (subvolumeRefBigDecimal == null ? null : new KeyValue(subvolumeRefBigDecimal));
BigDecimal surfaceClassRefBigDecimal = rset.getBigDecimal(structureMappingTable.surfaceClassRef.toString());
KeyValue surfaceClassRef = (surfaceClassRefBigDecimal == null ? null : new KeyValue(surfaceClassRefBigDecimal));
KeyValue structureRef = new KeyValue(rset.getBigDecimal(structureMappingTable.structRef.toString()));
//
// lookup structure and subVolume from SimulationContext by their keys
//
// DBCache will not always give same instance consistently (usually this is
// fixed up later in the ReferenceResolver at the Client).
//
Structure theStructure = null;
Structure[] structureArray = simContext.getModel().getStructures();
for (int i = 0; i < structureArray.length; i++) {
Structure structure = structureArray[i];
if (structure.getKey().compareEqual(structureRef)) {
theStructure = structure;
break;
}
}
if (theStructure == null) {
throw new DataAccessException("Can't match structure and subvolume");
}
GeometryClass theGeometryClass = null;
KeyValue geometryClassKey = (subVolumeRef == null ? surfaceClassRef : subVolumeRef);
if (geometryClassKey != null) {
GeometryClass[] geometryClasses = simContext.getGeometry().getGeometryClasses();
for (int i = 0; i < geometryClasses.length; i++) {
if (geometryClasses[i].getKey().compareEqual(geometryClassKey)) {
theGeometryClass = geometryClasses[i];
break;
}
}
if (theGeometryClass == null) {
throw new DataAccessException("Can't find Geometryclass");
}
}
Expression sizeExpression = null;
String sizeExpressionS = rset.getString(StructureMappingTable.table.sizeExp.getUnqualifiedColName());
if (!rset.wasNull() && sizeExpressionS != null && sizeExpressionS.length() > 0) {
try {
sizeExpressionS = TokenMangler.getSQLRestoredString(sizeExpressionS);
sizeExpression = new Expression(sizeExpressionS);
} catch (ExpressionException e) {
e.printStackTrace();
throw new DataAccessException("SimulationContextDbDriver.assignStructureMappingSQL : Couldn't parse non-null size expression for Structure " + theStructure.getName());
}
}
StructureMapping sm = simContext.getGeometryContext().getStructureMapping(theStructure);
try {
sm.getSizeParameter().setExpression(sizeExpression);
} catch (Exception e1) {
throw new DataAccessException("SimulationContextDbDriver.assignStructureMappingSQL : Couldn't set size expression '" + sizeExpressionS + "'for Structure " + theStructure.getName());
}
try {
sm.setGeometryClass(theGeometryClass);
} catch (PropertyVetoException e) {
lg.error(e.getMessage(), e);
throw new DataAccessException(e.getMessage());
}
if (sm instanceof FeatureMapping) {
FeatureMapping fm = (FeatureMapping) sm;
String boundaryTypeXmString = rset.getString(structureMappingTable.boundaryTypeXm.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeXm(new BoundaryConditionType(boundaryTypeXmString));
}
String boundaryTypeXpString = rset.getString(structureMappingTable.boundaryTypeXp.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeXp(new BoundaryConditionType(boundaryTypeXpString));
}
String boundaryTypeYmString = rset.getString(structureMappingTable.boundaryTypeYm.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeYm(new BoundaryConditionType(boundaryTypeYmString));
}
String boundaryTypeYpString = rset.getString(structureMappingTable.boundaryTypeYp.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeYp(new BoundaryConditionType(boundaryTypeYpString));
}
String boundaryTypeZmString = rset.getString(structureMappingTable.boundaryTypeZm.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeZm(new BoundaryConditionType(boundaryTypeZmString));
}
String boundaryTypeZpString = rset.getString(structureMappingTable.boundaryTypeZp.toString());
if (!rset.wasNull()) {
fm.setBoundaryConditionTypeZp(new BoundaryConditionType(boundaryTypeZpString));
}
String volPerUnitArea = rset.getString(structureMappingTable.volPerUnitAreaExp.toString());
if (!rset.wasNull()) {
try {
fm.getVolumePerUnitAreaParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(volPerUnitArea)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
String volPerUnitVol = rset.getString(structureMappingTable.volPerUnitVolExp.toString());
if (!rset.wasNull()) {
try {
fm.getVolumePerUnitVolumeParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(volPerUnitVol)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
} else if (sm instanceof MembraneMapping) {
MembraneMapping mm = (MembraneMapping) sm;
String surfToVolString = rset.getString(structureMappingTable.surfToVolExp.toString());
if (!rset.wasNull()) {
try {
mm.getSurfaceToVolumeParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(surfToVolString)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
String volFractString = rset.getString(structureMappingTable.volFractExp.toString());
if (!rset.wasNull()) {
try {
mm.getVolumeFractionParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(volFractString)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in volFract expression: " + e.getMessage());
}
}
boolean bCalculateVoltage = rset.getBoolean(structureMappingTable.bCalculateVoltage.toString());
if (!rset.wasNull()) {
mm.setCalculateVoltage(bCalculateVoltage);
}
java.math.BigDecimal specificCapacitance = rset.getBigDecimal(structureMappingTable.specificCap.toString());
if (!rset.wasNull()) {
try {
mm.getSpecificCapacitanceParameter().setExpression(new Expression(specificCapacitance.doubleValue()));
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
throw new DataAccessException("error setting membrane specific capacitance: " + e.getMessage());
}
}
String initialVoltageString = rset.getString(structureMappingTable.initialVoltage.toString());
if (!rset.wasNull()) {
try {
mm.getInitialVoltageParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(initialVoltageString)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("database parse error in initial membrane voltage: " + e.getMessage());
}
}
String areaPerUnitArea = rset.getString(structureMappingTable.areaPerUnitAreaExp.toString());
if (!rset.wasNull()) {
try {
mm.getAreaPerUnitAreaParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(areaPerUnitArea)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
String areaPerUnitVol = rset.getString(structureMappingTable.areaPerUnitVolExp.toString());
if (!rset.wasNull()) {
try {
mm.getAreaPerUnitVolumeParameter().setExpression(new Expression(TokenMangler.getSQLRestoredString(areaPerUnitVol)));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new DataAccessException("parse error in surfaceToVol expression: " + e.getMessage());
}
}
} else {
throw new DataAccessException("unknown structureMapping type");
}
// System.out.println("Structure Key = " + theStructure + " - " + "SubVolume Key " + theSubVolume.getKey());
}
} finally {
stmt.close();
}
}
Aggregations