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.conf;
18  
19  import org.springframework.util.ObjectUtils;
20  import org.springmodules.validation.util.condition.Condition;
21  import org.springmodules.validation.util.condition.common.AlwaysTrueCondition;
22  
23  /**
24   * Represents a cascade validation definition. Holds the name
25   * of the property to which the validation will be cascaded and
26   * the applicability condition to determine whether the cascading
27   * should be applied.
28   *
29   * @author Uri Boness
30   */
31  public class CascadeValidation {
32  
33      private String propertyName;
34  
35      private Condition applicabilityCondition;
36  
37      /**
38       * Constructs a new CascadeValidation with a given property name. This cascading always applies.
39       *
40       * @param propertyName The name of the property to which the validation will be cascaded.
41       */
42      public CascadeValidation(String propertyName) {
43          this(propertyName, new AlwaysTrueCondition());
44      }
45  
46      /**
47       * Constructs a new CascadeValidation with a given property name and applicability condition.
48       *
49       * @param propertyName The name of the property to which the validation will be cascaded.
50       * @param applicabilityCondition The condition to determine whether the cascading will be applied.
51       */
52      public CascadeValidation(String propertyName, Condition applicabilityCondition) {
53          this.propertyName = propertyName;
54          this.applicabilityCondition = applicabilityCondition;
55      }
56  
57      /**
58       * Returns the name of the property to which the validation will be cascaded.
59       *
60       * @return The name of the property to which the validation will be cascaded.
61       */
62      public String getPropertyName() {
63          return propertyName;
64      }
65  
66      /**
67       * Returns the condition that determines whether the cascading should be applied.
68       *
69       * @return The condition that determines whether the cascading should be applied.
70       */
71      public Condition getApplicabilityCondition() {
72          return applicabilityCondition;
73      }
74  
75      /**
76       * Sets the condition that determines whether the cascading should be applied.
77       *
78       * @param applicabilityCondition The condition that determines whether the cascading should be applied.
79       */
80      public void setApplicabilityCondition(Condition applicabilityCondition) {
81          this.applicabilityCondition = applicabilityCondition;
82      }
83  
84  
85      public boolean equals(Object object) {
86          if (this == object) {
87              return true;
88          }
89  
90          if (object == null || getClass() != object.getClass()) {
91              return false;
92          }
93  
94          CascadeValidation that = (CascadeValidation) object;
95  
96          if (!propertyName.equals(that.propertyName)) {
97              return false;
98          }
99  
100         return (ObjectUtils.nullSafeEquals(applicabilityCondition, that.applicabilityCondition));
101     }
102 
103     public int hashCode() {
104         int result;
105         result = propertyName.hashCode();
106         result = 29 * result + (applicabilityCondition != null ? applicabilityCondition.hashCode() : 0);
107         return result;
108     }
109 }