-
Notifications
You must be signed in to change notification settings - Fork 24
Home
Roman Schulte edited this page Aug 19, 2016
·
23 revisions
#JSBML Developer Wiki
##Offline Validation The offline validator is a alternative way to validate you document against the specifications of SBML. As the name will suggest it doesn't need internet connection.
###How it's work
One of the most important classes of the offline validator is the ValidationContext
. In the best case, this should be the only class the user will ever need. To reduce overhead, this class is also designed to be reusable.
This his how you setup a validation context:
// Obtain a new instance
ValidationContext ctx = new ValidationContext();
// Loading constraints to the context
ctx.loadConstraints(MyClass.class);
// Perform validation
MyClass myObject = new MyClass();
boolean isValid = ctx.validate(myObject);```
- ValidationContext:
* Most important class for user
* Should do all the work and easy to use
* Should be reusable
* Has a HashMap to store additional data
+ Cleared before validation starts
- Context calls the factory to get constraints
* Factory checks class hierarchy and is looking for ConstraintDeclarations
* Remember already visited classes to avoid double constraints
- Looking for ConstraintDeclaration
* Must be in package
* Must be named like class and ends with 'Constraints'
* Must be assignable to ConstraintDeclaration
- AbstractConstraintDeclaration:
* provides most functions
+ You only have to take care about which constraints should be loaded
+ and how each of the constraints will work
+ Creates automatically ConstraintGroups and ignores non existing constraints
+ Groups have always at least one member
* uses Reflection to find constraint declaration
+ Caches found classes and remembers not existing classes
* Caches constraints
+ Key = className + ErrorCode
+ Two constraints with same ErrorCode but different targets are possible
- TreeNodeConstraints
* Has special constraint which points the context to every child
* The constraint does nothing if recursive validation is disabled
###Add Constraints
- Create ConstraintDeclaration
* Remember naming convention and package
* Should extending AbstractConstraintDeclaration
- Collect ErrorCodes
- Provide ValidationFunctions
- Use level/version of context
- Remember that's cached
###Adding Error Objects
- Stored in JSON
- One big Dictionary/HashMap. ErrorCode as String is key for Entry
- Entry is again Dic/HashMap. Has following attributes:
+ "NAME" =
- Example Structure