|
From: <luc...@us...> - 2013-07-29 23:37:12
|
Revision: 18273
http://sourceforge.net/p/sbml/code/18273
Author: luciansmith
Date: 2013-07-29 23:37:09 +0000 (Mon, 29 Jul 2013)
Log Message:
-----------
* Updates to flattening to change error messages to talk about what the error is for, and what the name of the function is that's throwing the error.
* Include CompSBMLError.h in CompExtensionTypes
* Fix a couple tests, since the way we throw comp tests has changed a little.
* Fixes/efficiency changes to some error message checks.
* Fix some error messages to not hide the return values.
* 'fbc' -> 'comp'
* Many changes from CompFlatModelNotValid to CompFlatteningFailed, since the latter was more accurate.
* ReplacedBy 'updateIDs' function added to check consistent IDs properly, and in the proper order.
* Changed "1, 3, 1" -> 'getPackageVersion, getLevel, getVersion'
* Fixed the error messages/logic in SBaseRef::getReferencedElementFrom so that it works for all subclasses.
* In the flattening converter, we set things up to tell people that flattening errors came from flattening.
* Fixed test model 'test8' so that it doesn't violate the newly-noticed ID consistency errors for replacedBy elements.
* Fixes to ExtModelReferenceCycles::addAllReferences to stop crashes.
Modified Paths:
--------------
trunk/libsbml/src/sbml/packages/comp/common/CompExtensionTypes.h
trunk/libsbml/src/sbml/packages/comp/extension/CompModelPlugin.cpp
trunk/libsbml/src/sbml/packages/comp/extension/test/TestCheckConsistency.cpp
trunk/libsbml/src/sbml/packages/comp/sbml/Deletion.cpp
trunk/libsbml/src/sbml/packages/comp/sbml/ExternalModelDefinition.cpp
trunk/libsbml/src/sbml/packages/comp/sbml/Port.cpp
trunk/libsbml/src/sbml/packages/comp/sbml/ReplacedBy.cpp
trunk/libsbml/src/sbml/packages/comp/sbml/ReplacedBy.h
trunk/libsbml/src/sbml/packages/comp/sbml/ReplacedElement.cpp
trunk/libsbml/src/sbml/packages/comp/sbml/Replacing.cpp
trunk/libsbml/src/sbml/packages/comp/sbml/SBaseRef.cpp
trunk/libsbml/src/sbml/packages/comp/sbml/Submodel.cpp
trunk/libsbml/src/sbml/packages/comp/util/CompFlatteningConverter.cpp
trunk/libsbml/src/sbml/packages/comp/util/test/TestCompFlatteningConverter.cpp
trunk/libsbml/src/sbml/packages/comp/util/test/TestRunner.c
trunk/libsbml/src/sbml/packages/comp/util/test/test-data/test8.xml
trunk/libsbml/src/sbml/packages/comp/validator/CompSBMLErrorTable.h
trunk/libsbml/src/sbml/packages/comp/validator/constraints/CompConsistencyConstraints.cpp
trunk/libsbml/src/sbml/packages/comp/validator/constraints/ExtModelReferenceCycles.cpp
Added Paths:
-----------
trunk/libsbml/src/sbml/packages/comp/util/test/TestCompFlatteningErrorMessages.cpp
trunk/libsbml/src/sbml/packages/comp/util/test/test-data/subdir/badextmod.xml
trunk/libsbml/src/sbml/packages/comp/util/test/test-data/subdir/empty-comp.xml
trunk/libsbml/src/sbml/packages/comp/util/test/test-data/subdir/empty.xml
trunk/libsbml/src/sbml/packages/comp/util/test/test-data/subdir/level2.xml
trunk/libsbml/src/sbml/packages/comp/util/test/test-data/subdir/model.txt
trunk/libsbml/src/sbml/packages/comp/util/test/test-data/subdir/onemod.xml
trunk/libsbml/src/sbml/packages/comp/util/test/test-data/subdir/onemodnamed.xml
Modified: trunk/libsbml/src/sbml/packages/comp/common/CompExtensionTypes.h
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/common/CompExtensionTypes.h 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/common/CompExtensionTypes.h 2013-07-29 23:37:09 UTC (rev 18273)
@@ -43,4 +43,5 @@
#include <sbml/packages/comp/sbml/ReplacedBy.h>
#include <sbml/packages/comp/sbml/SBaseRef.h>
#include <sbml/packages/comp/sbml/Submodel.h>
+#include <sbml/packages/comp/validator/CompSBMLError.h>
#endif /* CompExtensionTypes_h */
Modified: trunk/libsbml/src/sbml/packages/comp/extension/CompModelPlugin.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/extension/CompModelPlugin.cpp 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/extension/CompModelPlugin.cpp 2013-07-29 23:37:09 UTC (rev 18273)
@@ -522,8 +522,8 @@
}
success = flat->appendFrom(submodel);
if (success != LIBSBML_OPERATION_SUCCESS) {
- string error = "The submodel '" + submodel->getId() + "' could not be used to create the flattened model: appending the elements of the submodel to the elements of the parent model failed.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "Unable to flatten model in CompModelPlugin::flattenModel: appending elements from the submodel '" + submodel->getId() + "' to the elements of the parent model failed.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
delete flat;
return NULL;
}
@@ -704,8 +704,8 @@
Model* model = static_cast<Model*>(getParentSBMLObject());
if (model==NULL) {
if (doc) {
- string error = "No Model parent of the 'comp' model plugin.";
- doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, 1, 3, 1, error);
+ string error = "Unable to discover any referenced elements in CompModelPlugin::saveAllReferencedElements: no Model parent of the 'comp' model plugin.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
@@ -755,8 +755,8 @@
Model* model = static_cast<Model*>(getParentSBMLObject());
if (model==NULL) {
if (doc) {
- string error = "No parent model could be found for the given 'comp' model plugin element.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "Unable to rename elements in CompModelPlugin::renameAllIDsAndPrepend: no parent model could be found for the given 'comp' model plugin element.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_INVALID_OBJECT;
}
@@ -769,15 +769,15 @@
if (subm==NULL) {
if (doc) {
stringstream error;
- error << "No valid submodel number " << sm << "for model " << model->getId();
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error.str());
+ error << "Unable to rename elements in CompModelPlugin::renameAllIDsAndPrepend: no valid submodel number " << sm << "for model " << model->getId();
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, 1, 3, 1, error.str());
}
return LIBSBML_OPERATION_FAILED;
}
if (!subm->isSetId()) {
if (doc) {
stringstream error;
- error << "Submodel number " << sm << "for model " << model->getId() << " is invalid: it has no 'id' attribute set.";
+ error << "Unable to rename elements in CompModelPlugin::renameAllIDsAndPrepend: submodel number " << sm << "for model " << model->getId() << " is invalid: it has no 'id' attribute set.";
doc->getErrorLog()->logPackageError("comp", CompSubmodelAllowedAttributes, 1, 3, 1, error.str());
}
return LIBSBML_INVALID_OBJECT;
@@ -801,8 +801,8 @@
if (instp==NULL) {
if (doc) {
//Shouldn't happen: 'getInstantiation' turns on the comp plugin.
- string error = "No valid 'comp' plugin for the model instantiated from submodel " + subm->getId();
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "Unable to rename elements in CompModelPlugin::renameAllIDsAndPrepend: no valid 'comp' plugin for the model instantiated from submodel " + subm->getId();
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
@@ -984,8 +984,8 @@
Model* model = static_cast<Model*>(getParentSBMLObject());
if (model==NULL) {
if (doc) {
- string error = "No parent model could be found for the given 'comp' model plugin element.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "Unable to attempt to perform deletions in CompModelPlugin::performDeletions: no parent model could be found for the given 'comp' model plugin element.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
@@ -1011,8 +1011,8 @@
if (modplug==NULL) {
if (doc) {
//Shouldn't happen: 'getInstantiation' turns on the comp plugin.
- string error = "No valid 'comp' plugin for the model instantiated from submodel " + submodel->getId();
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "Unable to rename elements in CompModelPlugin::performDeletions: no valid 'comp' plugin for the model instantiated from submodel " + submodel->getId();
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
@@ -1028,8 +1028,8 @@
Model* model = static_cast<Model*>(getParentSBMLObject());
if (model==NULL) {
if (doc) {
- string error = "No parent model could be found for the given 'comp' model plugin element.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "Unable to perform replacements in CompModelPlugin::performDeletions: no parent model could be found for the given 'comp' model plugin element.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
Modified: trunk/libsbml/src/sbml/packages/comp/extension/test/TestCheckConsistency.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/extension/test/TestCheckConsistency.cpp 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/extension/test/TestCheckConsistency.cpp 2013-07-29 23:37:09 UTC (rev 18273)
@@ -68,10 +68,8 @@
doc->checkConsistency();
unsigned int nerrors = doc->getNumErrors();
- fail_unless (nerrors == 3);
+ fail_unless (nerrors == 1);
fail_unless (doc->getError(0)->getErrorId() == 1020212);
- fail_unless (doc->getError(1)->getErrorId() == 1090106);
- fail_unless (doc->getError(2)->getErrorId() == 1090105);
delete doc;
}
Modified: trunk/libsbml/src/sbml/packages/comp/sbml/Deletion.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/sbml/Deletion.cpp 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/sbml/Deletion.cpp 2013-07-29 23:37:09 UTC (rev 18273)
@@ -262,38 +262,28 @@
{
SBMLDocument* doc = getSBMLDocument();
SBase* listodels = getParentSBMLObject();
- if (listodels==NULL) {
+ ListOf* listodelslist = static_cast<ListOf*>(listodels);
+ if (listodels==NULL || listodels->getTypeCode() != SBML_LIST_OF || listodelslist->getItemTypeCode() != SBML_COMP_DELETION ) {
if (doc) {
- string error = "The deletion ";
+ string error = "Unable to find referenced element in Deletion::saveReferencedElement: the deletion ";
if (isSetId()) {
- error += "'" + getId() + "'";
+ error += "'" + getId() + "' ";
}
- error += "has no parent list of deletions--the element it may reference cannot be found.";
- doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, 1, 3, 1, error);
+ error += "has no parent list of deletions.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
SBase* submodsb = listodels->getParentSBMLObject();
- if (submodsb==NULL) {
- if (doc) {
- string error = "The deletion ";
- if (isSetId()) {
- error += "'" + getId() + "'";
- }
- error += "has no parent submodel--the element it may reference cannot be found.";
- doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, 1, 3, 1, error);
- }
- return LIBSBML_OPERATION_FAILED;
- }
Submodel* submod = static_cast<Submodel*>(submodsb);
- if (submod==NULL) {
+ if (submodsb==NULL || submod->getTypeCode() != SBML_COMP_SUBMODEL) {
if (doc) {
- string error = "The deletion ";
+ string error = "Unable to find referenced element in Deletion::saveReferencedElement: the deletion ";
if (isSetId()) {
- error += "'" + getId() + "'";
+ error += "'" + getId() + "' ";
}
- error += "has no parent submodel--the element it may reference cannot be found.";
- doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, 1, 3, 1, error);
+ error += "has no parent submodel.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
Modified: trunk/libsbml/src/sbml/packages/comp/sbml/ExternalModelDefinition.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/sbml/ExternalModelDefinition.cpp 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/sbml/ExternalModelDefinition.cpp 2013-07-29 23:37:09 UTC (rev 18273)
@@ -439,7 +439,7 @@
const std::string details =
getErrorLog()->getError(n)->getMessage();
getErrorLog()->remove(UnknownPackageAttribute);
- getErrorLog()->logPackageError("fbc", CompExtModDefAllowedAttributes,
+ getErrorLog()->logPackageError("comp", CompExtModDefAllowedAttributes,
getPackageVersion(), sbmlLevel, sbmlVersion, details);
}
else if (getErrorLog()->getError(n)->getErrorId() == UnknownCoreAttribute)
@@ -447,7 +447,7 @@
const std::string details =
getErrorLog()->getError(n)->getMessage();
getErrorLog()->remove(UnknownCoreAttribute);
- getErrorLog()->logPackageError("fbc", CompExtModDefAllowedCoreAttributes,
+ getErrorLog()->logPackageError("comp", CompExtModDefAllowedCoreAttributes,
getPackageVersion(), sbmlLevel, sbmlVersion, details);
}
}
@@ -594,8 +594,8 @@
if (csdp == NULL)
{
if (origdoc) {
- string error = "Unable to resolve the external model definition '" + getId() + "': no 'comp' plugin found.";
- origdoc->getErrorLog()->logPackageError("comp", CompExtModDefBad, 1, 3, 1, error);
+ string error = "In ExternalModelDefinition::getReferencedModel, unable to resolve the external model definition '" + getId() + "': no 'comp' plugin found.";
+ origdoc->getErrorLog()->logPackageError("comp", CompUnresolvedReference, getPackageVersion(), getLevel(), getVersion(), error);
}
return NULL;
}
@@ -603,10 +603,10 @@
if (!isSetSource())
{
if (origdoc) {
- string error = "Unable to resolve the external model definition '" + getId() + "': the 'source' attribute was not set.";
- origdoc->getErrorLog()->logPackageError("comp", CompExtModDefAllowedAttributes, 1, 3, 1, error);
- return NULL;
+ string error = "In ExternalModelDefinition::getReferencedModel, unable to resolve the external model definition '" + getId() + "': the 'source' attribute was not set.";
+ origdoc->getErrorLog()->logPackageError("comp", CompExtModDefAllowedAttributes, getPackageVersion(), getLevel(), getVersion(), error);
}
+ return NULL;
}
SBMLDocument* doc = csdp->getSBMLDocumentFromURI(getSource());
@@ -616,10 +616,10 @@
// other operations are informed, and for example flattening will fail
// with error
if (origdoc) {
- string error = "Unable to resolve the external model definition '" + getId() + "': could not the resolve 'source' attribute '" + getSource() + "' as a valid SBML Document.";
- origdoc->getErrorLog()->logPackageError("comp", CompUnresolvedReference, 1, 3, 1, error);
- return NULL;
+ string error = "In ExternalModelDefinition::getReferencedModel, unable to resolve the external model definition '" + getId() + "': could not the resolve 'source' attribute '" + getSource() + "' as a valid SBML Document.";
+ origdoc->getErrorLog()->logPackageError("comp", CompUnresolvedReference, getPackageVersion(), getLevel(), getVersion(), error);
}
+ return NULL;
}
if (!(doc->getLevel() == 3 && doc->getVersion() == 1))
@@ -627,31 +627,31 @@
// comp v1 ONLY allows L3v1 models. All other levels and versions are not supported.
//
if (origdoc) {
- string error = "Unable to resolve the external model definition '" + getId() + "': the SBML document found at source '" + getSource() + "' was not SBML Level 3 Version 1.";
- origdoc->getErrorLog()->logPackageError("comp", CompReferenceMustBeL3, 1, 3, 1, error);
- return NULL;
+ string error = "In ExternalModelDefinition::getReferencedModel, unable to resolve the external model definition '" + getId() + "': the SBML document found at source '" + getSource() + "' was not SBML Level 3 Version 1.";
+ origdoc->getErrorLog()->logPackageError("comp", CompReferenceMustBeL3, getPackageVersion(), getLevel(), getVersion(), error);
}
+ return NULL;
}
Model* model = doc->getModel();
if (isSetModelRef())
{
csdp = static_cast<CompSBMLDocumentPlugin*>(doc->getPlugin(getPrefix()));
- if (csdp == NULL)
+ if (csdp == NULL || (csdp->getNumExternalModelDefinitions()==0 && csdp->getNumModelDefinitions()==0))
{
if (model==NULL) {
if (origdoc) {
- string error = "Unable to resolve the external model definition '" + getId() + "': the SBML document found at source '" + getSource() + "' had no resolvable models at all.";
- origdoc->getErrorLog()->logPackageError("comp", CompModReferenceMustIdOfModel, 1, 3, 1, error);
- return NULL;
+ string error = "In ExternalModelDefinition::getReferencedModel, unable to resolve the external model definition '" + getId() + "': the SBML document found at source '" + getSource() + "' had no resolvable models at all.";
+ origdoc->getErrorLog()->logPackageError("comp", CompNoModelInReference, getPackageVersion(), getLevel(), getVersion(), error);
}
+ return NULL;
}
else if (model->getId() != getModelRef()) {
if (origdoc) {
- string error = "Unable to resolve the external model definition '" + getId() + "': the SBML document found at source '" + getSource() + "' had no 'comp' extension objects, and the single model's ID did not match the modelRef '" + getModelRef() + "'.";
- origdoc->getErrorLog()->logPackageError("comp", CompModReferenceMustIdOfModel, 1, 3, 1, error);
- return NULL;
+ string error = "In ExternalModelDefinition::getReferencedModel, unable to resolve the external model definition '" + getId() + "': the SBML document found at source '" + getSource() + "' had no 'comp' model definitions, and the single model's ID ('" + model->getId() + "') did not match the modelRef '" + getModelRef() + "'.";
+ origdoc->getErrorLog()->logPackageError("comp", CompModReferenceMustIdOfModel, getPackageVersion(), getLevel(), getVersion(), error);
}
+ return NULL;
}
//else we can return the main 'model' object of the document.
}
@@ -661,10 +661,10 @@
if (referencedmod == NULL)
{
if (origdoc) {
- string error = "Unable to resolve the external model definition '" + getId() + "': the SBML document found at source '" + getSource() + "' did not have any model with the id '" + getModelRef() + "'.";
- origdoc->getErrorLog()->logPackageError("comp", CompModReferenceMustIdOfModel, 1, 3, 1, error);
- return NULL;
+ string error = "In ExternalModelDefinition::getReferencedModel, unable to resolve the external model definition '" + getId() + "': the SBML document found at source '" + getSource() + "' did not have any model with the id '" + getModelRef() + "'.";
+ origdoc->getErrorLog()->logPackageError("comp", CompModReferenceMustIdOfModel, getPackageVersion(), getLevel(), getVersion(), error);
}
+ return NULL;
}
ExternalModelDefinition* subextmod;
@@ -680,10 +680,10 @@
model = subextmod->getReferencedModel();
if (model==NULL) {
if (origdoc) {
- string error = "Unable to resolve the external model definition '" + getId() + "': the external model definition it referenced ('" + getModelRef() + "') could not be resolved.";
- origdoc->getErrorLog()->logPackageError("comp", CompUnresolvedReference, 1, 3, 1, error);
- return NULL;
+ string error = "In ExternalModelDefinition::getReferencedModel, unable to resolve the external model definition '" + getId() + "': the external model definition it referenced ('" + getModelRef() + "', from the document at '" + getSource() + "') could not be resolved.";
+ origdoc->getErrorLog()->logPackageError("comp", CompUnresolvedReference, getPackageVersion(), getLevel(), getVersion(), error);
}
+ return NULL;
}
return model;
@@ -699,10 +699,10 @@
// assert(false);
if (origdoc) {
- string error = "Unable to resolve the external model definition '" + getId() + "': the model object discovered at in the SBML document found at source '" + getSource() + "' was not of the type 'model' 'modelDefinition', or 'externalModelDefinition'. The most likely cause of this situation is if some other package extended one of those three types, but the external model definition code was not updated.";
- origdoc->getErrorLog()->logPackageError("comp", CompUnresolvedReference, 1, 3, 1, error);
- return NULL;
+ string error = "In ExternalModelDefinition::getReferencedModel, unable to resolve the external model definition '" + getId() + "': the model object discovered at in the SBML document found at source '" + getSource() + "' was not of the type 'model' 'modelDefinition', or 'externalModelDefinition'. The most likely cause of this situation is if some other package extended one of those three types, but the external model definition code was not updated.";
+ origdoc->getErrorLog()->logPackageError("comp", CompUnresolvedReference, getPackageVersion(), getLevel(), getVersion(), error);
}
+ return NULL;
}
}
}
@@ -710,8 +710,8 @@
if (model==NULL)
{
if (origdoc) {
- string error = "Unable to resolve the external model definition '" + getId() + "': the SBML document found at source '" + getSource() + "' did not have a model child of the SBML Document, and no 'modelRef' attribute was set to discover any other model in that document.";
- origdoc->getErrorLog()->logPackageError("comp", CompNoModelInReference, 1, 3, 1, error);
+ string error = "In ExternalModelDefinition::getReferencedModel, unable to resolve the external model definition '" + getId() + "': the SBML document found at source '" + getSource() + "' did not have a model child of the SBML Document, and no 'modelRef' attribute was set to discover any other model in that document.";
+ origdoc->getErrorLog()->logPackageError("comp", CompNoModelInReference, getPackageVersion(), getLevel(), getVersion(), error);
}
}
Modified: trunk/libsbml/src/sbml/packages/comp/sbml/Port.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/sbml/Port.cpp 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/sbml/Port.cpp 2013-07-29 23:37:09 UTC (rev 18273)
@@ -304,11 +304,11 @@
Model* model = CompBase::getParentModel(this);
if (model==NULL) {
if (doc) {
- string error = "No model could be found for the given <port> element";
+ string error = "Unable to discover referenced element: no model could be found for the given <port> element";
if (isSetId()) {
error += " '" + getId() + "'.";
}
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
Modified: trunk/libsbml/src/sbml/packages/comp/sbml/ReplacedBy.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/sbml/ReplacedBy.cpp 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/sbml/ReplacedBy.cpp 2013-07-29 23:37:09 UTC (rev 18273)
@@ -106,8 +106,8 @@
SBase* parent = getParentSBMLObject();
if (parent==NULL) {
if (doc) {
- string error = "No parent object for this <replacedBy> could be found.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "Unable to perform replacement in ReplacedBy::performReplacement: no parent object for this <replacedBy> could be found.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_INVALID_OBJECT;
}
@@ -133,7 +133,40 @@
return CompBase::removeFromParentAndPorts(parent);
}
+int
+ReplacedBy::updateIDs(SBase* oldnames, SBase* newnames)
+{
+ //The trick here is that 'oldnames' is actually replacing 'newnames' so we need to get the error messages correct.
+ int ret = LIBSBML_OPERATION_SUCCESS;
+ SBMLDocument* doc = getSBMLDocument();
+ if (!oldnames->isSetId() && newnames->isSetId()) {
+ if (doc) {
+ string error = "Unable to transform IDs in ReplacedBy::updateIDs during replacement: the '" + newnames->getId() + "' element's replacement does not have an ID set.";
+ doc->getErrorLog()->logPackageError("comp", CompMustReplaceIDs, getPackageVersion(), getLevel(), getVersion(), error);
+ }
+ return LIBSBML_INVALID_OBJECT;
+ }
+ if (!oldnames->isSetMetaId() && newnames->isSetMetaId()) {
+ if (doc) {
+ string error = "Unable to transform IDs in ReplacedBy::updateIDs during replacement: the replacement of the element with metaid '" + newnames->getMetaId() + "' does not have a metaid.";
+ doc->getErrorLog()->logPackageError("comp", CompMustReplaceMetaIDs, getPackageVersion(), getLevel(), getVersion(), error);
+ }
+ return LIBSBML_INVALID_OBJECT;
+ }
+ //LS DEBUG Somehow we need to check identifiers from other packages here (like spatial id's). How, exactly, is anyone's guess.
+ //Now update the IDs of 'newnames', if something wasn't set. (This avoids errors in Replacing::updateIDs)
+ if (oldnames->isSetId() && !newnames->isSetId()) {
+ newnames->setId(oldnames->getId());
+ }
+ if (oldnames->isSetMetaId() && !newnames->isSetMetaId()) {
+ newnames->setMetaId(oldnames->getMetaId());
+ }
+ //LS DEBUG We also need to update the other package IDs.
+ return Replacing::updateIDs(oldnames, newnames);
+}
+
+
/** @cond doxygen-libsbml-internal */
bool
Modified: trunk/libsbml/src/sbml/packages/comp/sbml/ReplacedBy.h
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/sbml/ReplacedBy.h 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/sbml/ReplacedBy.h 2013-07-29 23:37:09 UTC (rev 18273)
@@ -153,7 +153,29 @@
/** @cond doxygen-libsbml-internal */
+ /**
+ * Searches the model that @p oldnames came from for references to any of its ids,
+ * and replaces them with references to @p newnames.
+ *
+ * @param oldnames the object being replaced, and whose parent Model contains
+ * the references that need to be updated.
+ *
+ * @param newnames the object that should now be referenced instead, to which
+ * any references to @p oldnames should now point.
+ *
+ * @return integer value indicating success/failure of the
+ * function. @if clike The value is drawn from the
+ * enumeration #OperationReturnValues_t. @endif The possible values
+ * returned by this function are:
+ * @li @link OperationReturnValues_t#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS @endlink
+ * @li @link OperationReturnValues_t#LIBSBML_INVALID_OBJECT LIBSBML_INVALID_OBJECT @endlink
+ */
+ virtual int updateIDs(SBase* oldnames, SBase* newnames);
+ /** @endcond */
+
+ /** @cond doxygen-libsbml-internal */
+
/**
* Accepts the given SBMLVisitor.
*
Modified: trunk/libsbml/src/sbml/packages/comp/sbml/ReplacedElement.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/sbml/ReplacedElement.cpp 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/sbml/ReplacedElement.cpp 2013-07-29 23:37:09 UTC (rev 18273)
@@ -328,25 +328,26 @@
}
//Find the various objects and plugin objects we need for this to work.
SBase* lore = getParentSBMLObject();
+ ListOf* lorelist = static_cast<ListOf*>(lore);
if (lore == NULL) {
if (doc) {
- string error = "No parent <listOfReplacedElements> could be found for the given <replacement> element.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "Cannot carry out replacement in ReplacedElement::performReplacement: no parent <listOfReplacedElements> could be found for the given replacement element.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_INVALID_OBJECT;
}
- if (lore->getTypeCode() != SBML_LIST_OF) {
+ if (lore->getTypeCode() != SBML_LIST_OF || lorelist->getItemTypeCode() != SBML_COMP_REPLACEDELEMENT) {
if (doc) {
- string error = "No parent <listOfReplacedElements> could be found for the given <replacement> element.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "Cannot carry out replacement in ReplacedElement::performReplacement: no parent <listOfReplacedElements> could be found for the given replacement element.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_INVALID_OBJECT;
}
SBase* parent = lore->getParentSBMLObject();
if (parent==NULL) {
if (doc) {
- string error = "No parent could be found for the <listOfReplacedElements> object.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "Cannot carry out replacement in ReplacedElement::performReplacement: no parent could be found for the parent <listOfReplacedElements> object.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_INVALID_OBJECT;
}
@@ -386,23 +387,43 @@
SBase*
ReplacedElement::getReferencedElementFrom(Model* model)
{
- if (!hasRequiredAttributes()) {
- return NULL;
- }
+ SBMLDocument* doc = getSBMLDocument();
SBase* referent = Replacing::getReferencedElementFrom(model);
if (referent != NULL) return referent;
- if (isSetDeletion()) {
- //The deletion is not actually in the passed-in Model, but in our own Model.
- model = getParentModel(this);
- if (model==NULL) return NULL;
- if (!isSetSubmodelRef()) return NULL;
- CompModelPlugin* mplugin = static_cast<CompModelPlugin*>(model->getPlugin(getPrefix()));
- if (mplugin==NULL) return NULL;
- Submodel* submod = mplugin->getSubmodel(getSubmodelRef());
- if (submod==NULL) return NULL;
- return submod->getDeletion(getDeletion());
+ if (!isSetDeletion()) {
+ //In this case, something else went wrong in getReferencedElementFrom, which will have set its own error message.
+ return NULL;
}
- return NULL;
+ model = getParentModel(this);
+ if (model==NULL) {
+ if (doc) {
+ string error = "In ReplacedElement::getReferencedElementFrom, unable to find referenced deletion '" + getDeletion() + "' for <replacedElement>: no parent model could be found.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
+ }
+ return NULL;
+ }
+ CompModelPlugin* mplugin = static_cast<CompModelPlugin*>(model->getPlugin(getPrefix()));
+ if (mplugin==NULL) {
+ if (doc) {
+ string error = "In ReplacedElement::getReferencedElementFrom, unable to find referenced deletion '" + getDeletion() + "' for <replacedElement>: no 'comp' plugin for the parent model could be found.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
+ }
+ return NULL;
+ }
+ Submodel* submod = mplugin->getSubmodel(getSubmodelRef());
+ if (submod==NULL) {
+ if (doc) {
+ string error = "In ReplacedElement::getReferencedElementFrom, unable to find referenced deletion '" + getDeletion() + "' for <replacedElement>: no such submodel '" + getSubmodelRef() + "'.";
+ doc->getErrorLog()->logPackageError("comp", CompReplacedElementSubModelRef, getPackageVersion(), getLevel(), getVersion(), error);
+ }
+ return NULL;
+ }
+ SBase* ret = submod->getDeletion(getDeletion());
+ if (ret==NULL && doc) {
+ string error = "In ReplacedElement::getReferencedElementFrom, unable to find referenced deletion '" + getDeletion() + "' for <replacedElement>: no deletion with that ID exists in the model.";
+ doc->getErrorLog()->logPackageError("comp", CompDeletionMustReferenceObject, getPackageVersion(), getLevel(), getVersion(), error);
+ }
+ return ret;
}
/** @cond doxygen-libsbml-internal */
Modified: trunk/libsbml/src/sbml/packages/comp/sbml/Replacing.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/sbml/Replacing.cpp 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/sbml/Replacing.cpp 2013-07-29 23:37:09 UTC (rev 18273)
@@ -145,50 +145,50 @@
SBMLDocument* doc = getSBMLDocument();
if (!isSetSubmodelRef()) {
if (doc) {
- string error = "The given <" + getElementName() + "> element";
+ string error = "Unable to find referenced element in Replacing::saveReferencedElement: the given <" + getElementName() + "> element";
if (isSetId()) {
error += " '" + getId() + "'";
}
error += " has no 'submodelRef' attribute.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ doc->getErrorLog()->logPackageError("comp", CompReplacedElementAllowedAttributes, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_INVALID_OBJECT;
}
Model* model = getParentModel(this);
if (model==NULL) {
if (doc) {
- string error = "No parent model could be found for the given <" + getElementName() + "> element";
+ string error = "Unable to find referenced element in Replacing::saveReferencedElement: no parent model could be found for the given <" + getElementName() + "> element";
if (isSetId()) {
error += " '" + getId() + "'.";
}
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
CompModelPlugin* cmp = static_cast<CompModelPlugin*>(model->getPlugin(getPrefix()));
if (cmp==NULL) {
if (doc) {
- string error = "No 'comp' plugin for the parent model could be found for the given <" + getElementName() + "> element";
+ string error = "Unable to find referenced element in Replacing::saveReferencedElement: no 'comp' plugin for the parent model could be found for the given <" + getElementName() + "> element";
if (isSetId()) {
error += " '" + getId() + "'.";
}
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
Submodel* submod = cmp->getSubmodel(getSubmodelRef());
if (submod==NULL) {
if (doc) {
- string error = "For the given <" + getElementName() + "> element";
+ string error = "Unable to find referenced element for the given <" + getElementName() + "> element";
if (isSetId()) {
error += " '" + getId() + "'";
}
- error += ", the submodelRef '" + getSubmodelRef() + "' could not be found.";
+ error += " in Replacing::saveReferencedElement: the submodelRef '" + getSubmodelRef() + "' could not be found in the model.";
int errnumber = CompReplacedElementSubModelRef;
if (getTypeCode() == SBML_COMP_REPLACEDBY) {
errnumber = CompReplacedBySubModelRef;
}
- doc->getErrorLog()->logPackageError("comp", errnumber, 1, 3, 1, error);
+ doc->getErrorLog()->logPackageError("comp", errnumber, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_INVALID_ATTRIBUTE_VALUE;
}
@@ -376,15 +376,15 @@
SBMLDocument* doc = getSBMLDocument();
if (oldnames->isSetId() && !newnames->isSetId()) {
if (doc) {
- string error = "The '" + oldnames->getId() + "' element's replacement element does not have an ID set.";
- doc->getErrorLog()->logPackageError("comp", CompMustReplaceIDs, 1, 3, 1, error);
+ string error = "Unable to transform IDs in Replacing::updateIDs during replacement: the '" + oldnames->getId() + "' element's replacement does not have an ID set.";
+ doc->getErrorLog()->logPackageError("comp", CompMustReplaceIDs, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_INVALID_OBJECT;
}
if (oldnames->isSetMetaId() && !newnames->isSetMetaId()) {
if (doc) {
- string error = "The replacement of the element with metaid '" + oldnames->getMetaId() + "' does not have a metaid.";
- doc->getErrorLog()->logPackageError("comp", CompMustReplaceMetaIDs, 1, 3, 1, error);
+ string error = "Unable to transform IDs in Replacing::updateIDs during replacement: the replacement of the element with metaid '" + oldnames->getMetaId() + "' does not have a metaid.";
+ doc->getErrorLog()->logPackageError("comp", CompMustReplaceMetaIDs, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_INVALID_OBJECT;
}
@@ -394,8 +394,8 @@
ASTNode newkl;
if (replacedmod==NULL) {
if (doc) {
- string error = "The replacement of '" + oldnames->getId() + "' does not have a valid model.";
- doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, 1, 3, 1, error);
+ string error = "Unable to transform IDs in Replacing::updateIDs during replacement: the replacement of '" + oldnames->getId() + "' does not have a valid model.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_INVALID_OBJECT;
}
@@ -456,8 +456,8 @@
}
if (replacement==NULL) {
if (doc) {
- string error = "Internal error: cannot perform a conversion of NULL.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "Internal error in Replacing::performConversions: cannot perform a conversion of NULL.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
@@ -470,11 +470,11 @@
Model* replacedmod = const_cast<Model*>(CompBase::getParentModel(replaced));
if (replacedmod==NULL) {
if (doc) {
- string error = "No model parent could be found for replacement";
+ string error = "Unable to perform conversion of replacement in Replacing::performConversions: No model parent could be found for replacement";
if (replacement->isSetId()) {
error += replacement->getId() + ".";
}
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_INVALID_OBJECT;
}
@@ -501,7 +501,6 @@
int Replacing::convertConversionFactor(ASTNode*& conversionFactor)
{
int ret = LIBSBML_OPERATION_SUCCESS;
- SBMLDocument* doc = getSBMLDocument();
ASTNode* newCF = NULL;
if (mConversionFactor=="") {
newCF = conversionFactor;
@@ -524,9 +523,10 @@
newCF = conversionFactor;
}
else {
+ SBMLDocument* doc = getSBMLDocument();
if (doc) {
- string error = "Internal error: unknown conversion factor form.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "Internal error in Replacing::convertConversionFactor: unknown conversion factor form.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
Modified: trunk/libsbml/src/sbml/packages/comp/sbml/SBaseRef.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/sbml/SBaseRef.cpp 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/sbml/SBaseRef.cpp 2013-07-29 23:37:09 UTC (rev 18273)
@@ -735,12 +735,26 @@
SBMLDocument* doc = getSBMLDocument();
if (!hasRequiredAttributes()) {
if (doc) {
- string error = "Unable to find referenced element from SBase reference ";
+ string error = "In SBaseRef::getReferencedElementFrom, unable to find referenced element from <" + getElementName() + "> ";
if (isSetId()) {
- error += "'" + getId() + "' ";
+ error += "with ID '" + getId() + "' ";
}
- error += " as it does not have the required attributes.";
- doc->getErrorLog()->logPackageError("comp", CompSBaseRefMustReferenceOnlyOneObject, 1, 3, 1, error);
+ error += "as it does not have the required attributes.";
+ int en = CompSBaseRefMustReferenceObject;
+ switch(getTypeCode()) {
+ case SBML_COMP_REPLACEDBY:
+ en = CompReplacedByAllowedAttributes;
+ break;
+ case SBML_COMP_REPLACEDELEMENT:
+ en = CompReplacedElementAllowedAttributes;
+ break;
+ case SBML_COMP_PORT:
+ en = CompPortAllowedAttributes;
+ break;
+ case SBML_COMP_DELETION:
+ en = CompDeletionAllowedAttributes;
+ }
+ doc->getErrorLog()->logPackageError("comp", en, getPackageVersion(), getLevel(), getVersion(), error);
}
return NULL;
}
@@ -750,12 +764,12 @@
Port* port = mplugin->getPort(getPortRef());
if (port==NULL) {
if (doc) {
- string error = "Unable to find referenced element from SBase reference ";
+ string error = "In SBaseRef::getReferencedElementFrom, unable to find referenced element from SBase reference ";
if (isSetId()) {
error += "'" + getId() + "' ";
}
- error += " as the port it references ('" + getPortRef() +"') could not be found.";
- doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, 1, 3, 1, error);
+ error += "as the port it references ('" + getPortRef() +"') could not be found.";
+ doc->getErrorLog()->logPackageError("comp", CompPortRefMustReferencePort, getPackageVersion(), getLevel(), getVersion(), error);
}
return NULL;
}
@@ -764,22 +778,22 @@
else if (isSetIdRef()) {
referent = model->getElementBySId(getIdRef());
if (referent == NULL && doc) {
- string error = "No such SId in the model: '" + getIdRef() + "'.";
- doc->getErrorLog()->logPackageError("comp", CompIdRefMustReferenceObject, 1, 3, 1, error);
+ string error = "In SBaseRef::getReferencedElementFrom, unable to find referenced element: no such SId in the model: '" + getIdRef() + "'.";
+ doc->getErrorLog()->logPackageError("comp", CompIdRefMustReferenceObject, getPackageVersion(), getLevel(), getVersion(), error);
}
}
else if (isSetUnitRef()) {
referent = model->getUnitDefinition(getUnitRef());
if (referent == NULL && doc) {
- string error = "No such Unit in the model: '" + getUnitRef() + "'.";
- doc->getErrorLog()->logPackageError("comp", CompUnitRefMustReferenceUnitDef, 1, 3, 1, error);
+ string error = "In SBaseRef::getReferencedElementFrom, unable to find referenced element: no such Unit in the model: '" + getUnitRef() + "'.";
+ doc->getErrorLog()->logPackageError("comp", CompUnitRefMustReferenceUnitDef, getPackageVersion(), getLevel(), getVersion(), error);
}
}
else if (isSetMetaIdRef()) {
referent = model->getElementByMetaId(getMetaIdRef());
if (referent == NULL && doc) {
- string error = "No such metaid in the model: '" + getMetaIdRef() + "'.";
- doc->getErrorLog()->logPackageError("comp", CompMetaIdRefMustReferenceObject, 1, 3, 1, error);
+ string error = "In SBaseRef::getReferencedElementFrom, unable to find referenced element: no such metaid in the model: '" + getMetaIdRef() + "'.";
+ doc->getErrorLog()->logPackageError("comp", CompMetaIdRefMustReferenceObject, getPackageVersion(), getLevel(), getVersion(), error);
}
}
else {
@@ -794,7 +808,7 @@
//We're drilling into the submodels here, so our referent must be a submodel.
if (referent->getTypeCode() != SBML_COMP_SUBMODEL) {
if (doc) {
- string error = "The element ";
+ string error = "In SBaseRef::getReferencedElementFrom, unable to find referenced element: the element ";
if (referent->isSetId()) {
error += "'" + referent->getId() + "'";
}
@@ -802,22 +816,23 @@
error += "with the metaid '" + referent->getMetaId() + "'";
}
error += " is not a submodel, and therefore has no subobjects for the child <sBaseRef> to refer to.";
- doc->getErrorLog()->logPackageError("comp", CompParentOfSBRefChildMustBeSubmodel, 1, 3, 1, error);
+ doc->getErrorLog()->logPackageError("comp", CompParentOfSBRefChildMustBeSubmodel, getPackageVersion(), getLevel(), getVersion(), error);
}
return NULL;
}
Submodel* subm = static_cast<Submodel*>(referent);
if (subm==NULL) {
+ //Note: should be impossible.
if (doc) {
- string error = "The element ";
+ string error = "In SBaseRef::getReferencedElementFrom, unable to find referenced element: the element ";
if (referent->isSetId()) {
- error += "'" + referent->getId() + "'";
+ error += "'" + referent->getId() + "' ";
}
else if (referent->isSetMetaId()) {
- error += "with the metaid '" + referent->getMetaId() + "'";
+ error += "with the metaid '" + referent->getMetaId() + "' ";
}
- error += " claims to be a Submodel, but could not be programmatically turned into one.";
- doc->getErrorLog()->logPackageError("comp", CompParentOfSBRefChildMustBeSubmodel, 1, 3, 1, error);
+ error += "claims to be a Submodel, but could not be programmatically turned into one.";
+ doc->getErrorLog()->logPackageError("comp", CompParentOfSBRefChildMustBeSubmodel, getPackageVersion(), getLevel(), getVersion(), error);
}
return NULL;
}
@@ -839,21 +854,25 @@
SBase* parent = getParentSBMLObject();
if (parent==NULL) {
if (doc) {
- string error = "No parent could be found for the given <sBaseRef> element.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "In SBaseRef::saveReferencedElement, unable to find referenced element: no parent could be found for the given <sBaseRef> element.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
SBaseRef* parentref = static_cast<SBaseRef*>(parent);
- if (parentref==NULL) {
+ if (parentref==NULL || (parent->getTypeCode() != SBML_COMP_SBASEREF &&
+ parent->getTypeCode() != SBML_COMP_PORT &&
+ parent->getTypeCode() != SBML_COMP_DELETION &&
+ parent->getTypeCode() != SBML_COMP_REPLACEDBY &&
+ parent->getTypeCode() != SBML_COMP_REPLACEDELEMENT)) {
if (doc) {
- string error = "The parent of the given <sBaseRef> element was not the correct type.";
- doc->getErrorLog()->logPackageError("comp", CompFlatModelNotValid, 1, 3, 1, error);
+ string error = "In SBaseRef::saveReferencedElement, unable to find referenced element: the parent of the given <sBaseRef> element was not the correct type.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
}
return LIBSBML_OPERATION_FAILED;
}
if (parentref->saveReferencedElement() != LIBSBML_OPERATION_SUCCESS) {
- //saveReferencedelement will set its own error messages.
+ //saveReferencedElement will set its own error messages.
return LIBSBML_OPERATION_FAILED;
}
mReferencedElement = parentref->getReferencedElement();
Modified: trunk/libsbml/src/sbml/packages/comp/sbml/Submodel.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/sbml/Submodel.cpp 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/sbml/Submodel.cpp 2013-07-29 23:37:09 UTC (rev 18273)
@@ -816,15 +816,19 @@
}
const SBase* parent = getParentSBMLObject();
+ string parentmodelname = "";
while (parent != NULL && parent->getTypeCode() != SBML_DOCUMENT) {
if (parent->getTypeCode() == SBML_MODEL ||
parent->getTypeCode() == SBML_COMP_MODELDEFINITION ||
parent->getTypeCode() == SBML_COMP_EXTERNALMODELDEFINITION)
{
+ if (parentmodelname == "") {
+ parentmodelname = parent->getId();
+ }
if (getModelRef() == parent->getId() && docplugin->getExternalModelDefinition(getModelRef()) == NULL)
{
- string error = "The submodel '" + getId() + "' references the model '" + getModelRef() + "', which is already an ancestor of the submodel.";
- doc->getErrorLog()->logPackageError("comp", CompSubmodelCannotReferenceSelf, 1, 3, 1, error);
+ string error = "Instantiation error in Submodel::instantiate: the submodel '" + getId() + "' in model '" + parentmodelname + "' references the model '" + getModelRef() + "', which is already an ancestor of the submodel.";
+ doc->getErrorLog()->logPackageError("comp", CompSubmodelCannotReferenceSelf, getPackageVersion(), getLevel(), getVersion(), error);
return LIBSBML_INVALID_OBJECT;
}
}
@@ -838,22 +842,22 @@
}
if (!hasRequiredAttributes()) {
- string error = "The submodel '" + getId() + "' does not have ";
+ string error = "Instantiation error in Submodel::instantiate: ";
if (!isSetId()) {
- error += " an 'id' attribute.";
+ error += "A submodel in model '" + getParentModel(this)->getId() + "' does not have an 'id' attribute.";
}
else if (!isSetModelRef()) {
- error += " a 'modelRef' attribute.";
+ error += "The submodel '" + getId() + "' does not have a 'modelRef' attribute.";
}
- doc->getErrorLog()->logPackageError("comp", CompSubmodelAllowedAttributes, 1, 3, 1, error);
+ doc->getErrorLog()->logPackageError("comp", CompSubmodelAllowedAttributes, getPackageVersion(), getLevel(), getVersion(), error);
return LIBSBML_INVALID_OBJECT;
}
SBase* origmodel = docplugin->getModel(getModelRef());
if (origmodel==NULL) {
- string error = "Unable to instantiate submodel '" + getId() + "' because the referenced model ('" + getModelRef() +"') does not exist.";
- doc->getErrorLog()->logPackageError("comp", CompSubmodelMustReferenceModel, 1, 3, 1, error);
+ string error = "In Submodel::instantiate, unable to instantiate submodel '" + getId() + "' because the referenced model ('" + getModelRef() +"') does not exist.";
+ doc->getErrorLog()->logPackageError("comp", CompSubmodelMustReferenceModel, getPackageVersion(), getLevel(), getVersion(), error);
return LIBSBML_INVALID_OBJECT;
}
ExternalModelDefinition* extmod;
@@ -878,8 +882,8 @@
mInstantiatedModel = extmod->getReferencedModel();
if (mInstantiatedModel == NULL)
{
- string error = "Unable to instantiate submodel '" + getId() + "' because the external model definition it referenced (model ('" + getModelRef() +"') does not exist.";
- doc->getErrorLog()->logPackageError("comp", CompSubmodelMustReferenceModel, 1, 3, 1, error);
+ string error = "In Submodel::instantiate, unable to instantiate submodel '" + getId() + "' because the external model definition it referenced (model '" + getModelRef() +"') could not be resolved.";
+ doc->getErrorLog()->logPackageError("comp", CompSubmodelMustReferenceModel, getPackageVersion(), getLevel(), getVersion(), error);
return LIBSBML_OPERATION_FAILED;
}
@@ -888,15 +892,15 @@
break;
default:
//Should always be one of the above, unless someone extends one of the above and doesn't tell us.
- string error = "Unable to parse the model '" + origmodel->getId() + "', as it was not of the type 'model' 'modelDefinition', or 'externalModelDefinition'. The most likely cause of this situation is if some other package extended one of those three types, but the submodel code was not updated.";
- doc->getErrorLog()->logPackageError("comp", CompUnresolvedReference, 1, 3, 1, error);
+ string error = "Instantiation error in Submodel::instantiate: unable to parse the model '" + origmodel->getId() + "', as it was not of the type 'model' 'modelDefinition', or 'externalModelDefinition'. The most likely cause of this situation is if some other package extended one of those three types, but the submodel code was not updated.";
+ doc->getErrorLog()->logPackageError("comp", CompUnresolvedReference, getPackageVersion(), getLevel(), getVersion(), error);
return LIBSBML_OPERATION_FAILED;
}
if (mInstantiatedModel==NULL)
{
- string error = "Unable to create a valid copy of model '" + getModelRef() + "'.";
- doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, 1, 3, 1, error);
+ string error = "Instantiation error in Submodel::instantiate: unable to create a valid copy of model '" + getModelRef() + "'.";
+ doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error);
return LIBSBML_OPERATION_FAILED;
}
Modified: trunk/libsbml/src/sbml/packages/comp/util/CompFlatteningConverter.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/util/CompFlatteningConverter.cpp 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/util/CompFlatteningConverter.cpp 2013-07-29 23:37:09 UTC (rev 18273)
@@ -181,6 +181,14 @@
}
CompModelPlugin *modelPlugin = (CompModelPlugin*)(mModel->getPlugin("comp"));
+ if (modelPlugin==NULL) {
+ return LIBSBML_OPERATION_FAILED;
+ }
+
+ mDocument->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed,
+ modelPlugin->getPackageVersion(), mDocument->getLevel(), mDocument->getVersion(),
+ "The subsequent errors are from this attempt.");
+
Model* flatmodel = modelPlugin->flattenModel();
if (basePathResolverIndex != -1)
@@ -191,11 +199,11 @@
if (flatmodel == NULL)
{
- mDocument->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed,
- mDocument->getPlugin("comp")->getPackageVersion(), mDocument->getLevel(),
- mDocument->getVersion());
+ //'flattenModel' sets its own error messages.
return LIBSBML_OPERATION_FAILED;
}
+ //Otherwise, remove the 'subsequent errors' error message.
+ mDocument->getErrorLog()->remove(CompModelFlatteningFailed);
// now reconstruct the document taking user options into account
Modified: trunk/libsbml/src/sbml/packages/comp/util/test/TestCompFlatteningConverter.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/util/test/TestCompFlatteningConverter.cpp 2013-07-29 12:50:25 UTC (rev 18272)
+++ trunk/libsbml/src/sbml/packages/comp/util/test/TestCompFlatteningConverter.cpp 2013-07-29 23:37:09 UTC (rev 18273)
@@ -155,6 +155,14 @@
fail_unless(doc->getErrorLog()->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) == 0);
//For use debugging the above statement:
+
+ converter->setDocument(doc);
+ int result = converter->convert();
+
+ // fail if conversion was not valid
+ fail_unless(result == LIBSBML_OPERATION_SUCCESS);
+
+ //For use in debugging the above statement.
/*
SBMLErrorLog* errors = doc->getErrorLog();
if (errors->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) != 0) {
@@ -168,12 +176,6 @@
}
*/
- converter->setDocument(doc);
- int result = converter->convert();
-
- // fail if conversion was not valid
- fail_unless(result == LIBSBML_OPERATION_SUCCESS);
-
string newModel = writeSBMLToString(doc);
//writeSBMLToFile(doc, "test1_flat.xml");
string ffile = filename + file2;
@@ -271,7 +273,6 @@
START_TEST (test_comp_flatten_double_ext1)
{
SBMLNamespaces sbmlns(3,1,"comp",1);
- CompPkgNamespaces csbmlns(3,1,1,"comp");
// create the document
SBMLDocument *doc = new SBMLDocument(&sbmlns);
@@ -337,7 +338,6 @@
START_TEST (test_comp_flatten_double_ext2)
{
SBMLNamespaces sbmlns(3,1,"comp",1);
- CompPkgNamespaces csbmlns(3,1,1,"comp");
// create the document
SBMLDocument *doc = new SBMLDocument(&sbmlns);
@@ -427,7 +427,6 @@
START_TEST (test_comp_flatten_dropports)
{
SBMLNamespaces sbmlns(3,1,"comp",1);
- CompPkgNamespaces csbmlns(3,1,1,"comp");
// create the document
SBMLDocument *doc = new SBMLDocument(&sbmlns);
@@ -1580,34 +1579,6 @@
}
END_TEST
-START_TEST(test_comp_flatten_invalid)
-{
- ConversionProperties* props = new ConversionProperties();
-
- props->addOption("flatten comp");
-
- SBMLConverter* converter =
- SBMLConverterRegistry::getInstance().getConverterFor(*props);
-
- // load document
- string dir(TestDataDirectory);
- string fileName = dir + "1020616-fail-01-01.xml";
- SBMLDocument* doc = readSBMLFromFile(fileName.c_str());
-
- // fail if there is no model (readSBMLFromFile always returns a valid document)
- fail_unless(doc->getNumErrors() == 0);
- fail_unless(doc->getModel() != NULL);
-
- converter->setDocument(doc);
- int result = converter->convert();
-
- fail_unless( result == LIBSBML_CONV_INVALID_SRC_DOCUMENT);
-
- delete doc;
- delete converter;
-}
-END_TEST
-
Suite *
create_suite_TestFlatteningConverter (void)
{
@@ -1703,9 +1674,6 @@
tcase_add_test(tcase, test_comp_flatten_converter_packages4);
tcase_add_test(tcase, test_comp_validator_44781839);
-
- tcase_add_test(tcase, test_comp_flatten_invalid);
-
suite_add_tcase(suite, tcase);
return suite;
Added: trunk/libsbml/src/sbml/packages/comp/util/test/TestCompFlatteningErrorMessages.cpp
===================================================================
--- trunk/libsbml/src/sbml/packages/comp/util/test/TestComp...
[truncated message content] |