KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > 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.25 2004/02/24 03:55:48 zongaro Exp $
18  */

19
20 package org.apache.xalan.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 org.apache.xalan.xsltc.compiler.Stylesheet;
27 import org.apache.xalan.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
121     // Command-line error messages
122
public static final String JavaDoc COMPILE_STDIN_ERR = "COMPILE_STDIN_ERR";
123     public static final String JavaDoc COMPILE_USAGE_STR = "COMPILE_USAGE_STR";
124     public static final String JavaDoc TRANSFORM_USAGE_STR = "TRANSFORM_USAGE_STR";
125
126     // Recently added error messages
127
public static final String JavaDoc STRAY_SORT_ERR = "STRAY_SORT_ERR";
128     public static final String JavaDoc UNSUPPORTED_ENCODING = "UNSUPPORTED_ENCODING";
129     public static final String JavaDoc SYNTAX_ERR = "SYNTAX_ERR";
130     public static final String JavaDoc CONSTRUCTOR_NOT_FOUND = "CONSTRUCTOR_NOT_FOUND";
131     public static final String JavaDoc NO_JAVA_FUNCT_THIS_REF = "NO_JAVA_FUNCT_THIS_REF";
132     public static final String JavaDoc TYPE_CHECK_ERR = "TYPE_CHECK_ERR";
133     public static final String JavaDoc TYPE_CHECK_UNK_LOC_ERR = "TYPE_CHECK_UNK_LOC_ERR";
134     public static final String JavaDoc ILLEGAL_CMDLINE_OPTION_ERR = "ILLEGAL_CMDLINE_OPTION_ERR";
135     public static final String JavaDoc CMDLINE_OPT_MISSING_ARG_ERR = "CMDLINE_OPT_MISSING_ARG_ERR";
136     public static final String JavaDoc WARNING_PLUS_WRAPPED_MSG = "WARNING_PLUS_WRAPPED_MSG";
137     public static final String JavaDoc WARNING_MSG = "WARNING_MSG";
138     public static final String JavaDoc FATAL_ERR_PLUS_WRAPPED_MSG = "FATAL_ERR_PLUS_WRAPPED_MSG";
139     public static final String JavaDoc FATAL_ERR_MSG = "FATAL_ERR_MSG";
140     public static final String JavaDoc ERROR_PLUS_WRAPPED_MSG = "ERROR_PLUS_WRAPPED_MSG";
141     public static final String JavaDoc ERROR_MSG = "ERROR_MSG";
142     public static final String JavaDoc TRANSFORM_WITH_TRANSLET_STR = "TRANSFORM_WITH_TRANSLET_STR";
143     public static final String JavaDoc TRANSFORM_WITH_JAR_STR = "TRANSFORM_WITH_JAR_STR";
144     public static final String JavaDoc COULD_NOT_CREATE_TRANS_FACT = "COULD_NOT_CREATE_TRANS_FACT";
145     public static final String JavaDoc TRANSLET_NAME_JAVA_CONFLICT =
146                                                  "TRANSLET_NAME_JAVA_CONFLICT";
147     public static final String JavaDoc INVALID_QNAME_ERR = "INVALID_QNAME_ERR";
148     public static final String JavaDoc INVALID_NCNAME_ERR = "INVALID_NCNAME_ERR";
149     public static final String JavaDoc INVALID_METHOD_IN_OUTPUT = "INVALID_METHOD_IN_OUTPUT";
150                                                      
151     // All error messages are localized and are stored in resource bundles.
152
// This array and the following 4 strings are read from that bundle.
153
private static ResourceBundle JavaDoc _bundle;
154     
155     public final static String JavaDoc ERROR_MESSAGES_KEY = "ERROR_MESSAGES_KEY";
156     public final static String JavaDoc COMPILER_ERROR_KEY = "COMPILER_ERROR_KEY";
157     public final static String JavaDoc COMPILER_WARNING_KEY = "COMPILER_WARNING_KEY";
158     public final static String JavaDoc RUNTIME_ERROR_KEY = "RUNTIME_ERROR_KEY";
159
160     static {
161         _bundle = ResourceBundle.getBundle(
162                           "org.apache.xalan.xsltc.compiler.util.ErrorMessages",
163                           Locale.getDefault());
164     }
165
166     public ErrorMsg(String JavaDoc code) {
167     _code = code;
168     _line = 0;
169     }
170     
171     public ErrorMsg(Throwable JavaDoc e) {
172     _code = null;
173     _message = e.getMessage();
174     _line = 0;
175     }
176
177     public ErrorMsg(String JavaDoc message, int line) {
178     _code = null;
179     _message = message;
180     _line = line;
181     }
182
183     public ErrorMsg(String JavaDoc code, int line, Object JavaDoc param) {
184     _code = code;
185     _line = line;
186     _params = new Object JavaDoc[] { param };
187     }
188
189     public ErrorMsg(String JavaDoc code, Object JavaDoc param) {
190     this(code);
191     _params = new Object JavaDoc[1];
192     _params[0] = param;
193     }
194
195     public ErrorMsg(String JavaDoc code, Object JavaDoc param1, Object JavaDoc param2) {
196     this(code);
197     _params = new Object JavaDoc[2];
198     _params[0] = param1;
199     _params[1] = param2;
200     }
201
202     public ErrorMsg(String JavaDoc code, SyntaxTreeNode node) {
203     _code = code;
204     _url = getFileName(node);
205     _line = node.getLineNumber();
206     }
207
208     public ErrorMsg(String JavaDoc code, Object JavaDoc param1, SyntaxTreeNode node) {
209     _code = code;
210     _url = getFileName(node);
211     _line = node.getLineNumber();
212     _params = new Object JavaDoc[1];
213     _params[0] = param1;
214     }
215
216     public ErrorMsg(String JavaDoc code, Object JavaDoc param1, Object JavaDoc param2,
217             SyntaxTreeNode node) {
218     _code = code;
219     _url = getFileName(node);
220     _line = node.getLineNumber();
221     _params = new Object JavaDoc[2];
222     _params[0] = param1;
223     _params[1] = param2;
224     }
225
226     private String JavaDoc getFileName(SyntaxTreeNode node) {
227     Stylesheet stylesheet = node.getStylesheet();
228     if (stylesheet != null)
229         return stylesheet.getSystemId();
230     else
231         return null;
232     }
233
234     private String JavaDoc formatLine() {
235     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
236     if (_url != null) {
237         result.append(_url);
238         result.append(": ");
239     }
240     if (_line > 0) {
241         result.append("line ");
242         result.append(Integer.toString(_line));
243         result.append(": ");
244     }
245     return result.toString();
246     }
247     
248     /**
249      * This version of toString() uses the _params instance variable
250      * to format the message. If the <code>_code</code> is negative
251      * the use _message as the error string.
252      */

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

282     private String JavaDoc getErrorMessage() {
283       return _bundle.getString(_code);
284     }
285 }
286
287
Popular Tags