KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ConstraintUtils.java May 20, 2003, 1:19 PM
26  *
27  */

28
29 package com.sun.enterprise.tools.common.validation.constraints;
30
31 import java.text.MessageFormat JavaDoc;
32 import com.sun.enterprise.tools.common.validation.util.BundleReader;
33
34
35 /**
36  * ConstraintUtils is an <code>Object</code> providing the Utilities.
37  * <code>formatFailureMessage</code> methods, are the utility methods
38  * to format the failure messages. These Methods are used to format
39  * failure messages. Method <code>print</code> is the utility method
40  * to print this <code>Object</code>
41  *
42  * @author Rajeshwar Patil
43  * @version %I%, %G%
44  */

45 class ConstraintUtils {
46     /* A class implementation comment can go here. */
47
48     
49     /** Creates a new instance of ConstraintUtils */
50     ConstraintUtils() {
51     }
52
53
54     /**
55     * Prints this <code>Object</code>
56     */

57     void print() {
58         String JavaDoc format = BundleReader.getValue("Name_Value_Pair_Format");//NOI18N
59
Object JavaDoc[] arguments = new Object JavaDoc[]{"Constraint", this}; //NOI18N
60
System.out.println(MessageFormat.format(format, arguments));
61     }
62
63
64     /**
65     * Formats the failure message from the given information.
66     *
67     * @param constraint the failed <code>Constraint</code> name
68     * @param value the value the <code>constriant</code> failed for
69     * @param name the name of the <code>value</code> the
70     * <code>constriant</code> failed for
71     *
72     * @return the formatted failure message
73     */

74     String JavaDoc formatFailureMessage(String JavaDoc constraint, String JavaDoc value,
75             String JavaDoc name){
76         String JavaDoc failureMessage = null;
77         if(!((constraint == null) || (constraint.length() == 0) ||
78             (value == null) || (name == null) || (name.length() == 0))){
79
80             String JavaDoc format = BundleReader.getValue("MSG_Failure"); //NOI18N
81
Object JavaDoc[] arguments = new Object JavaDoc[]{constraint, value, name};
82
83             failureMessage = MessageFormat.format(format, arguments);
84         }
85         return failureMessage;
86     }
87
88
89     /**
90     * Formats the failure message from the given information.
91     *
92     * @param constraint the failed <code>Constraint</code> name
93     * @param name the name of the element, the <code>constriant</code>
94     * failed for
95     *
96     * @return the formatted failure message
97     */

98     String JavaDoc formatFailureMessage(String JavaDoc constraint, String JavaDoc name){
99         String JavaDoc failureMessage = null;
100         if(!((constraint == null) || (constraint.length() == 0) ||
101                 (name == null) || (name.length() == 0))){
102
103             String JavaDoc format = BundleReader.getValue("MSG_Failure_1"); //NOI18N
104
Object JavaDoc[] arguments = new Object JavaDoc[]{constraint, name};
105
106             failureMessage = MessageFormat.format(format, arguments);
107         }
108         return failureMessage;
109     }
110 }
111
Popular Tags