Validator springValidator = (Validator) validator;
if (logger.isDebugEnabled()) {
logger.debug("Invoking Spring Validator '" + ClassUtils.getShortName(validator.getClass()) + "'");
}
if (springValidator.supports(model.getClass())) {
MessageContextErrors errors = new MessageContextErrors(requestContext.getMessageContext(), modelName,
model, expressionParser, messageCodesResolver, mappingResults);
if (this.validationHints != null) {
if (springValidator instanceof SmartValidator) {
((SmartValidator) springValidator).validate(model, errors, this.validationHints);
}
else {
logger.warn("Validation hints provided but validator not an instance of SmartValidator: ["
+ springValidator.getClass().getName() + "]");
}
}
else {
springValidator.validate(model, errors);
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Spring Validator '" + ClassUtils.getShortName(validator.getClass())
+ "' doesn't support model class " + model.getClass());
}
}
return true;
}
// preferred
Method validateMethod = findValidationMethod(model, validator, "validate", ValidationContext.class);
if (validateMethod != null) {
if (logger.isDebugEnabled()) {
logger.debug("Invoking default validator method '" + ClassUtils.getShortName(validator.getClass())
+ ".validate(" + ClassUtils.getShortName(model.getClass()) + ", ValidationContext)'");
}
ReflectionUtils.invokeMethod(validateMethod, validator, new Object[] { model,
new DefaultValidationContext(requestContext, eventId, mappingResults) });
return true;
}
// mvc 2 compatibility only
validateMethod = findValidationMethod(model, validator, "validate", Errors.class);
if (validateMethod != null) {
if (logger.isDebugEnabled()) {
logger.debug("Invoking default validator method '" + ClassUtils.getShortName(validator.getClass())
+ ".validate(" + ClassUtils.getShortName(model.getClass()) + ", Errors)'");
}
MessageContextErrors errors = new MessageContextErrors(requestContext.getMessageContext(), modelName,
model, expressionParser, messageCodesResolver, mappingResults);
ReflectionUtils.invokeMethod(validateMethod, validator, new Object[] { model, errors });
return true;
}
return false;