KickJava   Java API By Example, From Geeks To Geeks.

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


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.text.MessageFormat JavaDoc;
23 import org.netbeans.modules.j2ee.sun.validation.util.BundleReader;
24
25
26 /**
27  * ConstraintUtils is an <code>Object</code> providing the Utilities.
28  * <code>formatFailureMessage</code> methods, are the utility methods
29  * to format the failure messages. These Methods are used to format
30  * failure messages. Method <code>print</code> is the utility method
31  * to print this <code>Object</code>
32  *
33  * @author Rajeshwar Patil
34  * @version %I%, %G%
35  */

36 class ConstraintUtils {
37     /* A class implementation comment can go here. */
38
39     
40     /** Creates a new instance of ConstraintUtils */
41     ConstraintUtils() {
42     }
43
44
45     /**
46     * Prints this <code>Object</code>
47     */

48     void print() {
49         String JavaDoc format = BundleReader.getValue("Name_Value_Pair_Format");//NOI18N
50
Object JavaDoc[] arguments = new Object JavaDoc[]{"Constraint", this}; //NOI18N
51
System.out.println(MessageFormat.format(format, arguments));
52     }
53
54
55     /**
56     * Formats the failure message from the given information.
57     *
58     * @param constraint the failed <code>Constraint</code> name
59     * @param value the value the <code>constriant</code> failed for
60     * @param name the name of the <code>value</code> the
61     * <code>constriant</code> failed for
62     *
63     * @return the formatted failure message
64     */

65     String JavaDoc formatFailureMessage(String JavaDoc constraint, String JavaDoc value,
66             String JavaDoc name){
67         String JavaDoc failureMessage = null;
68         if(!((constraint == null) || (constraint.length() == 0) ||
69             (value == null) || (name == null) || (name.length() == 0))){
70
71             String JavaDoc format = BundleReader.getValue("MSG_Failure"); //NOI18N
72
Object JavaDoc[] arguments = new Object JavaDoc[]{constraint, value, name};
73
74             failureMessage = MessageFormat.format(format, arguments);
75         }
76         return failureMessage;
77     }
78
79
80     /**
81     * Formats the failure message from the given information.
82     *
83     * @param constraint the failed <code>Constraint</code> name
84     * @param name the name of the element, the <code>constriant</code>
85     * failed for
86     *
87     * @return the formatted failure message
88     */

89     String JavaDoc formatFailureMessage(String JavaDoc constraint, String JavaDoc name){
90         String JavaDoc failureMessage = null;
91         if(!((constraint == null) || (constraint.length() == 0) ||
92                 (name == null) || (name.length() == 0))){
93
94             String JavaDoc format = BundleReader.getValue("MSG_Failure_1"); //NOI18N
95
Object JavaDoc[] arguments = new Object JavaDoc[]{constraint, name};
96
97             failureMessage = MessageFormat.format(format, arguments);
98         }
99         return failureMessage;
100     }
101 }
102
Popular Tags