1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  package org.springmodules.validation.bean.rule;
18  
19  import org.springmodules.validation.util.condition.Condition;
20  
21  /**
22   * Represents a validation rule. A validation rule binds an error to a condition.
23   *
24   * @author Uri Boness
25   */
26  public interface ValidationRule {
27  
28      /**
29       * Checks whether this validation is applicable on the given object. This can be used
30       * to define applicability rules base on runtime factors.
31       *
32       * @param obj The object to be validated
33       * @return True if this validation rule is applicable on the given obj, false otherwise.
34       */
35      boolean isApplicable(Object obj);
36  
37      /**
38       * Returns the condition of this validation rule.
39       *
40       * @return The condition of this validation rule.
41       */
42      Condition getCondition();
43  
44      /**
45       * Return the error code of this validation rule. This method cannot return <code>null</code>.
46       *
47       * @return The error code of this validation rule.
48       */
49      String getErrorCode();
50  
51      /**
52       * Returns the arguments that apply to the error code of this validation rule. This
53       * method should never return null. If there are no arguments, this method must return
54       * an empty array. This method accepts the validated object, this enables runtime generation
55       * of arguments based on that object.
56       *
57       * @param obj The validated object.
58       * @return The arguments that apply to the error code of this validation rule.
59       */
60      Object[] getErrorArguments(Object obj);
61  
62      /**
63       * Returns the default error message that can be used in case no error message is bound
64       * to the error code of the rule. This method can return <code>null</code> to indicate that
65       * no default message exists.
66       *
67       * @return The default error message of this validation rule.
68       */
69      String getDefaultErrorMessage();
70  
71  }