View Javadoc

1   /*
2    * Copyright 2004-2009 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }