| Package | org.granite.validation |
| Class | public class ValidatorFactory |
ValidatorFactory class is the entry point of the validation
framework. It serves as validator instance factory and holds all
specific validation configuration such as constraint registration, message
interpolator configuration, traversable resolver configuration, namespace
resolver configuration, etc.
All standard constraints (as specified by the JSR-303) are automatically
registered and may be used in your bean without any specific configuration.
For user defined constraints, they must be registered with the
registerConstraintClass method, otherwise they will be ignored.
A typical usage would be:
public class MyAnnotatedBean {
[NotNull] [Size(min="4")]
public var property:String;
}
var factory:ValidatorFactory = ValidatorFactory.getInstance();
var violations:Array = factory.validate(myAnnotatedBean);
violations = factory.validateProperty(myAnnotatedBean, "property");
violations = factory.validateValue(Type.forClass(MyAnnotatedBean), "property", "value");
See also
| Property | Defined by | ||
|---|---|---|---|
| defaultValidatorClass : Class
The default
IValidator implementation used for validation
operations. | ValidatorFactory | ||
| dispatchEvents : Boolean
Should the validation process dispatch validation events? Default is
true. | ValidatorFactory | ||
| messageInterpolator : IMessageInterpolator
The default
IMessageInterpolator implementation used for
validation operations. | ValidatorFactory | ||
| namespaceResolver : INamespaceResolver
The
INamespaceResolver implementation used for validation
operations. | ValidatorFactory | ||
| traversableResolver : ITraversableResolver
The default
ITraversableResolver implementation used for
validation operations. | ValidatorFactory | ||
| visitorHandlers : Array
The specific
IHandler classes to be used when visitating
a bean for validation. | ValidatorFactory | ||
| Method | Defined by | ||
|---|---|---|---|
|
getConstraintClass(name:String):Class
Returns a
IConstraint implementation class, based on
its unqualified class name. | ValidatorFactory | ||
|
[static]
Returns a unique instance of this
ValidatorFactory class. | ValidatorFactory | ||
|
Returns a new
IValidator implementation instance, based
on the supplied bean type. | ValidatorFactory | ||
|
getValidatorClass(type:Type):Class
Returns a
IValidator implementation class, based on
bean type. | ValidatorFactory | ||
|
registerConstraintClass(constraintClass:Class):void
Register a
IConstraint implementation class, so
annotations with its unqualified class name will be recognized as
constraint annotations. | ValidatorFactory | ||
|
registerValidatorClass(type:Type, validatorClass:Class):void
Register a
IValidator implementation class for a specific
bean type, so this IValidator implementation will be used
when encountering a bean of this type. | ValidatorFactory | ||
|
unregisterConstraintClass(constraintClass:Class):void
Unregister a
IConstraint implementation class, so
annotations with its unqualified class name won't be recognized as
constraint annotations anymore. | ValidatorFactory | ||
|
unregisterValidatorClass(type:Type):void
Unregister a
IValidator implementation class for a specific
bean type, so no specific IValidator implementation will be
used when encountering a bean of this type. | ValidatorFactory | ||
|
validate(bean:*, groups:Array = null):Array
Validate a bean.
| ValidatorFactory | ||
|
validateProperty(bean:Object, propertyName:String, groups:Array = null):Array
Validates all constraints placed on the property of
bean
named propertyName. | ValidatorFactory | ||
|
validateValue(type:Type, propertyName:String, value:Array, groups:* = null):Array
Validates all constraints placed on the property named
propertyName
of the class type would the property value be value. | ValidatorFactory | ||
| defaultValidatorClass | property |
defaultValidatorClass:Class [read-write]
The default IValidator implementation used for validation
operations. Default value is the GenericValidator class.
public function get defaultValidatorClass():Class
public function set defaultValidatorClass(value:Class):void
See also
| dispatchEvents | property |
dispatchEvents:Boolean [read-write]
Should the validation process dispatch validation events? Default is
true.
public function get dispatchEvents():Boolean
public function set dispatchEvents(value:Boolean):void
| messageInterpolator | property |
messageInterpolator:IMessageInterpolator [read-write]
The default IMessageInterpolator implementation used for
validation operations. Default value is the
DefaultMessageInterpolator class.
public function get messageInterpolator():IMessageInterpolator
public function set messageInterpolator(value:IMessageInterpolator):void
See also
| namespaceResolver | property |
namespaceResolver:INamespaceResolver [read-write]
The INamespaceResolver implementation used for validation
operations. Default value is the DefaultNamespaceResolver class.
Sample usage (the "g" namespace is used in the Size annotation):
package path.to.groups {
public interface MyGroup {}
}
var validatorFactory = ValidatorFactory.getInstance();
validatorFactory.namespaceResolver.registerNamespace("g", "path.to.groups.);
// instead of [Size(min="2", groups="path.to.groups.MyGroup")]
[Size(min="2", groups="g:MyGroup")]
public var property:String;
Note that the built-in Default group package is registered in the
default namespace, so you may use it without prefix (eg:
[Size(min="2", groups="Default")]).
public function get namespaceResolver():INamespaceResolver
public function set namespaceResolver(value:INamespaceResolver):void
See also
| traversableResolver | property |
traversableResolver:ITraversableResolver [read-write]
The default ITraversableResolver implementation used for
validation operations. Default value is the
DefaultTraversableResolver class.
public function get traversableResolver():ITraversableResolver
public function set traversableResolver(value:ITraversableResolver):void
See also
| visitorHandlers | property |
visitorHandlers:Array [read-write]
The specific IHandler classes to be used when visitating
a bean for validation. Default is null: no specific IHandler classes
other than the default ones.
public function get visitorHandlers():Array
public function set visitorHandlers(value:Array):void
See also
| getConstraintClass | () | method |
public function getConstraintClass(name:String):Class
Returns a IConstraint implementation class, based on
its unqualified class name.
name:String — the unqualified class name of a IConstraint
implementation class.
|
Class — the corresponding IConstraint implementation
class, or null if no such constraint is registered.
|
| getInstance | () | method |
public static function getInstance():ValidatorFactory
Returns a unique instance of this ValidatorFactory class.
ValidatorFactory |
| getValidator | () | method |
public function getValidator(type:Type):IValidator
Returns a new IValidator implementation instance, based
on the supplied bean type.
type:Type — bean type for which a validator instance is created.
|
IValidator —
a new validator instance.
|
See also
| getValidatorClass | () | method |
public function getValidatorClass(type:Type):Class
Returns a IValidator implementation class, based on
bean type.
type:Type — the type of a bean.
|
Class — a specific IValidator implementation class,
or the default IValidator implementation class
if no specific validator can be found.
|
| registerConstraintClass | () | method |
public function registerConstraintClass(constraintClass:Class):void
Register a IConstraint implementation class, so
annotations with its unqualified class name will be recognized as
constraint annotations. This method also allow to override a built-in
constraint definition with a specific implementation.
constraintClass:Class — the IConstraint implementation
class to be registered.
|
| registerValidatorClass | () | method |
public function registerValidatorClass(type:Type, validatorClass:Class):void
Register a IValidator implementation class for a specific
bean type, so this IValidator implementation will be used
when encountering a bean of this type.
type:Type — the type of the bean that should be validated by the supplied
IValidator implementation.
|
|
validatorClass:Class — the IValidator implementation
class to be registered.
|
| unregisterConstraintClass | () | method |
public function unregisterConstraintClass(constraintClass:Class):void
Unregister a IConstraint implementation class, so
annotations with its unqualified class name won't be recognized as
constraint annotations anymore. This method also allow to unregister a
built-in constraint definition.
constraintClass:Class — the IConstraint implementation
class to be unregistered.
|
| unregisterValidatorClass | () | method |
public function unregisterValidatorClass(type:Type):void
Unregister a IValidator implementation class for a specific
bean type, so no specific IValidator implementation will be
used when encountering a bean of this type.
type:Type — the type of the bean that shouldn't be validated by a supplied
IValidator implementation anymore.
|
| validate | () | method |
public function validate(bean:*, groups:Array = null):ArrayValidate a bean. This method is a shortcut for:
var validator:IValidator = getValidator(Type.forInstance(bean)); var violations:Array = validator.validate(bean, groups);
bean:* — the bean to be validated.
|
|
groups:Array (default = null) — an array of groups targeted for validation (default is
null, meaning that the Default group will be used).
|
Array — an array of ConstraintViolation, possibly null or
empty.
|
See also
| validateProperty | () | method |
public function validateProperty(bean:Object, propertyName:String, groups:Array = null):Array
Validates all constraints placed on the property of bean
named propertyName. This method is a shortcut for:
var validator:IValidator = getValidator(Type.forInstance(bean)); var violations:Array = validator.validateProperty(bean, propertyName, groups);
bean:Object — the bean holding the property to validate.
|
|
propertyName:String — the property name to validate.
|
|
groups:Array (default = null) — an array of groups targeted for validation (default is
null, meaning that the Default group will be used).
|
Array — an array of ConstraintViolation, possibly null or
empty.
|
See also
| validateValue | () | method |
public function validateValue(type:Type, propertyName:String, value:Array, groups:* = null):Array
Validates all constraints placed on the property named propertyName
of the class type would the property value be value.
This method is a shortcut for:
var validator:IValidator = getValidator(type); var violations:Array = validator.validateValue(type, propertyName, value, groups);
type:Type — the bean type holding the property to validate.
|
|
propertyName:String — the property name to validate.
|
|
value:Array — the property value to validate.
|
|
groups:* (default = null) — an array of groups targeted for validation (default is
null, meaning that the Default group will be used).
|
Array — an array of ConstraintViolation, possibly null or
empty.
|
See also