11/*
2- * Copyright 2002-2007 the original author or authors.
2+ * Copyright 2002-2011 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2020import org .apache .commons .logging .LogFactory ;
2121
2222import org .springframework .util .Assert ;
23+ import org .springframework .util .ObjectUtils ;
2324import org .springframework .util .StringUtils ;
2425
2526/**
@@ -46,11 +47,26 @@ public abstract class ValidationUtils {
4647 * @param validator the <code>Validator</code> to be invoked (must not be <code>null</code>)
4748 * @param obj the object to bind the parameters to
4849 * @param errors the {@link Errors} instance that should store the errors (must not be <code>null</code>)
49- * @throws IllegalArgumentException if either of the <code>Validator</code> or <code>Errors</code> arguments is <code>null</code>;
50- * or if the supplied <code>Validator</code> does not {@link Validator#supports(Class) support}
50+ * @throws IllegalArgumentException if either of the <code>Validator</code> or <code>Errors</code> arguments is
51+ * <code>null</code>, or if the supplied <code>Validator</code> does not {@link Validator#supports(Class) support}
5152 * the validation of the supplied object's type
5253 */
5354 public static void invokeValidator (Validator validator , Object obj , Errors errors ) {
55+ invokeValidator (validator , obj , errors , (Class []) null );
56+ }
57+
58+ /**
59+ * Invoke the given {@link Validator}/{@link SmartValidator} for the supplied object and
60+ * {@link Errors} instance.
61+ * @param validator the <code>Validator</code> to be invoked (must not be <code>null</code>)
62+ * @param obj the object to bind the parameters to
63+ * @param errors the {@link Errors} instance that should store the errors (must not be <code>null</code>)
64+ * @param validationHints one or more hint objects to be passed to the validation engine
65+ * @throws IllegalArgumentException if either of the <code>Validator</code> or <code>Errors</code> arguments is
66+ * <code>null</code>, or if the supplied <code>Validator</code> does not {@link Validator#supports(Class) support}
67+ * the validation of the supplied object's type
68+ */
69+ public static void invokeValidator (Validator validator , Object obj , Errors errors , Object ... validationHints ) {
5470 Assert .notNull (validator , "Validator must not be null" );
5571 Assert .notNull (errors , "Errors object must not be null" );
5672 if (logger .isDebugEnabled ()) {
@@ -60,7 +76,12 @@ public static void invokeValidator(Validator validator, Object obj, Errors error
6076 throw new IllegalArgumentException (
6177 "Validator [" + validator .getClass () + "] does not support [" + obj .getClass () + "]" );
6278 }
63- validator .validate (obj , errors );
79+ if (!ObjectUtils .isEmpty (validationHints ) && validator instanceof SmartValidator ) {
80+ ((SmartValidator ) validator ).validate (obj , errors , validationHints );
81+ }
82+ else {
83+ validator .validate (obj , errors );
84+ }
6485 if (logger .isDebugEnabled ()) {
6586 if (errors .hasErrors ()) {
6687 logger .debug ("Validator found " + errors .getErrorCount () + " errors" );
0 commit comments