|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbiz.c24.io.api.data.ValidationManager
public final class ValidationManager
A manager for running validations of C24 Integration Objects objects.
This class centralizes all validation configuration, previously dispersed within ComplexDataObject
and other API classes.
By extracting stateful validation properties such as validation listeners from the objects being validated, it gives far simpler control over the process
and leaves a much cleaner object model. And by splitting the old generic ComplexDataObject.validate() method into
validateByEvents(ComplexDataObject)
, validateByEvents(Object, DataComponent, ComplexDataObject)
and
validateByException(ComplexDataObject)
, validateByException(Object, DataComponent, ComplexDataObject)
it is now possible to eliminate
much of 'boiler-plate' code set up the event based validation mechanism and then was forced to catch and ignore validation exceptions which could never
have been thrown.
Note that this class is not synchronized. If
multiple threads access a ValidationManager instance concurrently, and at
least one of the threads is in the process of calling one of the validateBy* methods, it must be
synchronized externally.
Warning: Serialized objects of this class or of a deployed class which is derived from it may not be compatible with future releases of C24 Integreation Objects. The current serialization support is appropriate for short term storage or RMI between applications running the same version of C24 Integreation Objects.
Constructor Summary | |
---|---|
ValidationManager()
Creates a new instance. |
|
ValidationManager(ValidationConstraints constraints)
Creates a new instance from the specified set of constraints. |
|
ValidationManager(ValidationManager clone)
Creates a new instances, cloning the specified instance. |
Method Summary | |
---|---|
void |
addValidationListener(ValidationListener listener)
Adds a validation listener to be notified of validation events. |
boolean |
checkPredicates(ValidationRule v,
ComplexDataObject context)
Checks the predicate conditions have passed for the context. |
void |
clearPredicates()
Clear the predicates. |
void |
fireValidationEvent(ValidationEvent event)
Call back to notify the manager of an event during the validation process. |
RegExpEvaluator |
getCachedRegExpEvaluator(PatternTypeEnum patternTypeEnum,
String patternMatch)
Returns an instance of the Pattern and caching it |
net.sf.saxon.Configuration |
getCachedSaxonConfiguration()
Returns the shared Saxon Configuration used by XPath statements creating it on the fly and caching it if required. |
IOXPath |
getCachedXPath(XPathStatement statement)
Returns an instance for the supplied statement creating one on the fly and caching it if required. |
IOXPath |
getCachedXQuery(XQueryStatement statement)
Returns an instance for the supplied statement creating one on the fly and caching it if required. |
ValidationConstraints |
getConstraints()
Returns the validation constraints used to control the validation process. |
Logger |
getLog()
Returns the logger to be used to log messages during the validation process. |
ValidationStatistics |
getStatistics()
Returns the validation statistics which measure the instances being validated. |
ValidationListener[] |
getValidationListeners()
Returns the validation listeners added to this manager. |
boolean |
isPredicateEnabled(String predicate)
Returns whether or not the specified predicate is enabled. |
void |
removeValidationListener(ValidationListener listener)
Removes a validation listener. |
void |
setConstraints(ValidationConstraints constraints)
Sets the validation constraints used to control the validation process. |
void |
setLog(Logger log)
Set the logger to be used to log messages during the validation process. |
void |
setPredicateEnabled(String predicate,
boolean enabled)
Manually sets whether a particular predicate is enabled. |
boolean |
validateByEvents(ComplexDataObject object)
Validate the given ComplexDataObject and fire ValidationEvent s to registered listeners when validation failures are detected. |
boolean |
validateByEvents(Object object,
DataComponent component,
ComplexDataObject context)
Validate the given object and fire ValidationEvent s to registered listeners when validation failures are detected. |
void |
validateByException(ComplexDataObject object)
Validate the given ComplexDataObject and throw an exception when the first validation failure is detected. |
void |
validateByException(Object object,
DataComponent component,
ComplexDataObject context)
Validate the given object and throw an exception when the first validation failure is detected. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ValidationManager()
public ValidationManager(ValidationConstraints constraints)
constraints
- The validation constraints to use.public ValidationManager(ValidationManager clone)
clone
- The instance to be cloned.Method Detail |
---|
public ValidationConstraints getConstraints()
public void setConstraints(ValidationConstraints constraints)
constraints
- The validation constraints.public ValidationStatistics getStatistics()
public Logger getLog()
public void setLog(Logger log)
log
- The logger.public void clearPredicates()
public void setPredicateEnabled(String predicate, boolean enabled)
predicate
- The predicate.enabled
- Whether the predicate should be enabledpublic boolean isPredicateEnabled(String predicate)
predicate
- The predicate to check.
public IOXPath getCachedXPath(XPathStatement statement) throws IOXPathException
statement
- The XPath statement.
IOXPathException
- If there is a problem with the statement.public IOXPath getCachedXQuery(XQueryStatement statement) throws IOXPathException
statement
- The XQuery statement.
IOXPathException
- If there is a problem with the statement.public RegExpEvaluator getCachedRegExpEvaluator(PatternTypeEnum patternTypeEnum, String patternMatch) throws Exception
patternTypeEnum
- The type of Regular ExpressionpatternMatch
- The pattern match
Exception
public net.sf.saxon.Configuration getCachedSaxonConfiguration()
public void fireValidationEvent(ValidationEvent event) throws ValidationException
If the validation process was started via a call to validateByEvents(ComplexDataObject)
or validateByEvents(Object, DataComponent, ComplexDataObject)
then the event will be sent to all registered ValidationListener
s.
If the validation process was started via a call to validateByException(ComplexDataObject)
or validateByException(Object, DataComponent, ComplexDataObject)
then the event will be wrapped in an exception and thrown.
event
- The event to fire.
ValidationException
- If the validation process was started in exception mode and validation fails.public void addValidationListener(ValidationListener listener)
validateByEvents(ComplexDataObject)
or validateByEvents(Object, DataComponent, ComplexDataObject)
must be called for events to be propagated to listeners.
listener
- The validation listener to be added.public void removeValidationListener(ValidationListener listener)
listener
- The validation listener to be removed.public ValidationListener[] getValidationListeners()
public boolean checkPredicates(ValidationRule v, ComplexDataObject context)
context
- The context.
public void validateByException(ComplexDataObject object) throws ValidationException
ComplexDataObject
and throw an exception when the first validation failure is detected.
object
- The object to be validated.
ValidationException
- If validation failed.public void validateByException(Object object, DataComponent component, ComplexDataObject context) throws ValidationException
object
- The object to be validated - commonly a String, Integer, Double, Date etc.component
- The Element
or Attribute
inside context
which defines object
.context
- The parent of object
- could be null
.
ValidationException
- If validation failed.public boolean validateByEvents(ComplexDataObject object)
ComplexDataObject
and fire ValidationEvent
s to registered listeners when validation failures are detected.
object
- The object to be validated.
public boolean validateByEvents(Object object, DataComponent component, ComplexDataObject context)
ValidationEvent
s to registered listeners when validation failures are detected.
object
- The object to be validated - commonly a String, Integer, Double, Date etc.component
- The Element
or Attribute
inside context
which defines object
.context
- The parent of object
- could be null
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |