Java Code Examples for javax.validation.Validator#unwrap()

The following examples show how to use javax.validation.Validator#unwrap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodValidationInterceptor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public static Object invokeWithinValidation(MethodInvocation invocation, Validator validator, Class<?>[] groups)
		throws Throwable {

	org.hibernate.validator.method.MethodValidator methodValidator =
			validator.unwrap(org.hibernate.validator.method.MethodValidator.class);
	Set<org.hibernate.validator.method.MethodConstraintViolation<Object>> result =
			methodValidator.validateAllParameters(
					invocation.getThis(), invocation.getMethod(), invocation.getArguments(), groups);
	if (!result.isEmpty()) {
		throw new org.hibernate.validator.method.MethodConstraintViolationException(result);
	}
	Object returnValue = invocation.proceed();
	result = methodValidator.validateReturnValue(
			invocation.getThis(), invocation.getMethod(), returnValue, groups);
	if (!result.isEmpty()) {
		throw new org.hibernate.validator.method.MethodConstraintViolationException(result);
	}
	return returnValue;
}
 
Example 2
Source File: MethodValidationPostProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Set the JSR-303 Validator to delegate to for validating methods.
 * <p>Default is the default ValidatorFactory's default Validator.
 */
public void setValidator(Validator validator) {
	// Unwrap to the native Validator with forExecutables support
	if (validator instanceof LocalValidatorFactoryBean) {
		this.validator = ((LocalValidatorFactoryBean) validator).getValidator();
	}
	else if (validator instanceof SpringValidatorAdapter) {
		this.validator = validator.unwrap(Validator.class);
	}
	else {
		this.validator = validator;
	}
}
 
Example 3
Source File: MethodValidationPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the JSR-303 Validator to delegate to for validating methods.
 * <p>Default is the default ValidatorFactory's default Validator.
 */
public void setValidator(Validator validator) {
	// Unwrap to the native Validator with forExecutables support
	if (validator instanceof LocalValidatorFactoryBean) {
		this.validator = ((LocalValidatorFactoryBean) validator).getValidator();
	}
	else if (validator instanceof SpringValidatorAdapter) {
		this.validator = validator.unwrap(Validator.class);
	}
	else {
		this.validator = validator;
	}
}
 
Example 4
Source File: MethodValidationInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static Object invokeWithinValidation(MethodInvocation invocation, Validator validator, Class<?>[] groups)
		throws Throwable {

	org.hibernate.validator.method.MethodValidator methodValidator =
			validator.unwrap(org.hibernate.validator.method.MethodValidator.class);
	Set<org.hibernate.validator.method.MethodConstraintViolation<Object>> result =
			methodValidator.validateAllParameters(
					invocation.getThis(), invocation.getMethod(), invocation.getArguments(), groups);
	if (!result.isEmpty()) {
		throw new org.hibernate.validator.method.MethodConstraintViolationException(result);
	}
	Object returnValue = invocation.proceed();
	result = methodValidator.validateReturnValue(
			invocation.getThis(), invocation.getMethod(), returnValue, groups);
	if (!result.isEmpty()) {
		throw new org.hibernate.validator.method.MethodConstraintViolationException(result);
	}
	return returnValue;
}
 
Example 5
Source File: MethodValidationPostProcessor.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Set the JSR-303 Validator to delegate to for validating methods.
 * <p>Default is the default ValidatorFactory's default Validator.
 */
public void setValidator(Validator validator) {
	// Unwrap to the native Validator with forExecutables support
	if (validator instanceof LocalValidatorFactoryBean) {
		this.validator = ((LocalValidatorFactoryBean) validator).getValidator();
	}
	else if (validator instanceof SpringValidatorAdapter) {
		this.validator = validator.unwrap(Validator.class);
	}
	else {
		this.validator = validator;
	}
}