KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > xerces > validators > datatype > DatatypeMessageProvider


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.enhydra.apache.xerces.validators.datatype;
59
60 import java.util.ListResourceBundle JavaDoc;
61 import java.util.Locale JavaDoc;
62 import java.util.ResourceBundle JavaDoc;
63
64 import org.enhydra.apache.xerces.utils.XMLMessageProvider;
65
66 /**
67  *
68  * @author Jeffrey Rodriguez
69  * @version $Id: DatatypeMessageProvider.java,v 1.2 2005/01/26 08:28:44 jkjome Exp $
70  */

71 public class DatatypeMessageProvider implements XMLMessageProvider {
72     /**
73      * The domain of messages concerning the XML Schema: Datatypes specification.
74      */

75     public static final String JavaDoc DATATYPE_DOMAIN = "http://www.w3.org/TR/xml-schema-2";
76
77     /**
78      * Set the locale used for error messages
79      *
80      * @param locale the new locale
81      */

82     public void setLocale(Locale JavaDoc locale) {
83         fLocale = locale;
84     }
85     /**
86      * get the local used for error messages
87      *
88      * @return the locale
89      */

90     public Locale JavaDoc getLocale() {
91         return fLocale;
92     }
93
94     /**
95      * Creates a message from the specified key and replacement
96      * arguments, localized to the given locale.
97      *
98      * @param locale The requested locale of the message to be
99      * created.
100      * @param key The key for the message text.
101      * @param args The arguments to be used as replacement text
102      * in the message created.
103      */

104     public String JavaDoc createMessage(Locale JavaDoc locale, int majorCode, int minorCode, Object JavaDoc args[]) {
105         boolean throwex = false;
106         if ( fResourceBundle == null || locale != fLocale ) {
107             if ( locale != null )
108                 fResourceBundle = ListResourceBundle.getBundle("org.enhydra.apache.xerces.msg.DatatypeMessages", locale);
109             if ( fResourceBundle == null )
110                 fResourceBundle = ListResourceBundle.getBundle("org.enhydra.apache.xerces.msg.DatatypeMessages");
111         }
112         if ( majorCode < 0 || majorCode >= fgMessageKeys.length ) {
113             majorCode = MSG_BAD_MAJORCODE;
114             throwex = true;
115         }
116         String JavaDoc msgKey = fgMessageKeys[majorCode];
117         String JavaDoc msg = fResourceBundle.getString(msgKey);
118         if ( args != null ) {
119             try {
120                 msg = java.text.MessageFormat.format(msg, args);
121             }
122             catch ( Exception JavaDoc e ) {
123                 msg = fResourceBundle.getString(fgMessageKeys[MSG_FORMAT_FAILURE]);
124                 msg += " " + fResourceBundle.getString(msgKey);
125             }
126         }
127
128         if ( throwex ) {
129             throw new RuntimeException JavaDoc(msg);
130         }
131         return msg;
132     }
133     //
134
//
135
//
136
private Locale JavaDoc fLocale = null;
137     private ResourceBundle JavaDoc fResourceBundle = null;
138     //
139
// Major Codes
140
//
141
private static int counter = 0;
142     public static final int
143     MSG_BAD_MAJORCODE = counter++, // majorCode parameter to createMessage was out of bounds
144
MSG_FORMAT_FAILURE = counter++, // exception thrown during messageFormat call
145
NOT_BOOLEAN = counter++,
146     NOT_DECIMAL = counter++,
147     NOT_FLOAT = counter++,
148     NOT_DOUBLE = counter++,
149     INVALID_ENUM_VALUE = counter++,
150     OUT_OF_BOUNDS = counter++,
151     NOT_ENUM_VALUE = counter++,
152     FRACTION_GREATER_TOTALDIGITS = counter++,
153     FRACTION_EXCEEDED = counter++,
154     TOTALDIGITS_EXCEEDED = counter++,
155     ILLEGAL_FACET_VALUE = counter++,
156     ILLEGAL_ANYURI_FACET = counter++,
157     ILLEGAL_BOOLEAN_FACET = counter++,
158     ILLEGAL_BASE64_FACET = counter++,
159     ILLEGAL_DATETIME_FACET = counter++,
160     ILLEGAL_DECIMAL_FACET = counter++,
161     ILLEGAL_DOUBLE_FACET = counter++,
162     ILLEGAL_FLOAT_FACET = counter++,
163     ILLEGAL_HEXBINARY_FACET = counter++,
164     ILLEGAL_NOTATION_FACET = counter++,
165     ILLEGAL_QNAME_FACET = counter++,
166     ILLEGAL_STRING_FACET = counter++,
167     ILLEGAL_LIST_FACET = counter++,
168     ILLEGAL_UNION_FACET = counter++,
169     ILLEGAL_ANYSIMPLETYPE_FACET = counter++,
170
171     MSG_MAX_CODE = counter;
172
173     //
174
// Minor Codes
175
//
176
public static final int
177     MSG_NONE = 0;
178
179     public static final String JavaDoc[] fgMessageKeys = {
180         "BadMajorCode",
181         "FormatFailed",
182         "NotBoolean",
183         "NotDecimal",
184         "NotFloat",
185         "NotDouble",
186         "InvalidEnumValue",
187         "OutOfBounds",
188         "NotAnEnumValue",
189         "FractionDigitsLargerThanTotalDigits",
190         "FractionDigitsExceeded",
191         "TotalDigitsExceeded",
192         "IllegalFacetValue",
193         "IllegalAnyURIFacet",
194         "IllegalBooleanFacet",
195         "IllegalBase64Facet",
196         "IllegalDateTimeFacet",
197         "IllegalDecimalFacet",
198         "IllegalDoubleFacet",
199         "IllegalFloatFacet",
200         "IllegalHexBinaryFacet",
201         "IllegalNotationFacet",
202         "IllegalQNameFacet",
203         "IllegalStringFacet",
204         "IllegalListFacet",
205         "IllegalUnionFacet",
206         "IllegalAnySimpleTypeFacet"
207     };
208
209 }
210
Popular Tags