Search in sources :

Example 36 with ExpressionBindingException

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());
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) StructureSize(cbit.vcell.model.Structure.StructureSize) MolecularType(org.vcell.model.rbm.MolecularType) PropertyVetoException(java.beans.PropertyVetoException) MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage) Expression(cbit.vcell.parser.Expression)

Example 37 with ExpressionBindingException

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();
    }
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) MembraneMapping(cbit.vcell.mapping.MembraneMapping) KeyValue(org.vcell.util.document.KeyValue) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) StructureMapping(cbit.vcell.mapping.StructureMapping) BigDecimal(java.math.BigDecimal) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) DependencyException(org.vcell.util.DependencyException) RecordChangedException(cbit.sql.RecordChangedException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) PropertyVetoException(java.beans.PropertyVetoException) FeatureMapping(cbit.vcell.mapping.FeatureMapping) Expression(cbit.vcell.parser.Expression) ResultSet(java.sql.ResultSet) Structure(cbit.vcell.model.Structure) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)37 Expression (cbit.vcell.parser.Expression)26 ExpressionException (cbit.vcell.parser.ExpressionException)16 PropertyVetoException (java.beans.PropertyVetoException)15 Vector (java.util.Vector)8 MathException (cbit.vcell.math.MathException)7 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)7 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)7 ArrayList (java.util.ArrayList)7 VCUnitException (cbit.vcell.units.VCUnitException)6 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)5 ModelParameter (cbit.vcell.model.Model.ModelParameter)5 SpeciesContext (cbit.vcell.model.SpeciesContext)5 Issue (org.vcell.util.Issue)5 ModelException (cbit.vcell.model.ModelException)4 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)4 Structure (cbit.vcell.model.Structure)4 Element (org.jdom.Element)4 ScopedExpression (cbit.gui.ScopedExpression)3 SubVolume (cbit.vcell.geometry.SubVolume)3