KickJava   Java API By Example, From Geeks To Geeks.

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


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  * NonZeroLengthConstraint.java March 24, 2003, 5:17 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 import com.sun.enterprise.tools.common.validation.constraints.ConstraintFailure;
35 import com.sun.enterprise.tools.common.validation.util.BundleReader;
36
37 /**
38  * NonZeroLengthConstraint is a {@link Constraint} to validate non zero
39  * length value. It implements <code>Constraint</code> interface and extends
40  * {@link ConstraintUtils} class.
41  * <code>match</code> method of this object returns empty
42  * <code>Collection</code> if the value being validated is of non zero length;
43  * else it returns a <code>Collection</code> with a {@link ConstraintFailure}
44  * object in it.
45  * <code>ConstraintUtils</code> class provides utility methods for formating
46  * failure messages and a <code>print<method> method to print this object.
47  *
48  * @author Rajeshwar Patil
49  * @version %I%, %G%
50  */

51 public class NonZeroLengthConstraint extends ConstraintUtils
52                 implements Constraint {
53     
54     /** Creates a new instance of
55      * <code>NonZeroLengthConstraintConstraint</code>.
56      */

57     public NonZeroLengthConstraint() {
58     }
59
60
61     /**
62      * Validates the given value against this <code>Constraint</code>.
63      *
64      * @param value the value to be validated.
65      * @param name the element name, value of which is being validated.
66      * It is used only in case of <code>Constraint</code> failure, to construct
67      * the failure message.
68      *
69      * @return <code>Collection</code> the Collection of
70      * <code>ConstraintFailure</code> Objects. Collection is empty if
71      * there are no failures. Failure can occur if value being validated
72      * is of zero length.
73      */

74     public Collection JavaDoc match(String JavaDoc value, String JavaDoc name) {
75         Collection JavaDoc failed_constrained_list = new ArrayList JavaDoc();
76         if (value != null){
77             if(value.length() == 0){
78                 String JavaDoc failureMessage = formatFailureMessage(toString(), name);
79                 failed_constrained_list.add(new ConstraintFailure(toString(),
80                     value, name, failureMessage, BundleReader.getValue(
81                         "MSG_NonZeroLengthConstraint_Failure"))); //NOI18N
82
}
83         }
84         return failed_constrained_list;
85     }
86 }
87
Popular Tags