biz.c24.io.api.data
Class ValidationManager

java.lang.Object
  extended by biz.c24.io.api.data.ValidationManager
All Implemented Interfaces:
Serializable

public final class ValidationManager
extends Object
implements Serializable

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.

See Also:
Serialized Form

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 ValidationEvents to registered listeners when validation failures are detected.
 boolean validateByEvents(Object object, DataComponent component, ComplexDataObject context)
          Validate the given object and fire ValidationEvents 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

ValidationManager

public ValidationManager()
Creates a new instance.


ValidationManager

public ValidationManager(ValidationConstraints constraints)
Creates a new instance from the specified set of constraints.

Parameters:
constraints - The validation constraints to use.

ValidationManager

public ValidationManager(ValidationManager clone)
Creates a new instances, cloning the specified instance.

Parameters:
clone - The instance to be cloned.
Method Detail

getConstraints

public ValidationConstraints getConstraints()
Returns the validation constraints used to control the validation process.

Returns:
The validation constraints.

setConstraints

public void setConstraints(ValidationConstraints constraints)
Sets the validation constraints used to control the validation process.

Parameters:
constraints - The validation constraints.

getStatistics

public ValidationStatistics getStatistics()
Returns the validation statistics which measure the instances being validated.

Returns:
The validation statistics.

getLog

public Logger getLog()
Returns the logger to be used to log messages during the validation process.

Returns:
The logger

setLog

public void setLog(Logger log)
Set the logger to be used to log messages during the validation process.

Parameters:
log - The logger.

clearPredicates

public void clearPredicates()
Clear the predicates.


setPredicateEnabled

public void setPredicateEnabled(String predicate,
                                boolean enabled)
Manually sets whether a particular predicate is enabled.

Parameters:
predicate - The predicate.
enabled - Whether the predicate should be enabled

isPredicateEnabled

public boolean isPredicateEnabled(String predicate)
Returns whether or not the specified predicate is enabled.

Parameters:
predicate - The predicate to check.
Returns:
Whether the predicate is enabled.

getCachedXPath

public IOXPath getCachedXPath(XPathStatement statement)
                       throws IOXPathException
Returns an instance for the supplied statement creating one on the fly and caching it if required.

Parameters:
statement - The XPath statement.
Returns:
The IOXPath object.
Throws:
IOXPathException - If there is a problem with the statement.

getCachedXQuery

public IOXPath getCachedXQuery(XQueryStatement statement)
                        throws IOXPathException
Returns an instance for the supplied statement creating one on the fly and caching it if required.

Parameters:
statement - The XQuery statement.
Returns:
The IOXPath object.
Throws:
IOXPathException - If there is a problem with the statement.

getCachedRegExpEvaluator

public RegExpEvaluator getCachedRegExpEvaluator(PatternTypeEnum patternTypeEnum,
                                                String patternMatch)
                                         throws Exception
Returns an instance of the Pattern and caching it

Parameters:
patternTypeEnum - The type of Regular Expression
patternMatch - The pattern match
Returns:
The cached RegExpEvaluator
Throws:
Exception

getCachedSaxonConfiguration

public net.sf.saxon.Configuration getCachedSaxonConfiguration()
Returns the shared Saxon Configuration used by XPath statements creating it on the fly and caching it if required.

Returns:
The configuration.

fireValidationEvent

public void fireValidationEvent(ValidationEvent event)
                         throws ValidationException
Call back to notify the manager of an event during the validation process.

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 ValidationListeners.
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.

Parameters:
event - The event to fire.
Throws:
ValidationException - If the validation process was started in exception mode and validation fails.

addValidationListener

public void addValidationListener(ValidationListener listener)
Adds a validation listener to be notified of validation events. Note: validateByEvents(ComplexDataObject) or validateByEvents(Object, DataComponent, ComplexDataObject) must be called for events to be propagated to listeners.

Parameters:
listener - The validation listener to be added.

removeValidationListener

public void removeValidationListener(ValidationListener listener)
Removes a validation listener.

Parameters:
listener - The validation listener to be removed.

getValidationListeners

public ValidationListener[] getValidationListeners()
Returns the validation listeners added to this manager.

Returns:
The validation listeners.

checkPredicates

public boolean checkPredicates(ValidationRule v,
                               ComplexDataObject context)
Checks the predicate conditions have passed for the context.

Parameters:
context - The context.
Returns:
Whether the predicates have all passed.

validateByException

public void validateByException(ComplexDataObject object)
                         throws ValidationException
Validate the given ComplexDataObject and throw an exception when the first validation failure is detected.

Parameters:
object - The object to be validated.
Throws:
ValidationException - If validation failed.

validateByException

public void validateByException(Object object,
                                DataComponent component,
                                ComplexDataObject context)
                         throws ValidationException
Validate the given object and throw an exception when the first validation failure is detected.

Parameters:
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.
Throws:
ValidationException - If validation failed.

validateByEvents

public boolean validateByEvents(ComplexDataObject object)
Validate the given ComplexDataObject and fire ValidationEvents to registered listeners when validation failures are detected.

Parameters:
object - The object to be validated.
Returns:
Whether or not validation passed.

validateByEvents

public boolean validateByEvents(Object object,
                                DataComponent component,
                                ComplexDataObject context)
Validate the given object and fire ValidationEvents to registered listeners when validation failures are detected.

Parameters:
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.
Returns:
Whether or not validation passed.


C24 Technologies © 2002-2012: All Rights Reserved.