Class ConstraintHelper
- java.lang.Object
-
- org.hibernate.validator.internal.metadata.core.ConstraintHelper
-
public class ConstraintHelper extends Object
Keeps track of builtin constraints and their validator implementations, as well as already resolved validator definitions.- Author:
- Hardy Ferentschik, Alaa Nassef, Gunnar Morling, Guillaume Smet
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()<A extends Annotation>
List<ConstraintValidatorDescriptor<A>>findValidatorDescriptors(Class<A> annotationType, ValidationTarget validationTarget)Returns those validator descriptors for the given constraint annotation matching the given target.static ConstraintHelperforAllBuiltinConstraints()static ConstraintHelperforBuiltinConstraints(Set<String> enabledConstraints)<A extends Annotation>
List<ConstraintValidatorDescriptor<A>>getAllValidatorDescriptors(Class<A> annotationType)Returns the constraint validator classes for the given constraint annotation type, as retrieved fromConstraint.validatedBy(), internally registered validators for built-in constraints XML configuration and programmatically registered validators (seeConstraintMapping.constraintDefinition(Class)). The result is cached internally.static Set<String>getBuiltinConstraints()<A extends Annotation>
List<Annotation>getConstraintsFromMultiValueConstraint(A multiValueConstraint)Returns the constraints which are part of the given multi-value constraint.booleanisConstraintAnnotation(Class<? extends Annotation> annotationType)Checks whether the specified annotation is a valid constraint annotation.booleanisConstraintComposition(Class<? extends Annotation> annotationType)booleanisJdkAnnotation(Class<? extends Annotation> annotation)booleanisMultiValueConstraint(Class<? extends Annotation> annotationType)Checks whether a given annotation is a multi value constraint or not.<A extends Annotation>
voidputValidatorDescriptors(Class<A> annotationType, List<ConstraintValidatorDescriptor<A>> validatorDescriptors, boolean keepExistingClasses)Registers the given validator descriptors with the given constraint annotation type.
-
-
-
Field Detail
-
GROUPS
public static final String GROUPS
- See Also:
- Constant Field Values
-
PAYLOAD
public static final String PAYLOAD
- See Also:
- Constant Field Values
-
MESSAGE
public static final String MESSAGE
- See Also:
- Constant Field Values
-
VALIDATION_APPLIES_TO
public static final String VALIDATION_APPLIES_TO
- See Also:
- Constant Field Values
-
-
Method Detail
-
forAllBuiltinConstraints
public static ConstraintHelper forAllBuiltinConstraints()
-
forBuiltinConstraints
public static ConstraintHelper forBuiltinConstraints(Set<String> enabledConstraints)
-
getAllValidatorDescriptors
public <A extends Annotation> List<ConstraintValidatorDescriptor<A>> getAllValidatorDescriptors(Class<A> annotationType)
Returns the constraint validator classes for the given constraint annotation type, as retrieved fromConstraint.validatedBy(),- internally registered validators for built-in constraints
- XML configuration and
- programmatically registered validators (see
ConstraintMapping.constraintDefinition(Class)).
- Type Parameters:
A- the type of the annotation- Parameters:
annotationType- The constraint annotation type.- Returns:
- The validator classes for the given type.
-
findValidatorDescriptors
public <A extends Annotation> List<ConstraintValidatorDescriptor<A>> findValidatorDescriptors(Class<A> annotationType, ValidationTarget validationTarget)
Returns those validator descriptors for the given constraint annotation matching the given target.- Type Parameters:
A- the type of the annotation- Parameters:
annotationType- The annotation of interest.validationTarget- The target, either annotated element or parameters.- Returns:
- A list with matching validator descriptors.
-
putValidatorDescriptors
public <A extends Annotation> void putValidatorDescriptors(Class<A> annotationType, List<ConstraintValidatorDescriptor<A>> validatorDescriptors, boolean keepExistingClasses)
Registers the given validator descriptors with the given constraint annotation type.- Type Parameters:
A- the type of the annotation- Parameters:
annotationType- The constraint annotation typevalidatorDescriptors- The validator descriptors to registerkeepExistingClasses- Whether already-registered validators should be kept or not
-
isMultiValueConstraint
public boolean isMultiValueConstraint(Class<? extends Annotation> annotationType)
Checks whether a given annotation is a multi value constraint or not.- Parameters:
annotationType- the annotation type to check.- Returns:
trueif the specified annotation is a multi value constraints,falseotherwise.
-
getConstraintsFromMultiValueConstraint
public <A extends Annotation> List<Annotation> getConstraintsFromMultiValueConstraint(A multiValueConstraint)
Returns the constraints which are part of the given multi-value constraint.Invoke
isMultiValueConstraint(Class)prior to calling this method to check whether a given constraint actually is a multi-value constraint.- Type Parameters:
A- the type of the annotation- Parameters:
multiValueConstraint- the multi-value constraint annotation from which to retrieve the contained constraints- Returns:
- A list of constraint annotations, may be empty but never
null.
-
isConstraintAnnotation
public boolean isConstraintAnnotation(Class<? extends Annotation> annotationType)
Checks whether the specified annotation is a valid constraint annotation. A constraint annotation has to fulfill the following conditions:- Must be annotated with
Constraint - Define a message parameter
- Define a group parameter
- Define a payload parameter
- Parameters:
annotationType- The annotation type to test.- Returns:
trueif the annotation fulfills the above conditions,falseotherwise.
- Must be annotated with
-
isConstraintComposition
public boolean isConstraintComposition(Class<? extends Annotation> annotationType)
-
isJdkAnnotation
public boolean isJdkAnnotation(Class<? extends Annotation> annotation)
-
clear
public void clear()
-
-