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
setValidateRecursivly(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
Modifier and Type | Field and Description |
---|---|
private java.util.Set<SBMLValidator.CHECK_CATEGORY> |
categories |
private java.lang.Class<?> |
constraintType |
private java.util.HashMap<java.lang.String,java.lang.Object> |
hashMap |
private int |
level |
private java.util.Set<ValidationListener> |
listener |
protected static org.apache.log4j.Logger |
logger
Log4j logger
|
private boolean |
recursiv |
private AnyConstraint<java.lang.Object> |
rootConstraint |
private int |
version |
Constructor and Description |
---|
ValidationContext(int level,
int version) |
ValidationContext(int level,
int version,
AnyConstraint<java.lang.Object> rootConstraint,
java.util.Set<SBMLValidator.CHECK_CATEGORY> categories) |
Modifier and Type | Method and Description |
---|---|
void |
addValidationListener(ValidationListener listener)
Adds a
ValidationListener . |
void |
clear()
Clears the loaded constraints
|
void |
didValidate(AnyConstraint<?> constraint,
java.lang.Object o,
boolean success)
Will be called every time before a constraints starts his tests.
|
void |
enableCheckCategories(SBMLValidator.CHECK_CATEGORY[] categories,
boolean enable)
Calls
#enableCheckCategory(CheckCategory, boolean) for every
CheckCategory in the array. |
void |
enableCheckCategory(SBMLValidator.CHECK_CATEGORY category,
boolean enable)
Enables or disables the selected category.
|
SBMLValidator.CHECK_CATEGORY[] |
getCheckCategories()
Returns the list of all enabled check categories.
|
java.lang.Class<?> |
getConstraintType()
Gets the
Class on which the root constraint is typed. |
java.util.HashMap<java.lang.String,java.lang.Object> |
getHashMap()
Constraints can use this
HashMap to store additional
information. |
int |
getLevel()
Returns the used level of SBML
|
ValuePair<java.lang.Integer,java.lang.Integer> |
getLevelAndVersion()
This value determines which constraints will be loaded and in which way
broken constraints will be logged.
|
AnyConstraint<java.lang.Object> |
getRootConstraint()
Returns the root constraint from this context.
|
boolean |
getValidateRecursivly()
Returns
true if the validation also validate every child of a
TreeNode |
int |
getVersion()
Returns the used version of SBML
|
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)
Sets the level and version and loads the constraints.
|
void |
loadConstraints(java.lang.Class<?> clazz,
int level,
int version,
SBMLValidator.CHECK_CATEGORY[] categories) |
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)
|
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 |
setRootConstraint(AnyConstraint<java.lang.Object> rootConstraint,
java.lang.Class<?> constraintType) |
void |
setValidateRecursivly(boolean recursiv)
If set to true, the validation context will try to validate also the childs
of a TreeNode interface.
|
void |
setVersion(int version)
Set 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
true . |
void |
willValidate(AnyConstraint<?> constraint,
java.lang.Object o) |
protected static final transient org.apache.log4j.Logger logger
private AnyConstraint<java.lang.Object> rootConstraint
private java.util.Set<SBMLValidator.CHECK_CATEGORY> categories
private java.lang.Class<?> constraintType
private java.util.Set<ValidationListener> listener
private java.util.HashMap<java.lang.String,java.lang.Object> hashMap
private int level
private int version
private boolean recursiv
public ValidationContext(int level, int version)
public ValidationContext(int level, int version, AnyConstraint<java.lang.Object> rootConstraint, java.util.Set<SBMLValidator.CHECK_CATEGORY> categories)
public void addValidationListener(ValidationListener listener)
ValidationListener
. A ValidationContext
can have
multiple listeners and every attached listener will receive the events from
the validation.listener
- public void clear()
public void didValidate(AnyConstraint<?> constraint, java.lang.Object o, boolean success)
constraint
- o
- success
- public void enableCheckCategory(SBMLValidator.CHECK_CATEGORY category, boolean enable)
The enabled categories determines which constraints will be loaded in
#loadConstraints(Class, int, int, CheckCategory[])
. This function
won't change the root
constraint.
catergoy
- enable
- #loadConstraints(Class, int, int, CheckCategory[])
public void enableCheckCategories(SBMLValidator.CHECK_CATEGORY[] categories, boolean enable)
#enableCheckCategory(CheckCategory, boolean)
for every
CheckCategory
in the array.categories
- enable
- CheckCategory
public void loadConstraints(java.lang.Class<?> clazz)
clazz
- public void loadConstraints(java.lang.Class<?> clazz, int level, int version)
cclass
- level
- version
- loadConstraints(Class)
public void loadConstraints(java.lang.Class<?> clazz, int level, int version, SBMLValidator.CHECK_CATEGORY[] categories)
class
- level
- version
- categories
- public void loadConstraintsForAttribute(java.lang.Class<?> clazz, java.lang.String attributeName)
pkg
- attributeName
- object
- public SBMLValidator.CHECK_CATEGORY[] getCheckCategories()
public java.lang.Class<?> getConstraintType()
Class
on which the root constraint is typed.public java.util.HashMap<java.lang.String,java.lang.Object> getHashMap()
HashMap
to store additional
information.
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()
getLevel()
,
getVersion()
public AnyConstraint<java.lang.Object> getRootConstraint()
null
if no constraint was loaded. The
AnyConstraint.check(ValidationContext, Object)
will be called in
validate(Object)
null
if no constraints were loaded#loadConstraints(Class, int, int, CheckCategory[])
public int getVersion()
int
getLevel()
,
getLevelAndVersion()
public boolean getValidateRecursivly()
true
if the validation also validate every child of a
TreeNode
public boolean isLevelAndVersionLessThan(int level, int version)
level
- version
- public boolean isLevelAndVersionGreaterThan(int level, int version)
level
- version
- public boolean isLevelAndVersionEqualTo(int level, int version)
level
- version
- public boolean isLevelAndVersionGreaterEqualThan(int level, int version)
level
- version
- isLevelAndVersionGreaterThan(int, int)
,
isLevelAndVersionEqualTo(int, int)
public boolean isLevelAndVersionLesserEqualThan(int level, int version)
level
- version
- isLevelAndVersionLessThan(int, int)
,
isLevelAndVersionEqualTo(int, int)
public boolean removeValidationListener(ValidationListener listener)
ValidationListener
from this context.
Returns true
if the listener was removed.listener
- public void setLevel(int level)
level
- setLevelAndVersion(int, int)
public void setLevelAndVersion(int level, int version)
level
- version
- public void setRootConstraint(AnyConstraint<java.lang.Object> rootConstraint, java.lang.Class<?> constraintType)
public void setValidateRecursivly(boolean recursiv)
recursiv
- public void setVersion(int version)
version
- public boolean validate(java.lang.Object o)
o,
- object to be validatedpublic boolean validate(java.lang.Object o, boolean clearMap)
true
.o
- clearMap,
- clears HashMap after validationpublic void willValidate(AnyConstraint<?> constraint, java.lang.Object o)