1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package nl.openedge.baritus.validation.impl;
33
34 import java.util.ArrayList;
35 import java.util.Iterator;
36 import java.util.List;
37
38 import nl.openedge.baritus.FormBeanContext;
39 import nl.openedge.baritus.validation.ValidationActivationRule;
40
41 import org.infohazard.maverick.flow.ControllerContext;
42
43 /***
44 * You can use a list of validators while registering just one by using
45 * NestedValidationActionRule.
46 *
47 * @author Eelco Hillenius
48 */
49 public class NestedValidationActivationRule implements ValidationActivationRule
50 {
51
52 private List rules = null;
53
54 /***
55 * allows validation if all nested rules return true.
56 * @param cctx controller context
57 * @param formBeanContext form bean context
58 * @return boolean if all nested rules return true, false if one of them did not
59 *
60 * @see nl.openedge.baritus.validation.ValidationActivationRule#allowValidation(org.infohazard.maverick.flow.ControllerContext, nl.openedge.baritus.FormBeanContext)
61 */
62 public boolean allowValidation(
63 ControllerContext cctx,
64 FormBeanContext formBeanContext)
65 {
66 boolean allow = true;
67
68 if(rules != null)
69 {
70 for(Iterator i = rules.iterator(); i.hasNext(); )
71 {
72 ValidationActivationRule nested = (ValidationActivationRule)i.next();
73 allow = nested.allowValidation(cctx, formBeanContext);
74
75 if(!allow) break;
76 }
77 }
78
79 return allow;
80 }
81
82 /***
83 * add a validation activation rule to the end of the list.
84 * @param rule validation activation rule to be added
85 */
86 public void addRule(ValidationActivationRule rule)
87 {
88 if(rules == null)
89 {
90 rules = new ArrayList();
91 }
92 rules.add(rule);
93 }
94
95 /***
96 * add a validation activation rule to the list at the provided position.
97 *
98 * @param index the position in the list at which the provided rule should
99 * be inserted
100 * @param rule validation activation rule to be added
101 */
102 public void addRule(int index, ValidationActivationRule rule)
103 {
104 if(rules == null)
105 {
106 rules = new ArrayList();
107 }
108 rules.add(index, rule);
109 }
110
111 /***
112 * add list of rules to current list of rules.
113 *
114 * @param rules list of rules to be added
115 */
116 public void addAllRules(List rules)
117 {
118 if(rules == null)
119 {
120 rules = new ArrayList();
121 }
122 rules.addAll(rules);
123 }
124
125
126 /***
127 * remove a validation activation rule from list.
128 * @param rule validation activation rule to be removed
129 */
130 public void removeRule(ValidationActivationRule rule)
131 {
132 if(rules != null)
133 {
134 rules.remove(rule);
135 }
136 }
137
138 /***
139 * remove a validation activation rule at the provided position
140 * @param index the position at which the rule should be removed
141 */
142 public void removeRule(int index)
143 {
144 if(rules != null)
145 {
146 rules.remove(index);
147 }
148 }
149
150 /***
151 * clear the list of rules.
152 */
153 public void clear()
154 {
155 if(rules != null)
156 {
157 rules.clear();
158 rules = null;
159 }
160 }
161
162
163 /***
164 * get list of validation activation rules.
165 * @return List validation activation rules
166 */
167 public List getRules()
168 {
169 return rules;
170 }
171
172 /***
173 * set list of validation activation rules.
174 * @param list validation activation rules
175 */
176 public void setRules(List list)
177 {
178 rules = list;
179 }
180
181 }