KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > xsltc > compiler > util > ErrorMsg


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ErrorMsg.java,v 1.1.2.1 2006/09/19 01:06:58 jeffsuttor Exp $
18  */

19
20 package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
21
22 import java.text.MessageFormat JavaDoc;
23 import java.util.Locale JavaDoc;
24 import java.util.ResourceBundle JavaDoc;
25
26 import com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet;
27 import com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode;
28
29 /**
30  * @author Jacek Ambroziak
31  * @author Santiago Pericas-Geertsen
32  * @author G. Todd Miller
33  * @author Erwin Bolwidt <ejb@klomp.org>
34  * @author Morten Jorgensen
35  */

36 public final class ErrorMsg {
37
38     private String JavaDoc _code;
39     private int _line;
40     private String JavaDoc _message = null;
41     private String JavaDoc _url = null;
42     Object JavaDoc[] _params = null;
43
44     // Compiler error messages
45
public static final String JavaDoc MULTIPLE_STYLESHEET_ERR = "MULTIPLE_STYLESHEET_ERR";
46     public static final String JavaDoc TEMPLATE_REDEF_ERR = "TEMPLATE_REDEF_ERR";
47     public static final String JavaDoc TEMPLATE_UNDEF_ERR = "TEMPLATE_UNDEF_ERR";
48     public static final String JavaDoc VARIABLE_REDEF_ERR = "VARIABLE_REDEF_ERR";
49     public static final String JavaDoc VARIABLE_UNDEF_ERR = "VARIABLE_UNDEF_ERR";
50     public static final String JavaDoc CLASS_NOT_FOUND_ERR = "CLASS_NOT_FOUND_ERR";
51     public static final String JavaDoc METHOD_NOT_FOUND_ERR = "METHOD_NOT_FOUND_ERR";
52     public static final String JavaDoc ARGUMENT_CONVERSION_ERR = "ARGUMENT_CONVERSION_ERR";
53     public static final String JavaDoc FILE_NOT_FOUND_ERR = "FILE_NOT_FOUND_ERR";
54     public static final String JavaDoc INVALID_URI_ERR = "INVALID_URI_ERR";
55     public static final String JavaDoc FILE_ACCESS_ERR = "FILE_ACCESS_ERR";
56     public static final String JavaDoc MISSING_ROOT_ERR = "MISSING_ROOT_ERR";
57     public static final String JavaDoc NAMESPACE_UNDEF_ERR = "NAMESPACE_UNDEF_ERR";
58     public static final String JavaDoc FUNCTION_RESOLVE_ERR = "FUNCTION_RESOLVE_ERR";
59     public static final String JavaDoc NEED_LITERAL_ERR = "NEED_LITERAL_ERR";
60     public static final String JavaDoc XPATH_PARSER_ERR = "XPATH_PARSER_ERR";
61     public static final String JavaDoc REQUIRED_ATTR_ERR = "REQUIRED_ATTR_ERR";
62     public static final String JavaDoc ILLEGAL_CHAR_ERR = "ILLEGAL_CHAR_ERR";
63     public static final String JavaDoc ILLEGAL_PI_ERR = "ILLEGAL_PI_ERR";
64     public static final String JavaDoc STRAY_ATTRIBUTE_ERR = "STRAY_ATTRIBUTE_ERR";
65     public static final String JavaDoc ILLEGAL_ATTRIBUTE_ERR = "ILLEGAL_ATTRIBUTE_ERR";
66     public static final String JavaDoc CIRCULAR_INCLUDE_ERR = "CIRCULAR_INCLUDE_ERR";
67     public static final String JavaDoc RESULT_TREE_SORT_ERR = "RESULT_TREE_SORT_ERR";
68     public static final String JavaDoc SYMBOLS_REDEF_ERR = "SYMBOLS_REDEF_ERR";
69     public static final String JavaDoc XSL_VERSION_ERR = "XSL_VERSION_ERR";
70     public static final String JavaDoc CIRCULAR_VARIABLE_ERR = "CIRCULAR_VARIABLE_ERR";
71     public static final String JavaDoc ILLEGAL_BINARY_OP_ERR = "ILLEGAL_BINARY_OP_ERR";
72     public static final String JavaDoc ILLEGAL_ARG_ERR = "ILLEGAL_ARG_ERR";
73     public static final String JavaDoc DOCUMENT_ARG_ERR = "DOCUMENT_ARG_ERR";
74     public static final String JavaDoc MISSING_WHEN_ERR = "MISSING_WHEN_ERR";
75     public static final String JavaDoc MULTIPLE_OTHERWISE_ERR = "MULTIPLE_OTHERWISE_ERR";
76     public static final String JavaDoc STRAY_OTHERWISE_ERR = "STRAY_OTHERWISE_ERR";
77     public static final String JavaDoc STRAY_WHEN_ERR = "STRAY_WHEN_ERR";
78     public static final String JavaDoc WHEN_ELEMENT_ERR = "WHEN_ELEMENT_ERR";
79     public static final String JavaDoc UNNAMED_ATTRIBSET_ERR = "UNNAMED_ATTRIBSET_ERR";
80     public static final String JavaDoc ILLEGAL_CHILD_ERR = "ILLEGAL_CHILD_ERR";
81     public static final String JavaDoc ILLEGAL_ELEM_NAME_ERR = "ILLEGAL_ELEM_NAME_ERR";
82     public static final String JavaDoc ILLEGAL_ATTR_NAME_ERR = "ILLEGAL_ATTR_NAME_ERR";
83     public static final String JavaDoc ILLEGAL_TEXT_NODE_ERR = "ILLEGAL_TEXT_NODE_ERR";
84     public static final String JavaDoc SAX_PARSER_CONFIG_ERR = "SAX_PARSER_CONFIG_ERR";
85     public static final String JavaDoc INTERNAL_ERR = "INTERNAL_ERR";
86     public static final String JavaDoc UNSUPPORTED_XSL_ERR = "UNSUPPORTED_XSL_ERR";
87     public static final String JavaDoc UNSUPPORTED_EXT_ERR = "UNSUPPORTED_EXT_ERR";
88     public static final String JavaDoc MISSING_XSLT_URI_ERR = "MISSING_XSLT_URI_ERR";
89     public static final String JavaDoc MISSING_XSLT_TARGET_ERR = "MISSING_XSLT_TARGET_ERR";
90     public static final String JavaDoc NOT_IMPLEMENTED_ERR = "NOT_IMPLEMENTED_ERR";
91     public static final String JavaDoc NOT_STYLESHEET_ERR = "NOT_STYLESHEET_ERR";
92     public static final String JavaDoc ELEMENT_PARSE_ERR = "ELEMENT_PARSE_ERR";
93     public static final String JavaDoc KEY_USE_ATTR_ERR = "KEY_USE_ATTR_ERR";
94     public static final String JavaDoc OUTPUT_VERSION_ERR = "OUTPUT_VERSION_ERR";
95     public static final String JavaDoc ILLEGAL_RELAT_OP_ERR = "ILLEGAL_RELAT_OP_ERR";
96     public static final String JavaDoc ATTRIBSET_UNDEF_ERR = "ATTRIBSET_UNDEF_ERR";
97     public static final String JavaDoc ATTR_VAL_TEMPLATE_ERR = "ATTR_VAL_TEMPLATE_ERR";
98     public static final String JavaDoc UNKNOWN_SIG_TYPE_ERR = "UNKNOWN_SIG_TYPE_ERR";
99     public static final String JavaDoc DATA_CONVERSION_ERR = "DATA_CONVERSION_ERR";
100
101     // JAXP/TrAX error messages
102
public static final String JavaDoc NO_TRANSLET_CLASS_ERR = "NO_TRANSLET_CLASS_ERR";
103     public static final String JavaDoc NO_MAIN_TRANSLET_ERR = "NO_MAIN_TRANSLET_ERR";
104     public static final String JavaDoc TRANSLET_CLASS_ERR = "TRANSLET_CLASS_ERR";
105     public static final String JavaDoc TRANSLET_OBJECT_ERR = "TRANSLET_OBJECT_ERR";
106     public static final String JavaDoc ERROR_LISTENER_NULL_ERR = "ERROR_LISTENER_NULL_ERR";
107     public static final String JavaDoc JAXP_UNKNOWN_SOURCE_ERR = "JAXP_UNKNOWN_SOURCE_ERR";
108     public static final String JavaDoc JAXP_NO_SOURCE_ERR = "JAXP_NO_SOURCE_ERR";
109     public static final String JavaDoc JAXP_COMPILE_ERR = "JAXP_COMPILE_ERR";
110     public static final String JavaDoc JAXP_INVALID_ATTR_ERR = "JAXP_INVALID_ATTR_ERR";
111     public static final String JavaDoc JAXP_SET_RESULT_ERR = "JAXP_SET_RESULT_ERR";
112     public static final String JavaDoc JAXP_NO_TRANSLET_ERR = "JAXP_NO_TRANSLET_ERR";
113     public static final String JavaDoc JAXP_NO_HANDLER_ERR = "JAXP_NO_HANDLER_ERR";
114     public static final String JavaDoc JAXP_NO_RESULT_ERR = "JAXP_NO_RESULT_ERR";
115     public static final String JavaDoc JAXP_UNKNOWN_PROP_ERR = "JAXP_UNKNOWN_PROP_ERR";
116     public static final String JavaDoc SAX2DOM_ADAPTER_ERR = "SAX2DOM_ADAPTER_ERR";
117     public static final String JavaDoc XSLTC_SOURCE_ERR = "XSLTC_SOURCE_ERR";
118     public static final String JavaDoc ER_RESULT_NULL = "ER_RESULT_NULL";
119     public static final String JavaDoc JAXP_INVALID_SET_PARAM_VALUE = "JAXP_INVALID_SET_PARAM_VALUE";
120     public static final String JavaDoc JAXP_SET_FEATURE_NULL_NAME = "JAXP_SET_FEATURE_NULL_NAME";
121     public static final String JavaDoc JAXP_GET_FEATURE_NULL_NAME = "JAXP_GET_FEATURE_NULL_NAME";
122     public static final String JavaDoc JAXP_UNSUPPORTED_FEATURE = "JAXP_UNSUPPORTED_FEATURE";
123
124     // Command-line error messages
125
public static final String JavaDoc COMPILE_STDIN_ERR = "COMPILE_STDIN_ERR";
126     public static final String JavaDoc COMPILE_USAGE_STR = "COMPILE_USAGE_STR";
127     public static final String JavaDoc TRANSFORM_USAGE_STR = "TRANSFORM_USAGE_STR";
128
129     // Recently added error messages
130
public static final String JavaDoc STRAY_SORT_ERR = "STRAY_SORT_ERR";
131     public static final String JavaDoc UNSUPPORTED_ENCODING = "UNSUPPORTED_ENCODING";
132     public static final String JavaDoc SYNTAX_ERR = "SYNTAX_ERR";
133     public static final String JavaDoc CONSTRUCTOR_NOT_FOUND = "CONSTRUCTOR_NOT_FOUND";
134     public static final String JavaDoc NO_JAVA_FUNCT_THIS_REF = "NO_JAVA_FUNCT_THIS_REF";
135     public static final String JavaDoc TYPE_CHECK_ERR = "TYPE_CHECK_ERR";
136     public static final String JavaDoc TYPE_CHECK_UNK_LOC_ERR = "TYPE_CHECK_UNK_LOC_ERR";
137     public static final String JavaDoc ILLEGAL_CMDLINE_OPTION_ERR = "ILLEGAL_CMDLINE_OPTION_ERR";
138     public static final String JavaDoc CMDLINE_OPT_MISSING_ARG_ERR = "CMDLINE_OPT_MISSING_ARG_ERR";
139     public static final String JavaDoc WARNING_PLUS_WRAPPED_MSG = "WARNING_PLUS_WRAPPED_MSG";
140     public static final String JavaDoc WARNING_MSG = "WARNING_MSG";
141     public static final String JavaDoc FATAL_ERR_PLUS_WRAPPED_MSG = "FATAL_ERR_PLUS_WRAPPED_MSG";
142     public static final String JavaDoc FATAL_ERR_MSG = "FATAL_ERR_MSG";
143     public static final String JavaDoc ERROR_PLUS_WRAPPED_MSG = "ERROR_PLUS_WRAPPED_MSG";
144     public static final String JavaDoc ERROR_MSG = "ERROR_MSG";
145     public static final String JavaDoc TRANSFORM_WITH_TRANSLET_STR = "TRANSFORM_WITH_TRANSLET_STR";
146     public static final String JavaDoc TRANSFORM_WITH_JAR_STR = "TRANSFORM_WITH_JAR_STR";
147     public static final String JavaDoc COULD_NOT_CREATE_TRANS_FACT = "COULD_NOT_CREATE_TRANS_FACT";
148     public static final String JavaDoc TRANSLET_NAME_JAVA_CONFLICT =
149                                                  "TRANSLET_NAME_JAVA_CONFLICT";
150     public static final String JavaDoc INVALID_QNAME_ERR = "INVALID_QNAME_ERR";
151     public static final String JavaDoc INVALID_NCNAME_ERR = "INVALID_NCNAME_ERR";
152     public static final String JavaDoc INVALID_METHOD_IN_OUTPUT = "INVALID_METHOD_IN_OUTPUT";
153                                                      
154     // All error messages are localized and are stored in resource bundles.
155
// This array and the following 4 strings are read from that bundle.
156
private static ResourceBundle JavaDoc _bundle;
157     
158     public final static String JavaDoc ERROR_MESSAGES_KEY = "ERROR_MESSAGES_KEY";
159     public final static String JavaDoc COMPILER_ERROR_KEY = "COMPILER_ERROR_KEY";
160     public final static String JavaDoc COMPILER_WARNING_KEY = "COMPILER_WARNING_KEY";
161     public final static String JavaDoc RUNTIME_ERROR_KEY = "RUNTIME_ERROR_KEY";
162
163     static {
164         _bundle = ResourceBundle.getBundle(
165                           "com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMessages",
166                           Locale.getDefault());
167     }
168
169     public ErrorMsg(String JavaDoc code) {
170     _code = code;
171     _line = 0;
172     }
173     
174     public ErrorMsg(Throwable JavaDoc e) {
175     _code = null;
176     _message = e.getMessage();
177     _line = 0;
178     }
179
180     public ErrorMsg(String JavaDoc message, int line) {
181     _code = null;
182     _message = message;
183     _line = line;
184     }
185
186     public ErrorMsg(String JavaDoc code, int line, Object JavaDoc param) {
187     _code = code;
188     _line = line;
189     _params = new Object JavaDoc[] { param };
190     }
191
192     public ErrorMsg(String JavaDoc code, Object JavaDoc param) {
193     this(code);
194     _params = new Object JavaDoc[1];
195     _params[0] = param;
196     }
197
198     public ErrorMsg(String JavaDoc code, Object JavaDoc param1, Object JavaDoc param2) {
199     this(code);
200     _params = new Object JavaDoc[2];
201     _params[0] = param1;
202     _params[1] = param2;
203     }
204
205     public ErrorMsg(String JavaDoc code, SyntaxTreeNode node) {
206     _code = code;
207     _url = getFileName(node);
208     _line = node.getLineNumber();
209     }
210
211     public ErrorMsg(String JavaDoc code, Object JavaDoc param1, SyntaxTreeNode node) {
212     _code = code;
213     _url = getFileName(node);
214     _line = node.getLineNumber();
215     _params = new Object JavaDoc[1];
216     _params[0] = param1;
217     }
218
219     public ErrorMsg(String JavaDoc code, Object JavaDoc param1, Object JavaDoc param2,
220             SyntaxTreeNode node) {
221     _code = code;
222     _url = getFileName(node);
223     _line = node.getLineNumber();
224     _params = new Object JavaDoc[2];
225     _params[0] = param1;
226     _params[1] = param2;
227     }
228
229     private String JavaDoc getFileName(SyntaxTreeNode node) {
230     Stylesheet stylesheet = node.getStylesheet();
231     if (stylesheet != null)
232         return stylesheet.getSystemId();
233     else
234         return null;
235     }
236
237     private String JavaDoc formatLine() {
238     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
239     if (_url != null) {
240         result.append(_url);
241         result.append(": ");
242     }
243     if (_line > 0) {
244         result.append("line ");
245         result.append(Integer.toString(_line));
246         result.append(": ");
247     }
248     return result.toString();
249     }
250     
251     /**
252      * This version of toString() uses the _params instance variable
253      * to format the message. If the <code>_code</code> is negative
254      * the use _message as the error string.
255      */

256     public String JavaDoc toString() {
257     String JavaDoc suffix = (_params == null) ?
258         (null != _code ? new String JavaDoc(getErrorMessage()) : _message)
259         : MessageFormat.format(getErrorMessage(), _params);
260     return formatLine() + suffix;
261     }
262     
263     public String JavaDoc toString(Object JavaDoc obj) {
264     Object JavaDoc params[] = new Object JavaDoc[1];
265     params[0] = obj.toString();
266     String JavaDoc suffix = MessageFormat.format(getErrorMessage(), params);
267     return formatLine() + suffix;
268     }
269     
270     public String JavaDoc toString(Object JavaDoc obj0, Object JavaDoc obj1) {
271     Object JavaDoc params[] = new Object JavaDoc[2];
272     params[0] = obj0.toString();
273     params[1] = obj1.toString();
274     String JavaDoc suffix = MessageFormat.format(getErrorMessage(), params);
275     return formatLine() + suffix;
276     }
277
278     /**
279      * Return an ErrorMessages string corresponding to the _code
280      * This function is temporary until the three special-cased keys
281      * below are moved into ErrorMessages
282      *
283      * @return ErrorMessages string
284      */

285     private String JavaDoc getErrorMessage() {
286       return _bundle.getString(_code);
287     }
288 }
289
290
Popular Tags