1 16 19 20 package org.apache.xalan.xsltc.compiler.util; 21 22 import java.text.MessageFormat ; 23 import java.util.Locale ; 24 import java.util.ResourceBundle ; 25 26 import org.apache.xalan.xsltc.compiler.Stylesheet; 27 import org.apache.xalan.xsltc.compiler.SyntaxTreeNode; 28 29 36 public final class ErrorMsg { 37 38 private String _code; 39 private int _line; 40 private String _message = null; 41 private String _url = null; 42 Object [] _params = null; 43 44 public static final String MULTIPLE_STYLESHEET_ERR = "MULTIPLE_STYLESHEET_ERR"; 46 public static final String TEMPLATE_REDEF_ERR = "TEMPLATE_REDEF_ERR"; 47 public static final String TEMPLATE_UNDEF_ERR = "TEMPLATE_UNDEF_ERR"; 48 public static final String VARIABLE_REDEF_ERR = "VARIABLE_REDEF_ERR"; 49 public static final String VARIABLE_UNDEF_ERR = "VARIABLE_UNDEF_ERR"; 50 public static final String CLASS_NOT_FOUND_ERR = "CLASS_NOT_FOUND_ERR"; 51 public static final String METHOD_NOT_FOUND_ERR = "METHOD_NOT_FOUND_ERR"; 52 public static final String ARGUMENT_CONVERSION_ERR = "ARGUMENT_CONVERSION_ERR"; 53 public static final String FILE_NOT_FOUND_ERR = "FILE_NOT_FOUND_ERR"; 54 public static final String INVALID_URI_ERR = "INVALID_URI_ERR"; 55 public static final String FILE_ACCESS_ERR = "FILE_ACCESS_ERR"; 56 public static final String MISSING_ROOT_ERR = "MISSING_ROOT_ERR"; 57 public static final String NAMESPACE_UNDEF_ERR = "NAMESPACE_UNDEF_ERR"; 58 public static final String FUNCTION_RESOLVE_ERR = "FUNCTION_RESOLVE_ERR"; 59 public static final String NEED_LITERAL_ERR = "NEED_LITERAL_ERR"; 60 public static final String XPATH_PARSER_ERR = "XPATH_PARSER_ERR"; 61 public static final String REQUIRED_ATTR_ERR = "REQUIRED_ATTR_ERR"; 62 public static final String ILLEGAL_CHAR_ERR = "ILLEGAL_CHAR_ERR"; 63 public static final String ILLEGAL_PI_ERR = "ILLEGAL_PI_ERR"; 64 public static final String STRAY_ATTRIBUTE_ERR = "STRAY_ATTRIBUTE_ERR"; 65 public static final String ILLEGAL_ATTRIBUTE_ERR = "ILLEGAL_ATTRIBUTE_ERR"; 66 public static final String CIRCULAR_INCLUDE_ERR = "CIRCULAR_INCLUDE_ERR"; 67 public static final String RESULT_TREE_SORT_ERR = "RESULT_TREE_SORT_ERR"; 68 public static final String SYMBOLS_REDEF_ERR = "SYMBOLS_REDEF_ERR"; 69 public static final String XSL_VERSION_ERR = "XSL_VERSION_ERR"; 70 public static final String CIRCULAR_VARIABLE_ERR = "CIRCULAR_VARIABLE_ERR"; 71 public static final String ILLEGAL_BINARY_OP_ERR = "ILLEGAL_BINARY_OP_ERR"; 72 public static final String ILLEGAL_ARG_ERR = "ILLEGAL_ARG_ERR"; 73 public static final String DOCUMENT_ARG_ERR = "DOCUMENT_ARG_ERR"; 74 public static final String MISSING_WHEN_ERR = "MISSING_WHEN_ERR"; 75 public static final String MULTIPLE_OTHERWISE_ERR = "MULTIPLE_OTHERWISE_ERR"; 76 public static final String STRAY_OTHERWISE_ERR = "STRAY_OTHERWISE_ERR"; 77 public static final String STRAY_WHEN_ERR = "STRAY_WHEN_ERR"; 78 public static final String WHEN_ELEMENT_ERR = "WHEN_ELEMENT_ERR"; 79 public static final String UNNAMED_ATTRIBSET_ERR = "UNNAMED_ATTRIBSET_ERR"; 80 public static final String ILLEGAL_CHILD_ERR = "ILLEGAL_CHILD_ERR"; 81 public static final String ILLEGAL_ELEM_NAME_ERR = "ILLEGAL_ELEM_NAME_ERR"; 82 public static final String ILLEGAL_ATTR_NAME_ERR = "ILLEGAL_ATTR_NAME_ERR"; 83 public static final String ILLEGAL_TEXT_NODE_ERR = "ILLEGAL_TEXT_NODE_ERR"; 84 public static final String SAX_PARSER_CONFIG_ERR = "SAX_PARSER_CONFIG_ERR"; 85 public static final String INTERNAL_ERR = "INTERNAL_ERR"; 86 public static final String UNSUPPORTED_XSL_ERR = "UNSUPPORTED_XSL_ERR"; 87 public static final String UNSUPPORTED_EXT_ERR = "UNSUPPORTED_EXT_ERR"; 88 public static final String MISSING_XSLT_URI_ERR = "MISSING_XSLT_URI_ERR"; 89 public static final String MISSING_XSLT_TARGET_ERR = "MISSING_XSLT_TARGET_ERR"; 90 public static final String NOT_IMPLEMENTED_ERR = "NOT_IMPLEMENTED_ERR"; 91 public static final String NOT_STYLESHEET_ERR = "NOT_STYLESHEET_ERR"; 92 public static final String ELEMENT_PARSE_ERR = "ELEMENT_PARSE_ERR"; 93 public static final String KEY_USE_ATTR_ERR = "KEY_USE_ATTR_ERR"; 94 public static final String OUTPUT_VERSION_ERR = "OUTPUT_VERSION_ERR"; 95 public static final String ILLEGAL_RELAT_OP_ERR = "ILLEGAL_RELAT_OP_ERR"; 96 public static final String ATTRIBSET_UNDEF_ERR = "ATTRIBSET_UNDEF_ERR"; 97 public static final String ATTR_VAL_TEMPLATE_ERR = "ATTR_VAL_TEMPLATE_ERR"; 98 public static final String UNKNOWN_SIG_TYPE_ERR = "UNKNOWN_SIG_TYPE_ERR"; 99 public static final String DATA_CONVERSION_ERR = "DATA_CONVERSION_ERR"; 100 101 public static final String NO_TRANSLET_CLASS_ERR = "NO_TRANSLET_CLASS_ERR"; 103 public static final String NO_MAIN_TRANSLET_ERR = "NO_MAIN_TRANSLET_ERR"; 104 public static final String TRANSLET_CLASS_ERR = "TRANSLET_CLASS_ERR"; 105 public static final String TRANSLET_OBJECT_ERR = "TRANSLET_OBJECT_ERR"; 106 public static final String ERROR_LISTENER_NULL_ERR = "ERROR_LISTENER_NULL_ERR"; 107 public static final String JAXP_UNKNOWN_SOURCE_ERR = "JAXP_UNKNOWN_SOURCE_ERR"; 108 public static final String JAXP_NO_SOURCE_ERR = "JAXP_NO_SOURCE_ERR"; 109 public static final String JAXP_COMPILE_ERR = "JAXP_COMPILE_ERR"; 110 public static final String JAXP_INVALID_ATTR_ERR = "JAXP_INVALID_ATTR_ERR"; 111 public static final String JAXP_SET_RESULT_ERR = "JAXP_SET_RESULT_ERR"; 112 public static final String JAXP_NO_TRANSLET_ERR = "JAXP_NO_TRANSLET_ERR"; 113 public static final String JAXP_NO_HANDLER_ERR = "JAXP_NO_HANDLER_ERR"; 114 public static final String JAXP_NO_RESULT_ERR = "JAXP_NO_RESULT_ERR"; 115 public static final String JAXP_UNKNOWN_PROP_ERR = "JAXP_UNKNOWN_PROP_ERR"; 116 public static final String SAX2DOM_ADAPTER_ERR = "SAX2DOM_ADAPTER_ERR"; 117 public static final String XSLTC_SOURCE_ERR = "XSLTC_SOURCE_ERR"; 118 public static final String ER_RESULT_NULL = "ER_RESULT_NULL"; 119 public static final String JAXP_INVALID_SET_PARAM_VALUE = "JAXP_INVALID_SET_PARAM_VALUE"; 120 121 public static final String COMPILE_STDIN_ERR = "COMPILE_STDIN_ERR"; 123 public static final String COMPILE_USAGE_STR = "COMPILE_USAGE_STR"; 124 public static final String TRANSFORM_USAGE_STR = "TRANSFORM_USAGE_STR"; 125 126 public static final String STRAY_SORT_ERR = "STRAY_SORT_ERR"; 128 public static final String UNSUPPORTED_ENCODING = "UNSUPPORTED_ENCODING"; 129 public static final String SYNTAX_ERR = "SYNTAX_ERR"; 130 public static final String CONSTRUCTOR_NOT_FOUND = "CONSTRUCTOR_NOT_FOUND"; 131 public static final String NO_JAVA_FUNCT_THIS_REF = "NO_JAVA_FUNCT_THIS_REF"; 132 public static final String TYPE_CHECK_ERR = "TYPE_CHECK_ERR"; 133 public static final String TYPE_CHECK_UNK_LOC_ERR = "TYPE_CHECK_UNK_LOC_ERR"; 134 public static final String ILLEGAL_CMDLINE_OPTION_ERR = "ILLEGAL_CMDLINE_OPTION_ERR"; 135 public static final String CMDLINE_OPT_MISSING_ARG_ERR = "CMDLINE_OPT_MISSING_ARG_ERR"; 136 public static final String WARNING_PLUS_WRAPPED_MSG = "WARNING_PLUS_WRAPPED_MSG"; 137 public static final String WARNING_MSG = "WARNING_MSG"; 138 public static final String FATAL_ERR_PLUS_WRAPPED_MSG = "FATAL_ERR_PLUS_WRAPPED_MSG"; 139 public static final String FATAL_ERR_MSG = "FATAL_ERR_MSG"; 140 public static final String ERROR_PLUS_WRAPPED_MSG = "ERROR_PLUS_WRAPPED_MSG"; 141 public static final String ERROR_MSG = "ERROR_MSG"; 142 public static final String TRANSFORM_WITH_TRANSLET_STR = "TRANSFORM_WITH_TRANSLET_STR"; 143 public static final String TRANSFORM_WITH_JAR_STR = "TRANSFORM_WITH_JAR_STR"; 144 public static final String COULD_NOT_CREATE_TRANS_FACT = "COULD_NOT_CREATE_TRANS_FACT"; 145 public static final String TRANSLET_NAME_JAVA_CONFLICT = 146 "TRANSLET_NAME_JAVA_CONFLICT"; 147 public static final String INVALID_QNAME_ERR = "INVALID_QNAME_ERR"; 148 public static final String INVALID_NCNAME_ERR = "INVALID_NCNAME_ERR"; 149 public static final String INVALID_METHOD_IN_OUTPUT = "INVALID_METHOD_IN_OUTPUT"; 150 151 private static ResourceBundle _bundle; 154 155 public final static String ERROR_MESSAGES_KEY = "ERROR_MESSAGES_KEY"; 156 public final static String COMPILER_ERROR_KEY = "COMPILER_ERROR_KEY"; 157 public final static String COMPILER_WARNING_KEY = "COMPILER_WARNING_KEY"; 158 public final static String 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 code) { 167 _code = code; 168 _line = 0; 169 } 170 171 public ErrorMsg(Throwable e) { 172 _code = null; 173 _message = e.getMessage(); 174 _line = 0; 175 } 176 177 public ErrorMsg(String message, int line) { 178 _code = null; 179 _message = message; 180 _line = line; 181 } 182 183 public ErrorMsg(String code, int line, Object param) { 184 _code = code; 185 _line = line; 186 _params = new Object [] { param }; 187 } 188 189 public ErrorMsg(String code, Object param) { 190 this(code); 191 _params = new Object [1]; 192 _params[0] = param; 193 } 194 195 public ErrorMsg(String code, Object param1, Object param2) { 196 this(code); 197 _params = new Object [2]; 198 _params[0] = param1; 199 _params[1] = param2; 200 } 201 202 public ErrorMsg(String code, SyntaxTreeNode node) { 203 _code = code; 204 _url = getFileName(node); 205 _line = node.getLineNumber(); 206 } 207 208 public ErrorMsg(String code, Object param1, SyntaxTreeNode node) { 209 _code = code; 210 _url = getFileName(node); 211 _line = node.getLineNumber(); 212 _params = new Object [1]; 213 _params[0] = param1; 214 } 215 216 public ErrorMsg(String code, Object param1, Object param2, 217 SyntaxTreeNode node) { 218 _code = code; 219 _url = getFileName(node); 220 _line = node.getLineNumber(); 221 _params = new Object [2]; 222 _params[0] = param1; 223 _params[1] = param2; 224 } 225 226 private String 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 formatLine() { 235 StringBuffer result = new StringBuffer (); 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 253 public String toString() { 254 String suffix = (_params == null) ? 255 (null != _code ? new String (getErrorMessage()) : _message) 256 : MessageFormat.format(getErrorMessage(), _params); 257 return formatLine() + suffix; 258 } 259 260 public String toString(Object obj) { 261 Object params[] = new Object [1]; 262 params[0] = obj.toString(); 263 String suffix = MessageFormat.format(getErrorMessage(), params); 264 return formatLine() + suffix; 265 } 266 267 public String toString(Object obj0, Object obj1) { 268 Object params[] = new Object [2]; 269 params[0] = obj0.toString(); 270 params[1] = obj1.toString(); 271 String suffix = MessageFormat.format(getErrorMessage(), params); 272 return formatLine() + suffix; 273 } 274 275 282 private String getErrorMessage() { 283 return _bundle.getString(_code); 284 } 285 } 286 287 | Popular Tags |