use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class XmlReader method getGeometry.
/**
* This method returns a Geometry object from a XML representation.
* Creation date: (4/26/2001 12:12:18 PM)
* @return cbit.vcell.geometry.Geometry
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
public Geometry getGeometry(Element param) throws XmlParseException {
// Get the Extent object
Extent newextent = getExtent(param.getChild(XMLTags.ExtentTag, vcNamespace));
// Get VCimage information
VCImage newimage = null;
if (param.getChild(XMLTags.ImageTag, vcNamespace) != null) {
try {
newimage = getVCImage(param.getChild(XMLTags.ImageTag, vcNamespace), newextent);
} catch (Throwable e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
// Get attributes
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
int newdimension = Integer.parseInt(param.getAttributeValue(XMLTags.DimensionAttrTag));
// Get Version
Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
// Try to construct the geometry upon four different cases
Geometry newgeometry = null;
if (version != null && newimage != null) {
newgeometry = new Geometry(version, newimage);
} else if (version != null) {
newgeometry = new Geometry(version, newdimension);
} else if (newimage != null) {
newgeometry = new Geometry(name, newimage);
} else {
newgeometry = new Geometry(name, newdimension);
}
// set attributes
try {
if (!newgeometry.getName().equalsIgnoreCase(name)) {
newgeometry.setName(name);
}
// String annotation = param.getAttributeValue(XMLTags.AnnotationAttrTag);
// if (annotation!=null) {
// newgeometry.setDescription( unMangle(annotation) );
// }
// Add annotation
String annotation = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotation != null && annotation.length() > 0) {
newgeometry.setDescription(unMangle(annotation));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException occurred when setting the name " + name + " to a Geometry object!", e);
}
// Add the Extent
try {
newgeometry.getGeometrySpec().setExtent(newextent);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException occurred while trying to set the Extent for the Geometry " + name, e);
}
// Add the Origin
newgeometry.getGeometrySpec().setOrigin(getOrigin(param.getChild(XMLTags.OriginTag, vcNamespace)));
// Add the SubVolumes
List<Element> children = param.getChildren(XMLTags.SubVolumeTag, vcNamespace);
SubVolume[] newsubvolumes = new SubVolume[children.size()];
int subvolumeCounter = 0;
for (Element child : children) {
newsubvolumes[subvolumeCounter] = getSubVolume(child);
subvolumeCounter++;
}
try {
newgeometry.getGeometrySpec().setSubVolumes(newsubvolumes);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException was generated when ading the subvolumes to the Geometry " + name, e);
}
if (newgeometry.getDimension() > 0) {
// Add SurfaceClasses
List<Element> surfaceClassChildren = param.getChildren(XMLTags.SurfaceClassTag, vcNamespace);
SurfaceClass[] newSurfaceClassArr = new SurfaceClass[surfaceClassChildren.size()];
int surfClassCounter = 0;
for (Element surfClassChild : surfaceClassChildren) {
newSurfaceClassArr[surfClassCounter] = getSurfaceClass(surfClassChild, newgeometry);
surfClassCounter++;
}
try {
newgeometry.getGeometrySurfaceDescription().setSurfaceClasses(newSurfaceClassArr);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException was generated when ading the subvolumes to the Geometry " + name, e);
}
}
// read Filaments (if any)
Iterator<Element> iterator = param.getChildren(XMLTags.FilamentTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempElement = iterator.next();
String filname = unMangle(tempElement.getAttributeValue(XMLTags.NameAttrTag));
Iterator<Element> curveiterator = tempElement.getChildren().iterator();
while (curveiterator.hasNext()) {
ControlPointCurve curve = getControlPointCurve(curveiterator.next());
newgeometry.getGeometrySpec().getFilamentGroup().addCurve(filname, curve);
}
}
// read Surface description (if any)
Element sd = param.getChild(XMLTags.SurfaceDescriptionTag, vcNamespace);
if (sd != null) {
GeometrySurfaceDescription dummy = getGeometrySurfaceDescription(sd, newgeometry);
}
try {
newgeometry.precomputeAll(new GeometryThumbnailImageFactoryAWT(), false, false);
} catch (GeometryException e) {
e.printStackTrace(System.out);
} catch (ImageException e) {
e.printStackTrace(System.out);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
return newgeometry;
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class XmlReader method getMathModel.
/*
public RateRuleVariable[] getRateRuleVariables(Element rateRuleVarsElement, Model model) throws XmlParseException {
Iterator<Element> rateRuleVarsIterator = rateRuleVarsElement.getChildren(XMLTags.RateRuleVariableTag, vcNamespace).iterator();
Vector<RateRuleVariable> rateRuleVarsVector = new Vector<RateRuleVariable>();
while (rateRuleVarsIterator.hasNext()) {
Element rrvElement = (Element) rateRuleVarsIterator.next();
RateRuleVariable newRateRuleVar = null;
try {
String rrvName = unMangle(rrvElement.getAttributeValue(XMLTags.NameAttrTag));
String rrvStructureName = unMangle(rrvElement.getAttributeValue(XMLTags.StructureAttrTag));
// structure can be null
Structure rrvStructure = null;
if (rrvStructureName != null) {
rrvStructure = (Structure) model.getStructure(rrvStructureName);
}
// if (structureref == null) {
// throw new XmlParseException("The structure " + rrvStructureName + "could not be resolved!");
// }
String rrvRoleStr = rrvElement.getAttributeValue(XMLTags.ParamRoleAttrTag);
int rrvRole = RateRuleVariable.getParamRoleFromDesc(rrvRoleStr);
Element rrvParamElement = rrvElement.getChild(XMLTags.ParameterTag, vcNamespace);
ModelParameter rrvParameter = getModelParameter(rrvParamElement, model);
newRateRuleVar = new RateRuleVariable(rrvName, rrvStructure, rrvParameter, rrvRole);
newRateRuleVar.bind();
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e.getMessage());
}
if (newRateRuleVar != null) {
rateRuleVarsVector.add(newRateRuleVar);
}
}
return ((RateRuleVariable[])BeanUtils.getArray(rateRuleVarsVector, RateRuleVariable.class));
}
*/
/**
* This method returns a MathModel object from a XML Element.
* Creation date: (3/13/2001 12:35:00 PM)
* @return cbit.vcell.mathmodel.MathModel
* @param param org.jdom.Element
*/
public MathModel getMathModel(Element param) throws XmlParseException {
// Create it
// set Metadata (version), if any
Version versionObject = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
MathModel mathmodel = new MathModel(versionObject);
// Set attributes
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
try {
mathmodel.setName(name);
// String annotation = param.getAttributeValue(XMLTags.AnnotationAttrTag);
// if (annotation!=null) {
// mathmodel.setDescription(unMangle(annotation));
// }
// Add annotation
String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotationText != null && annotationText.length() > 0) {
mathmodel.setDescription(unMangle(annotationText));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("An error occurred while trying to set the name " + param.getAttributeValue(XMLTags.NameAttrTag) + "to a MathModel!", e);
}
// set Geometry (if any)
Element tempElem = param.getChild(XMLTags.GeometryTag, vcNamespace);
Geometry tempGeometry = getGeometry(tempElem);
// set MathDescription
tempElem = param.getChild(XMLTags.MathDescriptionTag, vcNamespace);
MathDescription mathDesc = getMathDescription(tempElem, tempGeometry);
if (tempElem != null) {
mathmodel.setMathDescription(mathDesc);
} else {
throw new XmlParseException("MathDescription missing in this MathModel!");
}
// set output functions (outputfunctionContext)
Element outputFunctionsElement = param.getChild(XMLTags.OutputFunctionsTag, vcNamespace);
if (outputFunctionsElement != null) {
ArrayList<AnnotatedFunction> outputFunctions = getOutputFunctions(outputFunctionsElement);
try {
// construct OutputFnContext from mathmodel and add output functions that were read in from XML.
OutputFunctionContext outputFnContext = mathmodel.getOutputFunctionContext();
for (AnnotatedFunction outputFunction : outputFunctions) {
outputFnContext.addOutputFunction(outputFunction);
}
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
}
// Set simulations contexts (if any)
List<Element> childList = param.getChildren(XMLTags.SimulationTag, vcNamespace);
Simulation[] simList = new Simulation[childList.size()];
int simCounter = 0;
for (Element simElement : childList) {
simList[simCounter] = getSimulation(simElement, mathDesc);
simCounter++;
}
try {
mathmodel.setSimulations(simList);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException occurred when adding the Simulations to the MathModel " + name, e);
}
return mathmodel;
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class XmlReader method getMeshSpecification.
/**
* This method returns a MeshSpecification object from a XML Element.
* Creation date: (5/22/2001 12:05:21 PM)
* @return cbit.vcell.mesh.MeshSpecification
* @param param org.jdom.Element
*/
private MeshSpecification getMeshSpecification(Element param, Geometry geometry) throws XmlParseException {
// *** create new MeshSpecification ***
MeshSpecification meshSpec = new MeshSpecification(geometry);
// get ISize
Element size = param.getChild(XMLTags.SizeTag, vcNamespace);
int x = Integer.parseInt(size.getAttributeValue(XMLTags.XAttrTag));
int y = Integer.parseInt(size.getAttributeValue(XMLTags.YAttrTag));
int z = Integer.parseInt(size.getAttributeValue(XMLTags.ZAttrTag));
ISize newsize = new ISize(x, y, z);
// set ISize
try {
meshSpec.setSamplingSize(newsize);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException was fired when setting the ISize object to a new MeshSpecification", e);
}
return meshSpec;
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class XmlReader method getImageSubVolume.
/**
* This method returns an ImageSubVolume object from a XML representation.
* Creation date: (5/1/2001 5:26:17 PM)
* @return cbit.vcell.geometry.ImageSubVolume
* @param param org.jdom.Element
*/
private ImageSubVolume getImageSubVolume(Element param) throws XmlParseException {
// retrieve the attributes
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
int handle = Integer.parseInt(param.getAttributeValue(XMLTags.HandleAttrTag));
int imagePixelValue = Integer.parseInt(param.getAttributeValue(XMLTags.ImagePixelValueTag));
// Get the PixelClass from image (image should be a sibling of this subVolume element)
Element imageElement = ((Element) param.getParent()).getChild(XMLTags.ImageTag, vcNamespace);
if (imageElement == null) {
throw new XmlParseException("image not found in geometry corresponding to ImageSubVolume");
}
List<Element> pixelClassList = imageElement.getChildren(XMLTags.PixelClassTag, vcNamespace);
VCPixelClass pixelClass = null;
for (Element pixelClassElement : pixelClassList) {
VCPixelClass pc = getPixelClass(pixelClassElement);
if (pc.getPixel() == imagePixelValue) {
pixelClass = pc;
}
}
if (pixelClass == null) {
throw new XmlParseException("image pixelclass(pixel=" + imagePixelValue + ") not found while creating ImageSubVolume " + name);
}
// retrieve the key if there is one
KeyValue key = null;
String stringkey = param.getAttributeValue(XMLTags.KeyValueAttrTag);
if (stringkey != null && stringkey.length() > 0 && this.readKeysFlag) {
key = new KeyValue(stringkey);
}
// Create the new Image SubVolume
ImageSubVolume newsubvolume = new ImageSubVolume(key, pixelClass, handle);
// set name
try {
newsubvolume.setName(name);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A propertyVetoException was generated when setting the name " + name + " to an ImageSubvolume object!", e);
}
return newsubvolume;
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class XmlReader method getFluxReaction.
/**
* This method returns a FluxReaction object from a XML element.
* Creation date: (3/16/2001 11:52:02 AM)
* @return cbit.vcell.model.FluxReaction
* @param param org.jdom.Element
* @throws XmlParseException
* @throws PropertyVetoException
* @throws ModelException
* @throws Exception
*/
private FluxReaction getFluxReaction(Element param, Model model) throws XmlParseException, PropertyVetoException {
// retrieve the key if there is one
KeyValue key = null;
String keystring = param.getAttributeValue(XMLTags.KeyValueAttrTag);
if (keystring != null && keystring.length() > 0 && this.readKeysFlag) {
key = new KeyValue(keystring);
}
// resolve reference to the Membrane
String structureName = unMangle(param.getAttributeValue(XMLTags.StructureAttrTag));
Membrane structureref = (Membrane) model.getStructure(structureName);
if (structureref == null) {
throw new XmlParseException("The membrane " + structureName + " could not be resolved in the dictionnary!");
}
// -- Instantiate new FluxReaction --
FluxReaction fluxreaction = null;
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String reversibleAttributeValue = param.getAttributeValue(XMLTags.ReversibleAttrTag);
boolean bReversible = true;
if (reversibleAttributeValue != null) {
if (Boolean.TRUE.toString().equals(reversibleAttributeValue)) {
bReversible = true;
} else if (Boolean.FALSE.toString().equals(reversibleAttributeValue)) {
bReversible = false;
} else {
throw new RuntimeException("unexpected value " + reversibleAttributeValue + " for reversible flag for reaction " + name);
}
}
try {
fluxreaction = new FluxReaction(model, structureref, key, name, bReversible);
fluxreaction.setModel(model);
} catch (Exception e) {
e.printStackTrace();
throw new XmlParseException("An exception occurred while trying to create the FluxReaction " + name, e);
}
// resolve reference to the fluxCarrier
if (param.getAttribute(XMLTags.FluxCarrierAttrTag) != null) {
String speciesname = unMangle(param.getAttributeValue(XMLTags.FluxCarrierAttrTag));
Species specieref = model.getSpecies(speciesname);
if (specieref != null) {
Feature insideFeature = model.getStructureTopology().getInsideFeature(structureref);
try {
if (insideFeature != null) {
SpeciesContext insideSpeciesContext = model.getSpeciesContext(specieref, insideFeature);
fluxreaction.addProduct(insideSpeciesContext, 1);
}
Feature outsideFeature = model.getStructureTopology().getOutsideFeature(structureref);
if (outsideFeature != null) {
SpeciesContext outsideSpeciesContext = model.getSpeciesContext(specieref, outsideFeature);
fluxreaction.addReactant(outsideSpeciesContext, 1);
}
} catch (ModelException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e.getMessage());
}
}
}
// Annotation
// String rsAnnotation = null;
// String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
// if (annotationText!=null && annotationText.length()>0) {
// rsAnnotation = unMangle(annotationText);
// }
// fluxreaction.setAnnotation(rsAnnotation);
// set the fluxOption
String fluxOptionString = null;
fluxOptionString = param.getAttributeValue(XMLTags.FluxOptionAttrTag);
if (fluxOptionString != null && fluxOptionString.length() > 0) {
try {
if (fluxOptionString.equals(XMLTags.FluxOptionElectricalOnly)) {
fluxreaction.setPhysicsOptions(FluxReaction.PHYSICS_ELECTRICAL_ONLY);
} else if (fluxOptionString.equals(XMLTags.FluxOptionMolecularAndElectrical)) {
fluxreaction.setPhysicsOptions(FluxReaction.PHYSICS_MOLECULAR_AND_ELECTRICAL);
} else if (fluxOptionString.equals(XMLTags.FluxOptionMolecularOnly)) {
fluxreaction.setPhysicsOptions(FluxReaction.PHYSICS_MOLECULAR_ONLY);
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException("A propertyVetoException was fired when setting the fluxOption to the flux reaction " + name, e);
}
}
// Add Reactants, if any
try {
Iterator<Element> iterator = param.getChildren(XMLTags.ReactantTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element temp = iterator.next();
// Add Reactant to this SimpleReaction
fluxreaction.addReactionParticipant(getReactant(temp, fluxreaction, model));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("Error adding a reactant to the reaction " + name + " : " + e.getMessage());
}
// Add Products, if any
try {
Iterator<Element> iterator = param.getChildren(XMLTags.ProductTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element temp = iterator.next();
// Add Product to this simplereaction
fluxreaction.addReactionParticipant(getProduct(temp, fluxreaction, model));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("Error adding a product to the reaction " + name + " : " + e.getMessage());
}
// Add Catalyst(Modifiers) (if there are)
Iterator<Element> iterator = param.getChildren(XMLTags.CatalystTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element temp = iterator.next();
fluxreaction.addReactionParticipant(getCatalyst(temp, fluxreaction, model));
}
// Add Kinetics
fluxreaction.setKinetics(getKinetics(param.getChild(XMLTags.KineticsTag, vcNamespace), fluxreaction, model));
// set the valence (for legacy support for "chargeCarrierValence" stored with reaction).
String valenceString = null;
try {
valenceString = unMangle(param.getAttributeValue(XMLTags.FluxCarrierValenceAttrTag));
if (valenceString != null && valenceString.length() > 0) {
KineticsParameter chargeValenceParameter = fluxreaction.getKinetics().getChargeValenceParameter();
if (chargeValenceParameter != null) {
chargeValenceParameter.setExpression(new Expression(Integer.parseInt(unMangle(valenceString))));
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
throw new XmlParseException("A NumberFormatException was fired when setting the (integer) valence '" + valenceString + "' (integer) to the flux reaction " + name, e);
}
return fluxreaction;
}
Aggregations