String beanName = StringUtils.uncapitalize(clazz.getSimpleName());
//
ValidatedBean validatedBean = new ValidatedBean(beanName, beanType);
//
Validator validator = validatorFactory.getValidator();
MessageInterpolator messageInterpolator = validatorFactory.getMessageInterpolator();
//
BeanDescriptor beanDescriptor = validator.getConstraintsForClass(beanType);
Set<PropertyDescriptor> propertyDescriptors = beanDescriptor.getConstrainedProperties();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
String propertyName = propertyDescriptor.getPropertyName();
ValidatedProperty validatedProperty = new ValidatedProperty(propertyName);
//
Set<ConstraintDescriptor<?>> constraintDesctipors = propertyDescriptor.getConstraintDescriptors();
for (final ConstraintDescriptor<?> constraintDescriptor : constraintDesctipors) {
// groups checks
if (isOutOfGroup(constraintDescriptor, groups)) {
continue;
}
//
String constraintName = getConstraintName(constraintDescriptor);
List<String> constraintParams = getConstraintParams(constraintDescriptor);
ValidatedConstraint validatedConstraint = new ValidatedConstraint(constraintName, constraintParams);
//
String messageTemplate = (String) constraintDescriptor.getAttributes().get("message");
MessageInterpolator.Context context = new MessageInterpolatorContext(constraintDescriptor);
String message = messageInterpolator.interpolate(messageTemplate, context);
//
validatedConstraint.setMessage(message);
//
validatedProperty.addValidatedConstraint(validatedConstraint);
}