* @param errors The {@link Errors} instance where all global validation errors will be registered.
*/
protected void applyGlobalValidationRules(BeanValidationConfiguration configuration, Object obj, Errors errors) {
ValidationRule[] globalRules = configuration.getGlobalRules();
for (int i = 0; i < globalRules.length; i++) {
ValidationRule rule = globalRules[i];
if (rule.isApplicable(obj) && !rule.getCondition().check(obj)) {
String errorCode = errorCodeConverter.convertGlobalErrorCode(rule.getErrorCode(), obj.getClass());
// if there is a nested path in errors, the global errors should be registered as field errors
// for the nested path. Otherwise, they should be registered as global errors. Starting from Spring 2.0-rc2
// this is actually not required - it's just enough to call rejectValue() with null as the field name,
// but we keep this implementation for now to support earlier versions.
if (StringUtils.hasLength(errors.getNestedPath())) {
String nestedPath = errors.getNestedPath();
String propertyName = nestedPath.substring(0, nestedPath.length() - 1);
errors.popNestedPath();
errors.rejectValue(propertyName, errorCode, rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
errors.pushNestedPath(propertyName);
} else {
errors.reject(errorCode, rule.getErrorArguments(obj), rule.getDefaultErrorMessage());
}
}
}
}