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.io.Serializable;
18: import java.util.HashSet;
19: import java.util.Set;
20: import org.araneaframework.uilib.form.Constraint;
21:
22: /**
23: * Helper for the {@link GroupedConstraint} that holds a set of currently
24: * active groups and provides a factory method for wrapping <code>Constraint</code>
25: * instances in {@link GroupedConstraint}.
26: * @author Ilja Livenson (ilja@webmedia.ee)
27: *
28: */
29: public class ConstraintGroupHelper implements Serializable {
30: private Set activeGroups = new HashSet();
31:
32: /**
33: * Wrap the <code>Constraint</code> in the <code>GroupedConstraint</code> instance
34: * assigned to the specified group.
35: * @param constraint Constraint to wrap.
36: * @param group Name of the group to assign the constraint to.
37: */
38: public Constraint createGroupedConstraint(Constraint constraint,
39: String group) {
40: return new GroupedConstraint(this , constraint, group);
41: }
42:
43: public void setActiveGroups(Set activeGroups) {
44: this .activeGroups = activeGroups == null ? new HashSet()
45: : activeGroups;
46: }
47:
48: public void setActiveGroup(String activeGroup) {
49: if (activeGroup == null) {
50: this .activeGroups = new HashSet();
51: return;
52: }
53: this .activeGroups = new HashSet(1);
54: this .activeGroups.add(activeGroup);
55: }
56:
57: public Set getActiveGroups() {
58: return activeGroups;
59: }
60:
61: public boolean isGroupActive(String group) {
62: return this.activeGroups.contains(group);
63: }
64: }
|