org.apache.openjpa.persistence.validation
Class ValidatorImpl

java.lang.Object
  extended by org.apache.openjpa.validation.AbstractValidator
      extended by org.apache.openjpa.persistence.validation.ValidatorImpl
All Implemented Interfaces:
Validator

public class ValidatorImpl
extends AbstractValidator


Constructor Summary
ValidatorImpl()
          Default constructor.
ValidatorImpl(Configuration conf)
           
ValidatorImpl(ValidatorFactory validatorFactory, ValidationMode mode)
          Type-specific constructor Returns an Exception if a Validator could not be created.
 
Method Summary
 void addValidationGroup(Integer event, Class<?>... validationGroup)
          Add a validation group for a specified event.
 void addValidationGroup(String validationGroupName, Class<?>... vgs)
          Add a validation group for the specific property.
 void addValidationGroup(String validationGroupName, String group)
          Add the validation group(s) for the specified event.
 BeanDescriptor getConstraintsForClass(Class<?> cls)
          Returns the validation constraints for the specified class
 Class<?>[] getValidationGroup(Integer event)
          Return the validation groups to be validated for a specified event
 boolean isValidating(Integer event)
          Returns whether the Validator is validating for the specified event.
<T> ValidationException
validate(T arg0, int event)
          Validates a given instance
<T> ValidationException
validateProperty(T arg0, String property, int event)
          Validates a property of a given instance
<T> ValidationException
validateValue(Class<T> arg0, String arg1, Object arg2, int event)
          Validates a value based upon the constraints applied to a given class attribute.
<T> boolean
validating(T arg0, int event)
          Returns whether validation is active for the given event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValidatorImpl

public ValidatorImpl()
Default constructor. Builds a default validator factory, if available and creates the validator. Returns an Exception if a Validator could not be created.


ValidatorImpl

public ValidatorImpl(Configuration conf)

ValidatorImpl

public ValidatorImpl(ValidatorFactory validatorFactory,
                     ValidationMode mode)
Type-specific constructor Returns an Exception if a Validator could not be created.

Parameters:
validatorFactory - Instance of validator factory to use. Specify null to use the default factory.
mode - ValdiationMode enum value
Method Detail

addValidationGroup

public void addValidationGroup(String validationGroupName,
                               Class<?>... vgs)
Add a validation group for the specific property. The properties map to a specific lifecycle event. To disable validation for a group, set the validation group to null.

Parameters:
validationGroupName -
vgs -

addValidationGroup

public void addValidationGroup(Integer event,
                               Class<?>... validationGroup)
Add a validation group for a specified event. Event definitions are defined in LifecycleEvent. To disable validation for a group, set the validation group to null.

Parameters:
event -
validationGroup -

addValidationGroup

public void addValidationGroup(String validationGroupName,
                               String group)
Add the validation group(s) for the specified event. Event definitions are defined in LifecycleEvent

Parameters:
event -
group -

getValidationGroup

public Class<?>[] getValidationGroup(Integer event)
Return the validation groups to be validated for a specified event

Parameters:
event - Lifecycle event id
Returns:
An array of validation groups

isValidating

public boolean isValidating(Integer event)
Returns whether the Validator is validating for the specified event. Based on whether validation groups are specified for the event.

Parameters:
event - the event to check for validation
Returns:
returns true if validating for this particular event

getConstraintsForClass

public BeanDescriptor getConstraintsForClass(Class<?> cls)
Returns the validation constraints for the specified class

Parameters:
cls - Class for which constraints to return
Returns:
The validation bean descriptor

validate

public <T> ValidationException validate(T arg0,
                                        int event)
Validates a given instance

Specified by:
validate in interface Validator
Specified by:
validate in class AbstractValidator
Type Parameters:
T - The instance to validate
Parameters:
arg0 - The class, of type T to validate
event - The event id
Returns:
ValidationException if the validator produces one or more constraint violations.

validateProperty

public <T> ValidationException validateProperty(T arg0,
                                                String property,
                                                int event)
Validates a property of a given instance

Specified by:
validateProperty in interface Validator
Specified by:
validateProperty in class AbstractValidator
Type Parameters:
T - The instance to validate
Parameters:
arg0 - The property to validate
property - The property to validate
event - The event id
Returns:
ValidationException if the validator produces one or more constraint violations.

validateValue

public <T> ValidationException validateValue(Class<T> arg0,
                                             String arg1,
                                             Object arg2,
                                             int event)
Validates a value based upon the constraints applied to a given class attribute.

Specified by:
validateValue in interface Validator
Specified by:
validateValue in class AbstractValidator
Type Parameters:
T - The instance type to base validation upon
Parameters:
arg0 - The class of type T to validate
arg1 - The property to validate
arg2 - The property value to validate
event - The event id
Returns:
ValidationException if the validator produces one or more constraint violations.

validating

public <T> boolean validating(T arg0,
                              int event)
Returns whether validation is active for the given event.

Specified by:
validating in interface Validator
Overrides:
validating in class AbstractValidator
Type Parameters:
T -
Parameters:
arg0 - Type being validated
event - event type
Returns:
true if validation is active for the specified event


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