org.apache.bval.jsr303
Class ConstraintValidation<T extends Annotation>

java.lang.Object
  extended by org.apache.bval.jsr303.ConstraintValidation<T>
All Implemented Interfaces:
ConstraintDescriptor<T>, Validation

public class ConstraintValidation<T extends Annotation>
extends Object
implements Validation, ConstraintDescriptor<T>

Description: Adapter between Constraint (JSR303) and Validation (Core)
this instance is immutable!


Constructor Summary
ConstraintValidation(Class<? extends ConstraintValidator<T,?>>[] validatorClasses, ConstraintValidator<T,?> validator, T annotation, Class<?> owner, AccessStrategy access, boolean reportFromComposite)
          Create a new ConstraintValidation instance.
 
Method Summary
 void addComposed(ConstraintValidation<?> aConstraintValidation)
          Add a composing constraint.
 ConstraintDescriptor<T> asSerializableDescriptor()
          Return a Serializable ConstraintDescriptor capturing a snapshot of current state.
 AccessStrategy getAccess()
          Get the AccessStrategy used by this ConstraintValidation.
 T getAnnotation()
          
 Map<String,Object> getAttributes()
          
 Set<ConstraintDescriptor<?>> getComposingConstraints()
          
(package private)  Set<ConstraintValidation<?>> getComposingValidations()
          Get the composing ConstraintValidation objects.
 List<Class<? extends ConstraintValidator<T,?>>> getConstraintValidatorClasses()
          
 Set<Class<?>> getGroups()
          
 String getMessageTemplate()
          Get the message template used by this constraint.
 Class<?> getOwner()
          Get the owning class of this ConstraintValidation.
 Set<Class<? extends Payload>> getPayload()
          
 ConstraintValidator<T,?> getValidator()
          Get the ConstraintValidator invoked by this ConstraintValidation.
 void initialize()
          Initialize the validator (if not null) with the stored annotation.
protected  boolean isMemberOf(Class<?> reqGroup)
          Learn whether this ConstraintValidation belongs to the specified group.
 boolean isReportAsSingleViolation()
          
 void setAnnotation(T annotation)
          Override the Annotation set at construction.
(package private)  void setGroups(Set<Class<?>> groups)
          Set the applicable validation groups.
(package private)  void setPayload(Set<Class<? extends Payload>> payload)
          Set the payload.
 String toString()
          
 void validate(GroupValidationContext<?> context)
          Validate a GroupValidationContext.
<L extends ValidationListener>
void
validate(ValidationContext<L> context)
          Perform a single validation routine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConstraintValidation

public ConstraintValidation(Class<? extends ConstraintValidator<T,?>>[] validatorClasses,
                            ConstraintValidator<T,?> validator,
                            T annotation,
                            Class<?> owner,
                            AccessStrategy access,
                            boolean reportFromComposite)
Create a new ConstraintValidation instance.

Parameters:
validatorClasses -
validator - - the constraint validator
annotation - - the annotation of the constraint
owner - - the type where the annotated element is placed (class, interface, annotation type)
access - - how to access the value
reportFromComposite -
Method Detail

asSerializableDescriptor

public ConstraintDescriptor<T> asSerializableDescriptor()
Return a Serializable ConstraintDescriptor capturing a snapshot of current state.

Returns:
ConstraintDescriptor

setGroups

void setGroups(Set<Class<?>> groups)
Set the applicable validation groups.

Parameters:
groups -

setPayload

void setPayload(Set<Class<? extends Payload>> payload)
Set the payload.

Parameters:
payload -

isReportAsSingleViolation

public boolean isReportAsSingleViolation()

Specified by:
isReportAsSingleViolation in interface ConstraintDescriptor<T extends Annotation>

addComposed

public void addComposed(ConstraintValidation<?> aConstraintValidation)
Add a composing constraint.

Parameters:
aConstraintValidation - to add

validate

public <L extends ValidationListener> void validate(ValidationContext<L> context)
Perform a single validation routine. Validate the object or property according to the current ValidationContext.

Specified by:
validate in interface Validation
Parameters:
context - - to access the property, value, constraints

validate

public void validate(GroupValidationContext<?> context)
Validate a GroupValidationContext.

Parameters:
context - root

initialize

public void initialize()
Initialize the validator (if not null) with the stored annotation.


toString

public String toString()

Overrides:
toString in class Object

getMessageTemplate

public String getMessageTemplate()
Get the message template used by this constraint.

Returns:
String

getValidator

public ConstraintValidator<T,?> getValidator()
Get the ConstraintValidator invoked by this ConstraintValidation.

Returns:

isMemberOf

protected boolean isMemberOf(Class<?> reqGroup)
Learn whether this ConstraintValidation belongs to the specified group.

Parameters:
reqGroup -
Returns:
boolean

getOwner

public Class<?> getOwner()
Get the owning class of this ConstraintValidation.

Returns:
Class

getAnnotation

public T getAnnotation()

Specified by:
getAnnotation in interface ConstraintDescriptor<T extends Annotation>

getAccess

public AccessStrategy getAccess()
Get the AccessStrategy used by this ConstraintValidation.

Returns:
AccessStrategy

setAnnotation

public void setAnnotation(T annotation)
Override the Annotation set at construction.

Parameters:
annotation -

getAttributes

public Map<String,Object> getAttributes()

Specified by:
getAttributes in interface ConstraintDescriptor<T extends Annotation>

getComposingConstraints

public Set<ConstraintDescriptor<?>> getComposingConstraints()

Specified by:
getComposingConstraints in interface ConstraintDescriptor<T extends Annotation>

getComposingValidations

Set<ConstraintValidation<?>> getComposingValidations()
Get the composing ConstraintValidation objects. This is effectively an implementation-specific analogue to getComposingConstraints().

Returns:
Set of ConstraintValidation

getGroups

public Set<Class<?>> getGroups()

Specified by:
getGroups in interface ConstraintDescriptor<T extends Annotation>

getPayload

public Set<Class<? extends Payload>> getPayload()

Specified by:
getPayload in interface ConstraintDescriptor<T extends Annotation>

getConstraintValidatorClasses

public List<Class<? extends ConstraintValidator<T,?>>> getConstraintValidatorClasses()

Specified by:
getConstraintValidatorClasses in interface ConstraintDescriptor<T extends Annotation>


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