KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > xerces > validators > schema > SchemaMessageProvider


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 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.schema;
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  * SchemaMessageProvider implements an XMLMessageProvider that
68  * provides localizable error messages for the W3C XML Schema Language
69  *
70  */

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

75     public static final String JavaDoc SCHEMA_DOMAIN = "http://www.w3.org/TR/xml-schema-1";
76
77     /**
78      *
79      */

80     public void setLocale(Locale JavaDoc locale) {
81         fLocale = locale;
82     }
83     /**
84      *
85      */

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

100     public String JavaDoc createMessage(Locale JavaDoc locale, int majorCode, int minorCode, Object JavaDoc args[]) {
101         boolean throwex = false;
102         if (fResourceBundle == null || locale != fLocale) {
103             if (locale != null)
104                 fResourceBundle = ListResourceBundle.getBundle("org.enhydra.apache.xerces.msg.SchemaMessages", locale);
105             if (fResourceBundle == null)
106                 fResourceBundle = ListResourceBundle.getBundle("org.enhydra.apache.xerces.msg.SchemaMessages");
107         }
108         if (majorCode < 0 || majorCode >= fgMessageKeys.length) {
109             majorCode = MSG_BAD_MAJORCODE;
110             throwex = true;
111         }
112         String JavaDoc msgKey = fgMessageKeys[majorCode];
113         String JavaDoc msg = fResourceBundle.getString(msgKey);
114         if (args != null) {
115             try {
116                 msg = java.text.MessageFormat.format(msg, args);
117             } catch (Exception JavaDoc e) {
118                 msg = fResourceBundle.getString(fgMessageKeys[MSG_FORMAT_FAILURE]);
119                 msg += " " + fResourceBundle.getString(msgKey);
120             }
121         }
122
123         if (throwex) {
124             throw new RuntimeException JavaDoc(msg);
125         }
126         return msg;
127     }
128     //
129
//
130
//
131
private Locale JavaDoc fLocale = null;
132     private ResourceBundle JavaDoc fResourceBundle = null;
133     //
134
// Major codes
135
//
136
public static final int
137         MSG_BAD_MAJORCODE = 0, // majorCode parameter to createMessage was out of bounds
138
MSG_FORMAT_FAILURE = 1, // exception thrown during messageFormat call
139
NoValidatorFor = 2,
140         IncorrectDatatype = 3,
141         AttMissingType = 4,
142         NotADatatype = 5,
143         TextOnlyContentWithType = 6,
144         FeatureUnsupported = 7,
145         NestedOnlyInElemOnly = 8,
146         EltRefOnlyInMixedElemOnly = 9,
147         OnlyInEltContent = 10,
148         OrderIsAll = 11,
149         DatatypeWithType = 12,
150         DatatypeQualUnsupported = 13,
151         GroupContentRestricted = 14,
152         UnknownBaseDatatype = 15,
153         BadAttWithRef = 16,
154         NoContentForRef = 17,
155         IncorrectDefaultType = 18,
156         IllegalAttContent = 19,
157         ValueNotInteger = 20,
158         DatatypeError = 21,
159         TypeAlreadySet = 22,
160         GenericError = 23,
161         UnclassifiedError = 24,
162         ContentError = 25,
163         AnnotationError = 26,
164         ListUnionRestrictionError = 27,
165         ProhibitedAttributePresent = 28,
166         // identity constraints
167
UniqueNotEnoughValues = 29,
168         KeyNotEnoughValues = 30,
169         KeyRefNotEnoughValues = 31,
170         DuplicateField = 32,
171         DuplicateUnique = 33,
172         DuplicateKey = 34,
173         KeyNotFound = 35,
174         UnknownField = 36,
175         KeyRefReferNotFound = 37,
176         FixedDiffersFromActual = 38,
177         // simpleType
178
InvalidBaseType = 39,
179         FieldMultipleMatch = 40,
180         KeyRefOutOfScope = 41,
181         AbsentKeyValue = 42,
182         KeyMatchesNillable = 43,
183         BadMinMaxForAllElem = 44,
184         BadMinMaxForGroupWithAll = 45,
185         SeqChoiceContentRestricted = 46,
186         AllContentRestricted = 47,
187         AllContentLimited = 48,
188         MinMaxOnGroupChild = 49,
189         BadMinMaxForAllGp = 50,
190         SchemaLocation = 51,
191         UniqueParticleAttribution = 52,
192         Con3X3ElementAppearance = 53,
193         Con3X3AttributeAppearance = 54,
194         Con3X3AttributeMustAppear = 55,
195         Con3X3AttributeInvalidValue = 56,
196         CardinalityNotEqual = 57,
197         // ...
198

199         MSG_MAX_CODE = 58;
200     //
201
// Minor Codes
202
//
203
public static final int
204         MSG_NONE = 0;
205
206     public static final String JavaDoc[] fgMessageKeys = {
207         "BadMajorCode", // 0, "The majorCode parameter to createMessage was out of bounds."
208
"FormatFailed", // 1, "An internal error occurred while formatting the following message:"
209
"NoValidatorFor", // 2, "No validator for datatype {0}"
210
"IncorrectDatatype", // 3, "Incorrect datatype: {0}"
211
"AttMissingType", // 4, "The {0} attribute must appear with a type attribute."
212
"NotADatatype", // 5, "{0} is not a datatype."
213
"TextOnlyContentWithType", // 6, "The content attribute must be 'textOnly' if you specify a type attribute."
214
"FeatureUnsupported", // 7, "{0} is unsupported"
215
"NestedOnlyInElemOnly", // 8, "Nested Element decls only allowed in elemOnly content"
216
"EltRefOnlyInMixedElemOnly", // 9, "Element references only allowed in mixed or elemOnly content"
217
"OnlyInEltContent", // 10, "{0} only allowed in elemOnly content."
218
"OrderIsAll", // 11, "{0} not allowed if the order is all."
219
"DatatypeWithType", // 12, "Datatype qualifiers can only be used if you specify a type attribute."},
220
"DatatypeQualUnsupported", // 13, "The datatype qualifier {0} is not supported."
221
"GroupContentRestricted", // 14, "Error: {0} content must be one of choice, all or sequence. Saw {1}"
222
"UnknownBaseDatatype", // 15, "Unknown base type {0} for type {1}." },
223
"BadAttWithRef", // 16, "ref cannot appear with any of type, abstract, block, final, nillable, default or fixed"},
224
"NoContentForRef", // 17, "Cannot have child content for an element declaration that has a ref attribute"
225
"IncorrectDefaultType", // 18, "Incorrect type for {0}'s default value: {1}"
226
"IllegalAttContent", // 19, "Illegal content {0} in attribute group"
227
"ValueNotInteger", // 20, "Value of {0} is not an integer"
228
"DatatypeError", // 21, "Datatype error {0}."
229
"TypeAlreadySet", // 22, "The type of the element has already been declared."
230
"GenericError", // 23, "Schema error: {0}."
231
"UnclassifiedError", // 24, "Unclassified error."
232
"ContentError", // 25, "Content (annotation?,..) is incorrect for type {0}"
233
"AnnotationError", // 26, "Annotation can only appear once: type {0}"
234
"ListUnionRestrictionError", // 27, "List | Union | Restriction content is invalid for type {0}"
235
"ProhibitedAttributePresent", // 28, attribue dcld prohibited is present
236
// identity constraint keys
237
"UniqueNotEnoughValues",
238         "KeyNotEnoughValues",
239         "KeyRefNotEnoughValues",
240         "DuplicateField",
241         "DuplicateUnique",
242         "DuplicateKey",
243         "KeyNotFound",
244         "UnknownField",
245         "KeyRefReferNotFound",
246         "FixedDiffersFromActual",
247         "InvalidBaseType",
248         "FieldMultipleMatch",
249         "KeyRefOutOfScope",
250         "AbsentKeyValue",
251         "KeyMatchesNillable",
252         "BadMinMaxForAllElem",
253         "BadMinMaxForGroupWithAll",
254         "SeqChoiceContentRestricted",
255         "AllContentRestricted",
256         "AllContentLimited",
257         "MinMaxOnGroupChild",
258         "BadMinMaxForAllGp",
259         "SchemaLocation",
260         "UniqueParticleAttribution",
261         "Con3X3ElementAppearance",
262         "Con3X3AttributeAppearance",
263         "Con3X3AttributeMustAppear",
264         "Con3X3AttributeInvalidValue",
265         "CardinalityNotEqual",
266         // END
267
};
268 }
269
Popular Tags