01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: **/package org.araneaframework.uilib.form.constraint;
16:
17: import java.util.ArrayList;
18: import java.util.Collection;
19: import java.util.Iterator;
20: import java.util.List;
21: import org.araneaframework.Environment;
22: import org.araneaframework.core.Assert;
23: import org.araneaframework.uilib.form.Constraint;
24:
25: /**
26: * This class is a generalization of a constraint that may contain other
27: * constraints.
28: *
29: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
30: */
31: public abstract class BaseCompositeConstraint extends BaseConstraint {
32: protected List constraints = new ArrayList();
33:
34: public BaseCompositeConstraint() {
35: }
36:
37: /**
38: * @since 1.0.9
39: */
40: public BaseCompositeConstraint(Constraint constraint) {
41: addConstraint(constraint);
42: }
43:
44: /**
45: * @since 1.0.9
46: */
47: public BaseCompositeConstraint(Collection constraints) {
48: addConstraints(constraints);
49: }
50:
51: /**
52: * Adds a contained constraint.
53: *
54: * @param constraint
55: * contained constraint.
56: * @return this composite constraint
57: */
58: public BaseCompositeConstraint addConstraint(Constraint constraint) {
59: constraints.add(constraint);
60: return this ;
61: }
62:
63: /**
64: * Adds contained constraints from supplied Collection.
65: *
66: * @param constraints Collection<Constraint>
67: * @return this composite constraint
68: * @since 1.0.9
69: */
70: public BaseCompositeConstraint addConstraints(Collection constraints) {
71: Assert.notNullParam(constraints, "constraints");
72: this .constraints.addAll(constraints);
73: return this ;
74: }
75:
76: /**
77: * Clears contained constraints.
78: */
79: public void clearConstraints() {
80: constraints.clear();
81: }
82:
83: public void setEnvironment(Environment environment) {
84: super .setEnvironment(environment);
85: for (Iterator i = constraints.iterator(); i.hasNext();) {
86: Constraint c = (Constraint) i.next();
87: c.setEnvironment(environment);
88: }
89: }
90: }
|