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;
}
Aggregations