org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorDescriptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bean-validator Show documentation
Show all versions of bean-validator Show documentation
JSR 380's RI, Hibernate Validator version ${hibernate-validator.version} and its dependencies repackaged as OSGi bundle
/*
* Hibernate Validator, declare and validate application constraints
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or .
*/
package org.hibernate.validator.internal.engine.constraintvalidation;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.EnumSet;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorFactory;
import javax.validation.constraintvalidation.ValidationTarget;
import org.hibernate.validator.cfg.context.ConstraintDefinitionContext.ValidationCallable;
/**
* Represents a specific validator (either based on an implementation of {@link ConstraintValidator} or given as a
* Lambda expression/method reference.
*
* @author Gunnar Morling
*/
public interface ConstraintValidatorDescriptor {
/**
* The implementation type of the represented validator.
*/
Class> getValidatorClass();
/**
* The targets supported for validation by the represented validator.
*/
EnumSet getValidationTargets();
/**
* The data type validated by the represented validator (not the constraint annotation type).
*/
Type getValidatedType();
/**
* Creates a new instance of the represented implementation type.
*/
ConstraintValidator newInstance(ConstraintValidatorFactory constraintValidatorFactory);
static ConstraintValidatorDescriptor forClass(Class> validatorClass,
Class constraintAnnotationType) {
return ClassBasedValidatorDescriptor.of( validatorClass, constraintAnnotationType );
}
static ConstraintValidatorDescriptor forLambda(Class annotationType, Type validatedType, ValidationCallable lambda) {
return new LambdaBasedValidatorDescriptor<>( validatedType, lambda );
}
}