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 org.araneaframework.Environment;
18: import org.araneaframework.uilib.form.Constraint;
19:
20: /**
21: * Constraint that will be applied iff the constraint's group is active.
22: *
23: * @author Ilja Livenson (ilja@webmedia.ee)
24: */
25: public class GroupedConstraint extends BaseConstraint {
26: private ConstraintGroupHelper conditionalConstraintHelper;
27: private Constraint constraint;
28: private String group;
29:
30: public GroupedConstraint(ConstraintGroupHelper helper,
31: Constraint constraint, String group) {
32: this .conditionalConstraintHelper = helper;
33: this .constraint = constraint;
34: this .group = group;
35: }
36:
37: protected void validateConstraint() throws Exception {
38: // in case the constraint's group is inactive, just ignore it
39: if (!this .conditionalConstraintHelper.isGroupActive(this .group))
40: return;
41: else
42: this .constraint.validate();
43: addErrors(constraint.getErrors());
44: constraint.clearErrors();
45: }
46:
47: public ConstraintGroupHelper getConditionalConstraintHelper() {
48: return conditionalConstraintHelper;
49: }
50:
51: public void setConditionalConstraintHelper(
52: ConstraintGroupHelper conditionalConstraintHelper) {
53: this .conditionalConstraintHelper = conditionalConstraintHelper;
54: }
55:
56: public void setEnvironment(Environment environment) {
57: constraint.setEnvironment(environment);
58: }
59:
60: public void setCustomErrorMessage(String customErrorMessage) {
61: constraint.setCustomErrorMessage(customErrorMessage);
62: }
63:
64: public void clearErrors() {
65: constraint.clearErrors();
66: }
67: }
|