KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > xerces > utils > ImplementationMessages


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999 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 package org.enhydra.apache.xerces.utils;
58
59 import java.util.ListResourceBundle JavaDoc;
60 import java.util.Locale JavaDoc;
61 import java.util.ResourceBundle JavaDoc;
62
63 /**
64  * ImplementationMessages provides messages internal to the parser implementation
65  *
66  * @version
67  */

68 public class ImplementationMessages implements XMLMessageProvider {
69     /**
70      * The domain of messages concerning the Xerces implementation.
71      */

72     public static final String JavaDoc XERCES_IMPLEMENTATION_DOMAIN = "http://www.apache.org/xml/xerces.html";
73
74     /**
75      *
76      */

77     public void setLocale(Locale JavaDoc locale) {
78         fLocale = locale;
79     }
80     /**
81      *
82      */

83     public Locale JavaDoc getLocale() {
84         return fLocale;
85     }
86
87     /**
88      * Creates a message from the specified key and replacement
89      * arguments, localized to the given locale.
90      *
91      * @param locale The requested locale of the message to be
92      * created.
93      * @param key The key for the message text.
94      * @param args The arguments to be used as replacement text
95      * in the message created.
96      */

97     public String JavaDoc createMessage(Locale JavaDoc locale, int majorCode, int minorCode, Object JavaDoc args[]) {
98         boolean throwex = false;
99         if (fResourceBundle == null || locale != fLocale) {
100             if (locale != null)
101                 fResourceBundle = ListResourceBundle.getBundle("org.enhydra.apache.xerces.msg.ImplementationMessages", locale);
102             if (fResourceBundle == null)
103                 fResourceBundle = ListResourceBundle.getBundle("org.enhydra.apache.xerces.msg.ImplementationMessages");
104         }
105         if (majorCode < 0 || majorCode >= fgMessageKeys.length - 1) {
106             majorCode = BAD_MAJORCODE;
107             throwex = true;
108         }
109         String JavaDoc msgKey = fgMessageKeys[majorCode];
110         String JavaDoc msg = fResourceBundle.getString(msgKey);
111         if (args != null) {
112             try {
113                 msg = java.text.MessageFormat.format(msg, args);
114             } catch (Exception JavaDoc e) {
115                 msg = fResourceBundle.getString(fgMessageKeys[FORMAT_FAILED]);
116                 msg += " " + fResourceBundle.getString(msgKey);
117             }
118         }
119         if (throwex) {
120             throw new RuntimeException JavaDoc(msg);
121         }
122         return msg;
123     }
124     //
125
//
126
//
127
private Locale JavaDoc fLocale = null;
128     private ResourceBundle JavaDoc fResourceBundle = null;
129     //
130
//
131
//
132
public static final int
133         BAD_MAJORCODE = 0, // majorCode parameter to createMessage was out of bounds
134
ENC4 = 1, // "Invalid UTF-8 code. (byte: 0x{0})"
135
ENC5 = 2, // "Invalid UTF-8 code. (bytes: 0x{0} 0x{1})"
136
ENC6 = 3, // "Invalid UTF-8 code. (bytes: 0x{0} 0x{1} 0x{2})"
137
ENC7 = 4, // "Invalid UTF-8 code. (bytes: 0x{0} 0x{1} 0x{2} 0x{3})"
138
IO0 = 5, // "File, \"{0}\", not found."
139
VAL_BST = 6, // "Invalid ContentSpecNode.NODE_XXX value for binary op CMNode."
140
VAL_CMSI = 7, // "Invalid CMStateSet bit index."
141
VAL_CST = 8, // "Unknown ContentSpecNode.NODE_XXX value."
142
VAL_LST = 9, // "Invalid ContentSpecNode.NODE_XXX value for leaf CMNode."
143
VAL_NIICM = 10, // "Only * unary ops should be in the internal content model tree."
144
VAL_NPCD = 11, // "PCData found in non-mixed model content."
145
VAL_UST = 12, // "Invalid ContentSpecNode.NODE_XXX value for unary op CMNode."
146
VAL_WCGHI = 13, // "Input to whatCanGoHere() is inconsistent."
147
INT_DCN = 14, // "Internal Error: dataChunk == NULL"
148
INT_PCN = 15, // "Internal Error: fPreviousChunk == NULL"
149
FATAL_ERROR = 16, // "Stopping after fatal error: {0}"
150

151         //
152
// KEEP THIS AT THE END
153
//
154
FORMAT_FAILED = 17; // "Internal Error while formatting error message "
155

156     //
157
// Table of error code to error key strings.
158
//
159
private static final String JavaDoc[] fgMessageKeys = {
160         "BadMajorCode", // 0, "The majorCode parameter to createMessage was out of bounds."
161
"ENC4", // 1, "Invalid UTF-8 code. (byte: 0x{0})"
162
"ENC5", // 2, "Invalid UTF-8 code. (bytes: 0x{0} 0x{1})"
163
"ENC6", // 3, "Invalid UTF-8 code. (bytes: 0x{0} 0x{1} 0x{2})"
164
"ENC7", // 4, "Invalid UTF-8 code. (bytes: 0x{0} 0x{1} 0x{2} 0x{3})"
165
"FileNotFound", // 5, "File, \"{0}\", not found."
166
"VAL_BST", // 6, "Invalid ContentSpecNode.NODE_XXX value for binary op CMNode."
167
"VAL_CMSI", // 7, "Invalid CMStateSet bit index."
168
"VAL_CST", // 8, "Unknown ContentSpecNode.NODE_XXX value."
169
"VAL_LST", // 9, "Invalid ContentSpecNode.NODE_XXX value for leaf CMNode."
170
"VAL_NIICM", // 10, "Only * unary ops should be in the internal content model tree."
171
"VAL_NPCD", // 11, "PCData found in non-mixed model content."
172
"VAL_UST", // 12, "Invalid ContentSpecNode.NODE_XXX value for unary op CMNode."
173
"VAL_WCGHI", // 13, "Input to whatCanGoHere() is inconsistent."
174
"INT_DCN", // 14, "Internal Error: dataChunk == NULL"
175
"INT_PCN", // 15, "Internal Error: fPreviousChunk == NULL"
176
"FatalError", // 16, "Stopping after fatal error: {0}"
177

178         //
179
// KEEP THIS AT THE END
180
//
181
"FormatFailed", // 17, "An internal error occurred while formatting the following message:"
182
null
183     };
184 }
185
Popular Tags