if (defaultGroups != null && defaultGroups.size() > 1) {
int numViolations = result.violationsSize();
// Validate the bean for each group in the sequence
final Group currentGroup = context.getCurrentGroup();
for (final Group each : defaultGroups) {
context.setCurrentGroup(each);
// ValidationHelper.validateBean(context);, doesn't match anymore because of @ConvertGroup
validateBean(context);
// Spec 3.4.3 - Stop validation if errors already found
if (result.violationsSize() > numViolations) {
break;
}
}
context.setCurrentGroup(currentGroup);
} else {
// For each class in the hierarchy of classes of rootBean,
// validate the constraints defined in that class according
// to the GroupSequence defined in the same class
// Obtain the full class hierarchy
final List<Class<?>> classHierarchy = new ArrayList<Class<?>>();
ClassHelper.fillFullClassHierarchyAsList(classHierarchy, context.getMetaBean().getBeanClass());
final Class<?> initialOwner = context.getCurrentOwner();
// For each owner in the hierarchy
for (final Class<?> owner : classHierarchy) {
context.setCurrentOwner(owner);
int numViolations = result.violationsSize();
// Obtain the group sequence of the owner, and use it for
// the constraints that belong to it
final List<Group> ownerDefaultGroups = context.getMetaBean().getFeature("{GroupSequence:" + owner.getCanonicalName() + "}");
for (Group each : ownerDefaultGroups) {
context.setCurrentGroup(each);
validateBean(context);
// Spec 3.4.3 - Stop validation if errors already found
if (result.violationsSize() > numViolations) {
break;
}
}
}
context.setCurrentOwner(initialOwner);
context.setCurrentGroup(Group.DEFAULT);
}
}
// if not the default group, proceed as normal
else {
validateBean(context);
}
// ### Then, the cascaded beans (@Valid)
for (final MetaProperty prop : context.getMetaBean().getProperties()) {
final Group group = context.getCurrentGroup();
final Group mappedGroup;
final Object feature = prop.getFeature(JsrFeatures.Property.PropertyDescriptor);
if (feature != null) {
mappedGroup = PropertyDescriptorImpl.class.cast(feature).mapGroup(group);
} else {
mappedGroup = group;
}
if (group != mappedGroup) {
final Groups propertyGroup = groupsComputer.computeGroups(new Class<?>[]{ mappedGroup.getGroup() });
validateCascadedBean(context, prop, propertyGroup);
} else {
validateCascadedBean(context, prop, null);
}