Top Description Inners Fields Constructors Methods
org.hibernate.validator.internal.metadata.core

public Class ConstraintHelper

extends Object
Class Inheritance
Static Imports
org.hibernate.validator.internal.metadata.core.BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_ASSERT_FALSE, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_ASSERT_TRUE, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_DECIMAL_MAX, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_DECIMAL_MIN, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_DIGITS, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_EMAIL, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_FUTURE, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_FUTURE_OR_PRESENT, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_MAX, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_MIN, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_NEGATIVE, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_NEGATIVE_OR_ZERO, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_NOT_BLANK, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_NOT_EMPTY, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_NOT_NULL, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_NULL, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_PAST, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_PAST_OR_PRESENT, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_PATTERN, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_POSITIVE, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_POSITIVE_OR_ZERO, .BuiltinConstraint.JAKARTA_VALIDATION_CONSTRAINTS_SIZE, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_BR_CNPJ, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_BR_CPF, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_BR_TITULO_ELEITORAL, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_CODE_POINT_LENGTH, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_CREDIT_CARD_NUMBER, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_CURRENCY, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_EAN, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_EMAIL, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_ISBN, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_LENGTH, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_LUHN_CHECK, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_MOD10_CHECK, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_MOD11_CHECK, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_MOD_CHECK, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_NORMALIZED, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_NOT_BLANK, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_NOT_EMPTY, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_PARAMETER_SCRIPT_ASSERT, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_PL_NIP, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_PL_PESEL, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_PL_REGON, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_RANGE, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_RU_INN, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_SCRIPT_ASSERT, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_TIME_DURATION_MAX, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_TIME_DURATION_MIN, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_UNIQUE_ELEMENTS, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_URL, .BuiltinConstraint.ORG_HIBERNATE_VALIDATOR_CONSTRAINTS_UUID, org.hibernate.validator.internal.util.logging.Messages.MESSAGES

Keeps track of builtin constraints and their validator implementations, as well as already resolved validator definitions.
Authors
Hardy Ferentschik, Alaa Nassef, Gunnar Morling, Guillaume Smet

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ConstraintHelper.ValidatorDescriptorMap

A type-safe wrapper around a concurrent map from constraint types to associated validator classes.

Field Summary

Modifier and TypeField and Description
private final Map<Class<? extends Annotation>, List<? extends ConstraintValidatorDescriptor<?>>>
private final ConcurrentMap<Class<? extends Annotation>, Boolean>
public static final String
private static final String
private Boolean
private static final String
private Boolean
private static final Log
public static final String
private final ConcurrentMap<Class<? extends Annotation>, Boolean>
public static final String
private static final List<String>
public static final String
private final ConstraintHelper.ValidatorDescriptorMap

Constructor Summary

AccessConstructor and Description
private
ConstraintHelper(Set<BuiltinConstraint> enabledBuiltinConstraints)

Method Summary

Modifier and TypeMethod and Description
private void
assertGroupsParameterExists(Class<? extends Annotation> annotationType)

private void
assertMessageParameterExists(Class<? extends Annotation> annotationType)

private void
private void
assertPayloadParameterExists(Class<? extends Annotation> annotationType)

private void
public void
public <
the type of the annotation
A extends Annotation
>
List<ConstraintValidatorDescriptor<A>>

Returns:

A list with matching validator descriptors.
findValidatorDescriptors
(Class<A>
The annotation of interest.
annotationType
,
ValidationTarget
The target, either annotated element or parameters.
validationTarget
)

Returns those validator descriptors for the given constraint annotation matching the given target.

public static ConstraintHelper
public static ConstraintHelper
forBuiltinConstraints(Set<String> enabledConstraints)

public <
the type of the annotation
A extends Annotation
>
List<ConstraintValidatorDescriptor<A>>

Returns:

The validator classes for the given type.
getAllValidatorDescriptors
(Class<A>
The constraint annotation type.
annotationType
)

Returns the constraint validator classes for the given constraint annotation type, as retrieved from

public static Set<String>
public <
the type of the annotation
A extends Annotation
>
List<Annotation>

Returns:

A list of constraint annotations, may be empty but never null.
getConstraintsFromMultiValueConstraint
(A
the multi-value constraint annotation from which to retrieve the contained constraints
multiValueConstraint
)

Returns the constraints which are part of the given multi-value constraint.

private <A extends Annotation> List<ConstraintValidatorDescriptor<A>>

Returns:

A list with the default validators as retrieved from Constraint#validatedBy() or the list of validators for built-in constraints.
getDefaultValidatorDescriptors
(Class<A>
The constraint annotation type.
annotationType
)

Returns the default validators for the given constraint type.

private boolean
isBuiltinConstraint(Class<? extends Annotation> annotationType)

private static boolean
public boolean

Returns:

true if the annotation fulfills the above conditions, false otherwise.
isConstraintAnnotation
(Class<? extends Annotation>
The annotation type to test.
annotationType
)

Checks whether the specified annotation is a valid constraint annotation.

public boolean
isConstraintComposition(Class<? extends Annotation> annotationType)

private boolean
public boolean
isJdkAnnotation(Class<? extends Annotation> annotation)

private boolean
public boolean

Returns:

true if the specified annotation is a multi value constraints, false otherwise.
isMultiValueConstraint
(Class<? extends Annotation>
the annotation type to check.
annotationType
)

Checks whether a given annotation is a multi value constraint or not.

private static <A extends Annotation> void
putBuiltinConstraint(Map<Class<? extends Annotation>, List<ConstraintValidatorDescriptor<?>>> validators, Class<A> constraintType)

private static <A extends Annotation> void
putBuiltinConstraint(Map<Class<? extends Annotation>, List<ConstraintValidatorDescriptor<?>>> validators, Class<A> constraintType, Class<? extends ConstraintValidator<A, ?>> validatorType)

private static <A extends Annotation> void
putBuiltinConstraints(Map<Class<? extends Annotation>, List<ConstraintValidatorDescriptor<?>>> validators, Class<A> constraintType, List<Class<? extends ConstraintValidator<A, ?>>> validatorTypes)

public <
the type of the annotation
A extends Annotation
>
void
putValidatorDescriptors(Class<A>
The constraint annotation type
annotationType
,
List<ConstraintValidatorDescriptor<A>>
The validator descriptors to register
validatorDescriptors
,
boolean
Whether already-registered validators should be kept or not
keepExistingClasses
)

Registers the given validator descriptors with the given constraint annotation type.

private static <T> T
run(PrivilegedAction<T> action)

Runs the given privileged action, using a privileged block if required.

private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

enabledBuiltinConstraintsback to summary
private final Map<Class<? extends Annotation>, List<? extends ConstraintValidatorDescriptor<?>>> enabledBuiltinConstraints
Annotations
@Immutable
externalConstraintsback to summary
private final ConcurrentMap<Class<? extends Annotation>, Boolean> externalConstraints
GROUPSback to summary
public static final String GROUPS
JAVA_MONEY_CLASS_NAMEback to summary
private static final String JAVA_MONEY_CLASS_NAME
javaMoneyInClasspathback to summary
private Boolean javaMoneyInClasspath
JODA_TIME_CLASS_NAMEback to summary
private static final String JODA_TIME_CLASS_NAME
jodaTimeInClassPathback to summary
private Boolean jodaTimeInClassPath
LOGback to summary
private static final Log LOG
MESSAGEback to summary
public static final String MESSAGE
multiValueConstraintsback to summary
private final ConcurrentMap<Class<? extends Annotation>, Boolean> multiValueConstraints
PAYLOADback to summary
public static final String PAYLOAD
SUPPORTED_VALID_METHODSback to summary
private static final List<String> SUPPORTED_VALID_METHODS
VALIDATION_APPLIES_TOback to summary
public static final String VALIDATION_APPLIES_TO
validatorDescriptorsback to summary
private final ConstraintHelper.ValidatorDescriptorMap validatorDescriptors

Constructor Detail

ConstraintHelperback to summary
private ConstraintHelper(Set<BuiltinConstraint> enabledBuiltinConstraints)
Annotations
@SuppressWarnings:deprecation

Method Detail

assertGroupsParameterExistsback to summary
private void assertGroupsParameterExists(Class<? extends Annotation> annotationType)
assertMessageParameterExistsback to summary
private void assertMessageParameterExists(Class<? extends Annotation> annotationType)
assertNoParameterStartsWithValidback to summary
private void assertNoParameterStartsWithValid(Class<? extends Annotation> annotationType)
assertPayloadParameterExistsback to summary
private void assertPayloadParameterExists(Class<? extends Annotation> annotationType)
assertValidationAppliesToParameterSetUpCorrectlyback to summary
private void assertValidationAppliesToParameterSetUpCorrectly(Class<? extends Annotation> annotationType)
clearback to summary
public void clear()
findValidatorDescriptorsback to summary
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.

Parameters
<A>
the type of the annotation
annotationType:Class<A>

The annotation of interest.

validationTarget:ValidationTarget

The target, either annotated element or parameters.

Returns:List<ConstraintValidatorDescriptor<A>>

A list with matching validator descriptors.

forAllBuiltinConstraintsback to summary
public static ConstraintHelper forAllBuiltinConstraints()
forBuiltinConstraintsback to summary
public static ConstraintHelper forBuiltinConstraints(Set<String> enabledConstraints)
getAllValidatorDescriptorsback to summary
public <A extends Annotation> List<ConstraintValidatorDescriptor<A>> getAllValidatorDescriptors(Class<A> annotationType)

Returns the constraint validator classes for the given constraint annotation type, as retrieved from

The result is cached internally.
Parameters
<A>
the type of the annotation
annotationType:Class<A>

The constraint annotation type.

Returns:List<ConstraintValidatorDescriptor<A>>

The validator classes for the given type.

getBuiltinConstraintsback to summary
public static Set<String> getBuiltinConstraints()
getConstraintsFromMultiValueConstraintback to summary
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.

Parameters
<A>
the type of the annotation
multiValueConstraint:A

the multi-value constraint annotation from which to retrieve the contained constraints

Returns:List<Annotation>

A list of constraint annotations, may be empty but never null.

getDefaultValidatorDescriptorsback to summary
private <A extends Annotation> List<ConstraintValidatorDescriptor<A>> getDefaultValidatorDescriptors(Class<A> annotationType)

Returns the default validators for the given constraint type.

Parameters
annotationType:Class<A>

The constraint annotation type.

Returns:List<ConstraintValidatorDescriptor<A>>

A list with the default validators as retrieved from Constraint#validatedBy() or the list of validators for built-in constraints.

Annotations
@SuppressWarnings:unchecked
isBuiltinConstraintback to summary
private boolean isBuiltinConstraint(Class<? extends Annotation> annotationType)
isClassPresentback to summary
private static boolean isClassPresent(String className)
isConstraintAnnotationback to summary
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:Class<? extends Annotation>

The annotation type to test.

Returns:boolean

true if the annotation fulfills the above conditions, false otherwise.

isConstraintCompositionback to summary
public boolean isConstraintComposition(Class<? extends Annotation> annotationType)
isJavaMoneyInClasspathback to summary
private boolean isJavaMoneyInClasspath()
isJdkAnnotationback to summary
public boolean isJdkAnnotation(Class<? extends Annotation> annotation)
isJodaTimeInClasspathback to summary
private boolean isJodaTimeInClasspath()
isMultiValueConstraintback to summary
public boolean isMultiValueConstraint(Class<? extends Annotation> annotationType)

Checks whether a given annotation is a multi value constraint or not.

Parameters
annotationType:Class<? extends Annotation>

the annotation type to check.

Returns:boolean

true if the specified annotation is a multi value constraints, false otherwise.

putBuiltinConstraintback to summary
private static <A extends Annotation> void putBuiltinConstraint(Map<Class<? extends Annotation>, List<ConstraintValidatorDescriptor<?>>> validators, Class<A> constraintType)
putBuiltinConstraintback to summary
private static <A extends Annotation> void putBuiltinConstraint(Map<Class<? extends Annotation>, List<ConstraintValidatorDescriptor<?>>> validators, Class<A> constraintType, Class<? extends ConstraintValidator<A, ?>> validatorType)
putBuiltinConstraintsback to summary
private static <A extends Annotation> void putBuiltinConstraints(Map<Class<? extends Annotation>, List<ConstraintValidatorDescriptor<?>>> validators, Class<A> constraintType, List<Class<? extends ConstraintValidator<A, ?>>> validatorTypes)
putValidatorDescriptorsback to summary
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.

Parameters
<A>
the type of the annotation
annotationType:Class<A>

The constraint annotation type

validatorDescriptors:List<ConstraintValidatorDescriptor<A>>

The validator descriptors to register

keepExistingClasses:boolean

Whether already-registered validators should be kept or not

runback to summary
private static <T> T run(PrivilegedAction<T> action)

Runs the given privileged action, using a privileged block if required.

Note

This must never be changed into a publicly available method to avoid execution of arbitrary privileged actions within HV's protection domain.

Annotations
@IgnoreForbiddenApisErrors
reason:SecurityManager is deprecated in JDK17
supportsValidationTargetback to summary
private boolean supportsValidationTarget(ConstraintValidatorDescriptor<?> validatorDescriptor, ValidationTarget target)
org.hibernate.validator.internal.metadata.core back to summary

private Class ConstraintHelper.ValidatorDescriptorMap

extends Object
Class Inheritance
  • java.lang.Object
  • org.hibernate.validator.internal.metadata.core.ConstraintHelper.ValidatorDescriptorMap
Annotations
@SuppressWarnings:unchecked

A type-safe wrapper around a concurrent map from constraint types to associated validator classes. The casts are safe as data is added trough the typed API only.
Author
Gunnar Morling

Field Summary

Modifier and TypeField and Description
private final ConcurrentMap<Class<? extends Annotation>, List<? extends ConstraintValidatorDescriptor<?>>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private <A extends Annotation> List<ConstraintValidatorDescriptor<A>>
computeIfAbsent(Class<A> annotationType, Function<? super Class<A>, List<ConstraintValidatorDescriptor<A>>> mappingFunction)

private <A extends Annotation> void
put(Class<A> annotationType, List<ConstraintValidatorDescriptor<A>> validatorDescriptors)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

constraintValidatorDescriptorsback to summary
private final ConcurrentMap<Class<? extends Annotation>, List<? extends ConstraintValidatorDescriptor<?>>> constraintValidatorDescriptors

Constructor Detail

ValidatorDescriptorMapback to summary
private ValidatorDescriptorMap()

Method Detail

computeIfAbsentback to summary
private <A extends Annotation> List<ConstraintValidatorDescriptor<A>> computeIfAbsent(Class<A> annotationType, Function<? super Class<A>, List<ConstraintValidatorDescriptor<A>>> mappingFunction)
putback to summary
private <A extends Annotation> void put(Class<A> annotationType, List<ConstraintValidatorDescriptor<A>> validatorDescriptors)