Search in sources :

Example 1 with ConstructorDescriptor

use of javax.validation.metadata.ConstructorDescriptor in project tomee by apache.

the class BValInterceptor method construct.

@SuppressWarnings({ "unchecked", "rawtypes" })
// TODO: see previous one
@AroundConstruct
public Object construct(final InvocationContext context) throws Exception {
    final Constructor ctor = context.getConstructor();
    if (!isConstructorValidated(ctor)) {
        return context.proceed();
    }
    final Class clazz = ctor.getDeclaringClass();
    final ClassValidationData validationData = new ClassValidationData(clazz);
    if (validationData.getJwtConstraints().size() > 0) {
        // anywhere on the class
        return context.proceed();
    }
    final ConstructorDescriptor constraints = validator.getConstraintsForClass(clazz).getConstraintsForConstructor(ctor.getParameterTypes());
    if (!DescriptorManager.isConstrained(constraints)) {
        return context.proceed();
    }
    initExecutableValidator();
    if (constraints.hasConstrainedParameters()) {
        final Set<ConstraintViolation<?>> violations = executableValidator.validateConstructorParameters(ctor, context.getParameters());
        if (!violations.isEmpty()) {
            throw new ConstraintViolationException(violations);
        }
    }
    final Object result = context.proceed();
    if (constraints.hasConstrainedReturnValue()) {
        final Set<ConstraintViolation<?>> violations = executableValidator.validateConstructorReturnValue(ctor, context.getTarget());
        if (!violations.isEmpty()) {
            throw new ConstraintViolationException(violations);
        }
    }
    return result;
}
Also used : Constructor(java.lang.reflect.Constructor) ConstraintViolation(javax.validation.ConstraintViolation) ConstructorDescriptor(javax.validation.metadata.ConstructorDescriptor) ConstraintViolationException(javax.validation.ConstraintViolationException) AroundConstruct(javax.interceptor.AroundConstruct)

Aggregations

Constructor (java.lang.reflect.Constructor)1 AroundConstruct (javax.interceptor.AroundConstruct)1 ConstraintViolation (javax.validation.ConstraintViolation)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 ConstructorDescriptor (javax.validation.metadata.ConstructorDescriptor)1