KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > validation > constraints > AndConstraint


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.validation.constraints;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24
25 /**
26  * AndConstraint is a logical <code>And</code> {@link Constraint}. It validates
27  * the given value by performing logical <code>And</code> of validations of the
28  * value against its constituent <code>leftConstraint</code> and
29  * <code>rightConstraint</code>.
30  * <p>
31  * It implements <code>Constraint</code> interface and extends
32  * {@link ConstraintUtils} class.
33  * <code>match</code> method of this object returns empty collection if the
34  * value being validated satisfies both the <code>leftConstraint</code> and the
35  * <code>rightConstraint</code>; else it returns a <code>Collection</code>
36  * with {@link ConstraintFailure} objects in it for the failed
37  * <code>Constraints</code>.
38  * <code>ConstraintUtils</code> class provides utility methods for formating
39  * failure messages and a <code>print<method> method to print this object.
40  *
41  * @author Rajeshwar Patil
42  * @version %I%, %G%
43  */

44 public class AndConstraint extends ConstraintUtils implements Constraint {
45
46     /**
47      * The left <code>Constraint</code> of this <code>AndCosntraint</code>
48      * This <code>AndConstraint</code> is logical <code>AND</code> of its left
49      * <code>Constraint</code> and right <code>Constraint</code>.
50      */

51     private Constraint leftConstraint = null;
52
53
54     /**
55      * The right <code>Constraint</code> of this <code>AndCosntraint</code>
56      * This <code>AndConstraint</code> is logical <code>AND</code> of its left
57      * <code>Constraint</code> and right <code>Constraint</code>.
58      */

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

89     public Collection JavaDoc match(String JavaDoc value, String JavaDoc name) {
90         Collection JavaDoc failed_constrained_list = new ArrayList JavaDoc();
91         failed_constrained_list.addAll(leftConstraint.match(value, name));
92         failed_constrained_list.addAll(rightConstraint.match(value, name));
93         return failed_constrained_list;
94     }
95
96
97     /**
98      * Sets the given <code>Constraint</code> as the
99      * <code>leftConstraint</code> of this object.
100      *
101      * @param constraint the <code>Constraint</code> to be
102      * set as <code>leftConstraint</code> of this object
103      */

104     public void setLeftConstraint(Constraint constraint){
105         leftConstraint = constraint;
106     }
107
108
109     /**
110      * Sets the given <code>Constraint</code> as
111      * the <code>rightConstraint</code> of this object.
112      *
113      * @param constraint the <code>Constraint</code> to be
114      * set as <code>rightConstraint</code> of this object
115      */

116     public void setRightConstraint(Constraint constraint){
117         rightConstraint = constraint;
118     }
119
120
121     /**
122      * Prints this <code>Constraint</code>.
123      */

124     public void print() {
125         super.print();
126         ((ConstraintUtils)leftConstraint).print();
127         ((ConstraintUtils)rightConstraint).print();
128     }
129 }
130
Popular Tags