foundGroups = true;
} else if (ConstraintAnnotationAttributes.VALIDATION_APPLIES_TO.getAttributeName().equals(name)) {
buildValidationAppliesTo(method);
validationAppliesTo = method;
} else if (name.startsWith("valid")) {
throw new ConstraintDefinitionException("constraints parameters can't start with valid: " + name);
} else {
if (ConstraintAnnotationAttributes.MESSAGE.getAttributeName().equals(name)) {
foundMessage = true;
if (!TypeUtils.isAssignable(method.getReturnType(), ConstraintAnnotationAttributes.MESSAGE.getType())) {
throw new ConstraintDefinitionException("Return type for message() must be of type " + ConstraintAnnotationAttributes.MESSAGE.getType());
}
}
constraintValidation.getAttributes().put(name, method.invoke(constraintValidation.getAnnotation()));
}
} catch (final ConstraintDefinitionException cde) {
throw cde;
} catch (final Exception e) { // do nothing
log.log(Level.WARNING, String.format("Error processing annotation: %s ", constraintValidation.getAnnotation()), e);
}
}
}
if (!foundMessage) {
throw new ConstraintDefinitionException("Annotation " + annotationType.getName() + " has no message method");
}
if (!foundPayload) {
throw new ConstraintDefinitionException("Annotation " + annotationType.getName() + " has no payload method");
}
if (!foundGroups) {
throw new ConstraintDefinitionException("Annotation " + annotationType.getName() + " has no groups method");
}
if (validationAppliesTo != null && !ConstraintTarget.IMPLICIT.equals(validationAppliesTo.getDefaultValue())) {
throw new ConstraintDefinitionException("validationAppliesTo default value should be IMPLICIT");
}
// valid validationAppliesTo
final Constraint annotation = annotationType.getAnnotation(Constraint.class);
if (annotation == null) {
return;
}
final Pair validationTarget = computeValidationTarget(annotation.validatedBy());
for (final Annotation a : annotationType.getAnnotations()) {
final Class<? extends Annotation> aClass = a.annotationType();
if (aClass.getName().startsWith("java.lang.annotation.")) {
continue;
}
final Constraint inheritedConstraint = aClass.getAnnotation(Constraint.class);
if (inheritedConstraint != null && !aClass.getName().startsWith("javax.validation.constraints.")) {
final Pair validationTargetInherited = computeValidationTarget(inheritedConstraint.validatedBy());
if ((validationTarget.a > 0 && validationTargetInherited.b > 0 && validationTarget.b == 0)
|| (validationTarget.b > 0 && validationTargetInherited.a > 0 && validationTarget.a == 0)) {
throw new ConstraintDefinitionException("Parent and child constraint have different targets");
}
}
}
}