org.apache.bval
Class BeanValidator<T extends ValidationListener>

java.lang.Object
  extended by org.apache.bval.BeanValidator<T>

public class BeanValidator<T extends ValidationListener>
extends Object

Description: Top-Level API-class to validate objects or object-trees. You can invoke, extend or utilize this class if you need other ways to integrate validation in your application.

This class supports cyclic object graphs by keeping track of validated instances in the validation context.


Constructor Summary
BeanValidator()
          Create a new BeanValidator instance.
BeanValidator(MetaBeanFinder metaBeanFinder)
          Create a new BeanValidator instance.
 
Method Summary
protected  ValidationContext<T> createContext()
          factory method - overwrite in subclasses
protected  T createResults()
          factory method - overwrite in subclasses
protected
<VL extends ValidationListener>
boolean
determineMetaBean(Validate validate, Object parameter, ValidationContext<VL> context)
          Determine the metabean for the given object.
 MetaBeanFinder getMetaBeanFinder()
          Get the metabean finder associated with this validator.
 boolean isTreatMapsLikeBeans()
           
 void setTreatMapsLikeBeans(boolean treatMapsLikeBeans)
           
 T validate(Object bean)
          Convenience API.
 T validate(Object bean, MetaBean metaBean)
          Convenience API.
protected
<VL extends ValidationListener>
void
validateBeanNet(ValidationContext<VL> context)
           internal validate a bean (=not a collection of beans) and its related beans
 T validateCall(Method method, Object[] parameters)
          Validate the method parameters based on @Validate annotations.
 T validateProperty(Object bean, MetaProperty metaProperty)
          Convenience API.
protected
<VL extends ValidationListener>
void
validateRelatedBean(ValidationContext<VL> context, MetaProperty prop)
          Validate a property of a graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanValidator

public BeanValidator()
Create a new BeanValidator instance. Convenience constructor. Use the global instance of MetaBeanManagerFactory.getFinder().


BeanValidator

public BeanValidator(MetaBeanFinder metaBeanFinder)
Create a new BeanValidator instance.

Parameters:
metaBeanFinder -
Method Detail

validate

public T validate(Object bean)
Convenience API. validate a root object with all related objects with its default metaBean definition.

Parameters:
bean -
Returns:
results - validation results found

validate

public T validate(Object bean,
                  MetaBean metaBean)
Convenience API. validate a root object with all related objects according to the metaBean.

Parameters:
bean - - a single bean or a collection of beans (that share the same metaBean!)
metaBean -
Returns:
results - validation results found

validateCall

public T validateCall(Method method,
                      Object[] parameters)
Validate the method parameters based on @Validate annotations. Requirements: Parameter, that are to be validated must be annotated with @Validate

Parameters:
method - - a method
parameters - - the parameters suitable to the method
Returns:
a validation result or null when there was nothing to validate
See Also:
Validate

determineMetaBean

protected <VL extends ValidationListener> boolean determineMetaBean(Validate validate,
                                                                    Object parameter,
                                                                    ValidationContext<VL> context)
Determine the metabean for the given object.

Type Parameters:
VL -
Parameters:
validate -
parameter -
context -
Returns:
true when validation should happen, false to skip it

createResults

protected T createResults()
factory method - overwrite in subclasses

Returns:
ValidationListener of the proper type

createContext

protected ValidationContext<T> createContext()
factory method - overwrite in subclasses

Returns:
ValidationContext parameterized with our listener type

validateProperty

public T validateProperty(Object bean,
                          MetaProperty metaProperty)
Convenience API. validate a single property.

Parameters:
bean - - the root object
metaProperty - - metadata for the property
Returns:
validation results

validateBeanNet

protected <VL extends ValidationListener> void validateBeanNet(ValidationContext<VL> context)
internal validate a bean (=not a collection of beans) and its related beans


validateRelatedBean

protected <VL extends ValidationListener> void validateRelatedBean(ValidationContext<VL> context,
                                                                   MetaProperty prop)
Validate a property of a graph.

Type Parameters:
VL -
Parameters:
context -
prop -

isTreatMapsLikeBeans

public boolean isTreatMapsLikeBeans()

setTreatMapsLikeBeans

public void setTreatMapsLikeBeans(boolean treatMapsLikeBeans)

getMetaBeanFinder

public MetaBeanFinder getMetaBeanFinder()
Get the metabean finder associated with this validator.

Returns:
a MetaBeanFinder
See Also:
MetaBeanManagerFactory.getFinder()


Copyright © 2010-2012 Apache Software Foundation. All Rights Reserved.