@SuppressWarnings({ RAWTYPES, UNCHECKED }) private void addConstraints(final Builder builder, final Method method) { final Annotation[] annotations = method.getAnnotations(); boolean collectionConstraintAdded = false; for (final Annotation annotation : annotations) { final javax.validation.Constraint annotationAnnotation = annotation.annotationType().getAnnotation( javax.validation.Constraint.class); if (annotationAnnotation != null) { if (annotation.annotationType() != Size.class) { final GenericPropertyConstraint propertyConstraint = new GenericPropertyConstraint(annotation, method.getReturnType()); builder.add(propertyConstraint); } else { checkCollection(builder, method, (Size) annotation); collectionConstraintAdded = true; } } } if (!collectionConstraintAdded) { checkCollection(builder, method, null); } }
private void checkCollection(final PropertyMetaData.Builder builder, final Method method, final Size size) { final Class<?> type = builder.getType().getType(); if (Collection.class.isAssignableFrom(type)) { final PropertyElementType elementTypeAnnotation = method.getAnnotation(PropertyElementType.class); final Class<?> elementType = calcElementType(elementTypeAnnotation); final List<? extends PropertyConstraint<?>> elementConstraints = calcElementConstraints(method); Integer min = null; Integer max = null; if (size != null) { min = size.min(); max = size.max(); } final PropertyConstraint<?> propertyConstraint = new ListValueConstraint(elementType, min, max, elementConstraints); builder.add(propertyConstraint); } }
@SuppressWarnings({ RAWTYPES, UNCHECKED }) private static void addValueRange(final Builder builder, final Method method) { final PropertyValueRange<?> valueRange = calculateValueRange(method); if (valueRange != null) { builder.with(valueRange); final PropertyRangeConstraint<?> constraint = new PropertyRangeConstraint(valueRange); builder.add(constraint); } }