001:/*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019:
020:/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 2.1 */
021:package org.openharmonise.commons.xml.parser;
022:
023:public class TokenMgrError extends Error {
024:
025: /*
026: * Ordinals for various reasons why an Error of this type can be thrown.
027: */
028:
029: /**
030: * Lexical error occured.
031: */
032: static final int LEXICAL_ERROR = 0;
033:
034: /**
035: * An attempt wass made to create a second instance of a static token manager.
036: */
037: static final int STATIC_LEXER_ERROR = 1;
038:
039: /**
040: * Tried to change to an invalid lexical state.
041: */
042: static final int INVALID_LEXICAL_STATE = 2;
043:
044: /**
045: * Detected (and bailed out of) an infinite loop in the token manager.
046: */
047: static final int LOOP_DETECTED = 3;
048:
049: /**
050: * Indicates the reason why the exception is thrown. It will have
051: * one of the above 4 values.
052: */
053: int errorCode;
054:
055: /**
056: * Replaces unprintable characters by their espaced (or unicode escaped)
057: * equivalents in the given string
058: */
059: protected static final String addEscapes(String str) {
060: StringBuffer retval = new StringBuffer();
061: char ch;
062: for (int i = 0; i < str.length(); i++) {
063: switch (str.charAt(i))
064: {
065: case 0 :
066: continue;
067: case '\b':
068: retval.append("\\b");
069: continue;
070: case '\t':
071: retval.append("\\t");
072: continue;
073: case '\n':
074: retval.append("\\n");
075: continue;
076: case '\f':
077: retval.append("\\f");
078: continue;
079: case '\r':
080: retval.append("\\r");
081: continue;
082: case '\"':
083: retval.append("\\\"");
084: continue;
085: case '\'':
086: retval.append("\\\'");
087: continue;
088: case '\\':
089: retval.append("\\\\");
090: continue;
091: default:
092: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
093: String s = "0000" + Integer.toString(ch, 16);
094: retval.append("\\u" + s.substring(s.length() - 4, s.length()));
095: } else {
096: retval.append(ch);
097: }
098: continue;
099: }
100: }
101: return retval.toString();
102: }
103:
104: /**
105: * Returns a detailed message for the Error when it is thrown by the
106: * token manager to indicate a lexical error.
107: * Parameters :
108: * EOFSeen : indicates if EOF caused the lexicl error
109: * curLexState : lexical state in which this error occured
110: * errorLine : line number when the error occured
111: * errorColumn : column number when the error occured
112: * errorAfter : prefix that was seen before this error occured
113: * curchar : the offending character
114: * Note: You can customize the lexical error message by modifying this method.
115: */
116: private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
117: return("Lexical error at line " +
118: errorLine + ", column " +
119: errorColumn + ". Encountered: " +
120: (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
121: "after : \"" + addEscapes(errorAfter) + "\"");
122: }
123:
124: /**
125: * You can also modify the body of this method to customize your error messages.
126: * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
127: * of end-users concern, so you can return something like :
128: *
129: * "Internal Error : Please file a bug report .... "
130: *
131: * from this method for such cases in the release version of your parser.
132: */
133: public String getMessage() {
134: return super .getMessage();
135: }
136:
137: /*
138: * Constructors of various flavors follow.
139: */
140:
141: public TokenMgrError() {
142: }
143:
144: public TokenMgrError(String message, int reason) {
145: super (message);
146: errorCode = reason;
147: }
148:
149: public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
150: this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
151: }
152:}
|