Example of creating a custom validator to be called during validation.
public class MyCustomValidator : SBMLValidator
{
public MyCustomValidator()
: base()
{
}
public MyCustomValidator(MyCustomValidator orig)
: base(orig)
{
}
public new SBMLValidator clone() { return new MyCustomValidator(this); }
public new virtual long validate()
{
if (getDocument() == null || getModel() == null)
return 0;
if (getModel().getNumReactions() == 0 && getModel().getNumRules() == 0)
return 0;
int numErrors = 0;
for (int i = 0; i < getModel().getNumRules(); i++)
{
if (getModel().getRule(i).getTypeCode() == libsbml.SBML_ALGEBRAIC_RULE)
{
getErrorLog().add(new SBMLError(99999, 3, 1,
"This model uses algebraic rules, however this application does not support them.",
0, 0,
libsbml.LIBSBML_SEV_WARNING,
libsbml.LIBSBML_CAT_SBML
));
numErrors++;
}
}
for (int i = 0; i < getModel().getNumReactions(); i++)
{
if (getModel().getReaction(i).isSetFast() &&
getModel().getReaction(i).getFast())
{
getErrorLog().add(new SBMLError(99999, 3, 1,
"This model uses fast reactions, however this application does not support them.",
0, 0,
libsbml.LIBSBML_SEV_WARNING,
libsbml.LIBSBML_CAT_SBML
));
numErrors++;
}
}
return numErrors;
}
public static int Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("Usage: addCustomValidator filename"); ;
return 1;
}
SBMLDocument document = libsbml.readSBML(args[0]);
document.addValidator(new MyCustomValidator());
int numErrors = (int)document.checkConsistency();
document.printErrors();
return numErrors;
}
};