KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > validation > constraints > AndConstraint


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * AndConstraint.java March 24, 2003, 5:42 PM
26  *
27  */

28
29 package com.sun.enterprise.tools.common.validation.constraints;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.Collection JavaDoc;
33
34 /**
35  * AndConstraint is a logical <code>And</code> {@link Constraint}. It validates
36  * the given value by performing logical <code>And</code> of validations of the
37  * value against its constituent <code>leftConstraint</code> and
38  * <code>rightConstraint</code>.
39  * <p>
40  * It implements <code>Constraint</code> interface and extends
41  * {@link ConstraintUtils} class.
42  * <code>match</code> method of this object returns empty collection if the
43  * value being validated satisfies both the <code>leftConstraint</code> and the
44  * <code>rightConstraint</code>; else it returns a <code>Collection</code>
45  * with {@link ConstraintFailure} objects in it for the failed
46  * <code>Constraints</code>.
47  * <code>ConstraintUtils</code> class provides utility methods for formating
48  * failure messages and a <code>print<method> method to print this object.
49  *
50  * @author Rajeshwar Patil
51  * @version %I%, %G%
52  */

53 public class AndConstraint extends ConstraintUtils implements Constraint {
54
55     /**
56      * The left <code>Constraint</code> of this <code>AndCosntraint</code>
57      * This <code>AndConstraint</code> is logical <code>AND</code> of its left
58      * <code>Constraint</code> and right <code>Constraint</code>.
59      */

60     private Constraint leftConstraint = null;
61
62
63     /**
64      * The right <code>Constraint</code> of this <code>AndCosntraint</code>
65      * This <code>AndConstraint</code> is logical <code>AND</code> of its left
66      * <code>Constraint</code> and right <code>Constraint</code>.
67      */

68     private Constraint rightConstraint = null;
69
70
71     /** Creates a new instance of <code>AndConstraint</code> */
72     public AndConstraint() {
73         Constraint leftConstraint = null;
74         Constraint rightConstraint = null;
75     }
76
77
78     /** Creates a new instance of <code>AndConstraint</code> */
79     public AndConstraint(Constraint leftConstraint,
80             Constraint rightConstraint){
81         this.leftConstraint = leftConstraint;
82         this.rightConstraint = rightConstraint;
83     }
84
85
86     /**
87      * Validates the given value against this <code>Constraint</code>.
88      *
89      * @param value the value to be validated
90      * @param name the element name, value of which is being validated.
91      * It is used only in case of <code>Constraint</code> failure, to construct
92      * the failure message.
93      *
94      * @return <code>Collection</code> the Collection of
95      * <code>ConstraintFailure</code> Objects. Collection is empty if
96      * there are no failures.
97      */

98     public Collection JavaDoc match(String JavaDoc value, String JavaDoc name) {
99         Collection JavaDoc failed_constrained_list = new ArrayList JavaDoc();
100         failed_constrained_list.addAll(leftConstraint.match(value, name));
101         failed_constrained_list.addAll(rightConstraint.match(value, name));
102         return failed_constrained_list;
103     }
104
105
106     /**
107      * Sets the given <code>Constraint</code> as the
108      * <code>leftConstraint</code> of this object.
109      *
110      * @param constraint the <code>Constraint</code> to be
111      * set as <code>leftConstraint</code> of this object
112      */

113     public void setLeftConstraint(Constraint constraint){
114         leftConstraint = constraint;
115     }
116
117
118     /**
119      * Sets the given <code>Constraint</code> as
120      * the <code>rightConstraint</code> of this object.
121      *
122      * @param constraint the <code>Constraint</code> to be
123      * set as <code>rightConstraint</code> of this object
124      */

125     public void setRightConstraint(Constraint constraint){
126         rightConstraint = constraint;
127     }
128
129
130     /**
131      * Prints this <code>Constraint</code>.
132      */

133     public void print() {
134         super.print();
135         ((ConstraintUtils)leftConstraint).print();
136         ((ConstraintUtils)rightConstraint).print();
137     }
138 }
139
Popular Tags