All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorDescriptor Maven / Gradle / Ivy

Go to download

JSR 380's RI, Hibernate Validator version ${hibernate-validator.version} and its dependencies repackaged as OSGi bundle

There is a newer version: 5.1.0
Show newest version
/*
 * 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 );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy