LoggingValidationContext
public class ValidationContext
extends java.lang.Object
ValidationContext
object is used to perform offline validation.
To prepare the context for the validation use the
loadConstraints(Class)
method, which will loads all
the required constraints to validate a object from this class. By default the
context will try to validate recursive by searching for the TreeNode
interface. This behavior can be changed with
setValidateRecursively(boolean)
.
To start the validation process call
validate(Object)
with a object which is a instance
of the class for which the constraints were loaded. If not constraints were
loaded or the object doesn't match the class, no validation process is
started.
To track the validation process in real-time you can add a
ValidationListener
to this context by using the
addValidationListener(ValidationListener)
method.
The level and version parameter determine which SBML specifications are used. For more informations look up sbml.org
Constructor | Description |
---|---|
ValidationContext(int level,
int version) |
Creates a new
ValidationContext for the given SBML level and version. |
ValidationContext(int level,
int version,
AnyConstraint<java.lang.Object> rootConstraint,
java.util.Set<SBMLValidator.CHECK_CATEGORY> categories) |
Creates a new
ValidationContext for the given SBML level and version. |
Modifier and Type | Method | Description |
---|---|---|
void |
addValidationListener(ValidationListener listener) |
Adds a
ValidationListener to this context. |
void |
clear() |
Clears the loaded constraints
|
void |
didValidate(AnyConstraint<?> constraint,
java.lang.Object o,
boolean success) |
Calls the
ValidationListener.didValidate(ValidationContext, AnyConstraint, Object, boolean)
method on all the listeners. |
void |
enableCheckCategories(SBMLValidator.CHECK_CATEGORY[] categories,
boolean enable) |
Calls
enableCheckCategory(CHECK_CATEGORY, boolean) for every
SBMLValidator.CHECK_CATEGORY in the array. |
void |
enableCheckCategory(SBMLValidator.CHECK_CATEGORY category,
boolean enable) |
Enables or disables the selected category.
|
SBMLValidator.CHECK_CATEGORY[] |
getCheckCategories() |
Returns all the enabled check categories.
|
java.lang.Class<?> |
getConstraintType() |
Gets the
Class on which the root constraint is typed. |
java.util.Map<java.lang.String,java.lang.Object> |
getHashMap() |
Gets the validation objects
HashMap . |
int |
getLevel() |
Returns the used level of SBML
|
ValuePair<java.lang.Integer,java.lang.Integer> |
getLevelAndVersion() |
Returns the SBML level and version of the
ValidationContext . |
java.lang.Integer |
getPackageVersion(java.lang.String packageShortName) |
Gets the package version to validate.
|
AnyConstraint<java.lang.Object> |
getRootConstraint() |
Returns the root constraint from this context.
|
boolean |
getValidateRecursively() |
Returns
true if the validation also validate every child of a
TreeNode . |
int |
getVersion() |
Returns the used version of SBML
|
boolean |
isEnabledCategory(SBMLValidator.CHECK_CATEGORY checkCategory) |
Returns true if the given
SBMLValidator.CHECK_CATEGORY is enabled in this ValidationContext . |
boolean |
isLevelAndVersionEqualTo(int level,
int version) |
Checks if the level and version of this context are both the same as the
given values.
|
boolean |
isLevelAndVersionGreaterEqualThan(int level,
int version) |
Checks if the level and version of this context is greater or equal to the
given values.
|
boolean |
isLevelAndVersionGreaterThan(int level,
int version) |
Checks if the level and version of this context is greater than the given
level and version.
|
boolean |
isLevelAndVersionLesserEqualThan(int level,
int version) |
Checks if the level and version of this context is lesser or equal to the
given values.
|
boolean |
isLevelAndVersionLessThan(int level,
int version) |
Checks if the level and version of this context is less then the given
level and version.
|
void |
loadConstraints(java.lang.Class<?> clazz) |
Loads the constraints to validate a Object from the class.
|
void |
loadConstraints(java.lang.Class<?> clazz,
int level,
int version) |
Loads the constraints and sets the level and version.
|
void |
loadConstraints(java.lang.Class<?> clazz,
int level,
int version,
SBMLValidator.CHECK_CATEGORY[] categories) |
Loads the constraints to validate a Object from the given class.
|
void |
loadConstraintsForAttribute(java.lang.Class<?> clazz,
java.lang.String attributeName) |
Validates a single attribute.
|
boolean |
removeValidationListener(ValidationListener listener) |
Removes a
ValidationListener from this context. |
void |
setLevel(int level) |
Set the SBML level of the
ValidationContext . |
void |
setLevelAndVersion(int level,
int version) |
Sets the level/version and clears the root constraint if one of these
values differs from the current values.
|
void |
setPackageVersion(java.lang.String packageShortName,
int packageVersion) |
Sets the package version to validate
|
void |
setRootConstraint(AnyConstraint<java.lang.Object> rootConstraint,
java.lang.Class<?> constraintType) |
Sets the root constraints and the root constraint class type.
|
void |
setValidateRecursively(boolean recursive) |
Sets the recursivity of the validation.
|
void |
setVersion(int version) |
Sets the version of the context and clears the root constraint.
|
boolean |
validate(java.lang.Object o) |
Validates the object against the loaded constraints.
|
boolean |
validate(java.lang.Object o,
boolean clearMap) |
Validates the object with the loaded constraints and clears the HashMap
afterwards if the clearMap is set to
true . |
void |
willValidate(AnyConstraint<?> constraint,
java.lang.Object o) |
Allows a
ValidationListener to perform some operation before
a constraint is called. |
public ValidationContext(int level, int version)
ValidationContext
for the given SBML level and version.level
- the SBML levelversion
- the SBML versionpublic ValidationContext(int level, int version, AnyConstraint<java.lang.Object> rootConstraint, java.util.Set<SBMLValidator.CHECK_CATEGORY> categories)
ValidationContext
for the given SBML level and version.level
- the SBML levelversion
- the SBML versionrootConstraint
- the root constraint for the validationcategories
- the SBMLValidator.CHECK_CATEGORY
spublic void addValidationListener(ValidationListener listener)
ValidationListener
to this context.
A ValidationContext
can have
multiple listeners and every attached listener will receive the events from
the validation.
listener
- the listener to addpublic void clear()
public final void didValidate(AnyConstraint<?> constraint, java.lang.Object o, boolean success)
ValidationListener.didValidate(ValidationContext, AnyConstraint, Object, boolean)
method on all the listeners.
Will be called every time after a constraints finished the checks.
constraint
- the constraint that has been validatedo
- the object on which the constraint that has been validatedsuccess
- true
if the constraint was successful, false
if an error was detected.public void enableCheckCategory(SBMLValidator.CHECK_CATEGORY category, boolean enable)
The enabled categories determines which constraints will be loaded in
loadConstraints(Class, int, int, CHECK_CATEGORY[])
. This function
won't change the root constraint.
category
- the category to enable or disableenable
- a boolean to tell if we enable (true
) or disable (false
) the categoryloadConstraints(Class, int, int, CHECK_CATEGORY[])
public void enableCheckCategories(SBMLValidator.CHECK_CATEGORY[] categories, boolean enable)
enableCheckCategory(CHECK_CATEGORY, boolean)
for every
SBMLValidator.CHECK_CATEGORY
in the array.categories
- the categories to enable or disableenable
- a boolean to tell if we enable (true
) or disable (false
) the categoriesSBMLValidator.CHECK_CATEGORY
public void loadConstraints(java.lang.Class<?> clazz)
Uses the CheckCategories, level and version of this context. Resets the root constraint.
clazz
- the class to load constraint forpublic void loadConstraints(java.lang.Class<?> clazz, int level, int version)
clazz
- the class to load constraint forlevel
- the SBML levelversion
- the SBML versionloadConstraints(Class)
public void loadConstraints(java.lang.Class<?> clazz, int level, int version, SBMLValidator.CHECK_CATEGORY[] categories)
Sets, as well, the level and version and the enabled categories
of the ValidationContext
.
clazz
- the class to load constraint forlevel
- the SBML levelversion
- the SBML versioncategories
- the categories to enableloadConstraints(Class)
public void loadConstraintsForAttribute(java.lang.Class<?> clazz, java.lang.String attributeName)
clazz
- the class to load constraint forattributeName
- the attribute name to load constraint forpublic SBMLValidator.CHECK_CATEGORY[] getCheckCategories()
public java.lang.Class<?> getConstraintType()
Class
on which the root constraint is typed.Class
on which the root constraint is typed.public java.util.Map<java.lang.String,java.lang.Object> getHashMap()
HashMap
.
Constraints can use this HashMap
to store additional
information if needed.
Notice that this method doesn't return a copy, but a reference to the actual instance.
HashMap
.public int getLevel()
int
getVersion()
,
getLevelAndVersion()
public ValuePair<java.lang.Integer,java.lang.Integer> getLevelAndVersion()
ValidationContext
.
This value determines which constraints will be loaded and in which way broken constraints will be logged.
getLevel()
,
getVersion()
public AnyConstraint<java.lang.Object> getRootConstraint()
The value may be
null
if no constraint was loaded. The
AnyConstraint.check(ValidationContext, Object)
method will be called on
the root constraint in validate(Object)
.
null
if no constraints were loadedloadConstraints(Class, int, int, CHECK_CATEGORY[])
public int getVersion()
int
getLevel()
,
getLevelAndVersion()
public boolean getValidateRecursively()
true
if the validation also validate every child of a
TreeNode
.true
if the validation is done recursively.public boolean isEnabledCategory(SBMLValidator.CHECK_CATEGORY checkCategory)
SBMLValidator.CHECK_CATEGORY
is enabled in this ValidationContext
.checkCategory
- the check categorySBMLValidator.CHECK_CATEGORY
is enabled in this ValidationContext
.public boolean isLevelAndVersionLessThan(int level, int version)
A level and version pair is less if either the level is smaller or the level is equal but the version is smaller.
level
- the SBML levelversion
- the SBML versiontrue
if the level and version of this context is less then the given
level and version.public boolean isLevelAndVersionGreaterThan(int level, int version)
A level and version pair is greater if either the level is greater or the level is equal but the version is greater.
level
- the SBML levelversion
- the SBML versiontrue
if the level and version of this context is greater than the given
level and version.public boolean isLevelAndVersionEqualTo(int level, int version)
level
- the SBML levelversion
- the SBML versiontrue
if the level and version of this context are both the same as the
given values.public boolean isLevelAndVersionGreaterEqualThan(int level, int version)
level
- the SBML levelversion
- the SBML versiontrue
if the level and version of this context is greater or equal to the
given values.isLevelAndVersionGreaterThan(int, int)
,
isLevelAndVersionEqualTo(int, int)
public boolean isLevelAndVersionLesserEqualThan(int level, int version)
level
- the SBML levelversion
- the SBML versiontrue
if the level and version of this context is lesser or equal to the
given values.isLevelAndVersionLessThan(int, int)
,
isLevelAndVersionEqualTo(int, int)
public boolean removeValidationListener(ValidationListener listener)
ValidationListener
from this context.
Returns true
if the listener was removed.
listener
- the listener to removetrue
if the listener was removedpublic void setLevel(int level)
ValidationContext
.level
- the SBML levelsetLevelAndVersion(int, int)
public void setLevelAndVersion(int level, int version)
level
- the SBML levelversion
- the SBML versionpublic void setPackageVersion(java.lang.String packageShortName, int packageVersion)
packageShortName
- the package short labelpackageVersion
- the package versionpublic java.lang.Integer getPackageVersion(java.lang.String packageShortName)
It can return Null
or '-1', in which case it means that we do not need to validate
the package.
packageShortName
- public void setRootConstraint(AnyConstraint<java.lang.Object> rootConstraint, java.lang.Class<?> constraintType)
rootConstraint
- the root constraintconstraintType
- the constraint typepublic void setValidateRecursively(boolean recursive)
If set to true, the validation context will try to validate also the child
of a TreeNode
instance.
recursive
- boolean to indicate if the validation should be recursive or notpublic void setVersion(int version)
version
- the SBML versionpublic boolean validate(java.lang.Object o)
o
- object to be validatedpublic boolean validate(java.lang.Object o, boolean clearMap)
true
.o
- the object to validateclearMap
- boolean to indicate if we need to clear the context after validationtrue
if the object passed successfully validation.public void willValidate(AnyConstraint<?> constraint, java.lang.Object o)
ValidationListener
to perform some operation before
a constraint is called.
This method will be called every time before a constraints starts its tests.
constraint
- the constraint that will be calledo
- the object on which the constraint will be called