1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 0.7pre2 */
2
3 /**
4 * Redistribution and use of this software and associated documentation
5 * ("Software"), with or without modification, are permitted provided
6 * that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain copyright
9 * statements and notices. Redistributions must also contain a
10 * copy of this document.
11 *
12 * 2. Redistributions in binary form must reproduce the
13 * above copyright notice, this list of conditions and the
14 * following disclaimer in the documentation and/or other
15 * materials provided with the distribution.
16 *
17 * 3. The name "Exolab" must not be used to endorse or promote
18 * products derived from this Software without prior written
19 * permission of Intalio, Inc. For written permission,
20 * please contact info@exolab.org.
21 *
22 * 4. Products derived from this Software may not be called "Exolab"
23 * nor may "Exolab" appear in their names without prior written
24 * permission of Intalio, Inc. Exolab is a registered
25 * trademark of Intalio, Inc.
26 *
27 * 5. Due credit should be given to the Exolab Project
28 * (http://www.exolab.org/).
29 *
30 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
31 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
32 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
33 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
34 * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
41 * OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 * Copyright 2000 (C) Intalio Inc. All Rights Reserved.
44 *
45 * $Id$
46 */
47
48 package org.exolab.castor.xml.dtd.parser;
49
50 /**
51 * This Error is occurs if the Token Manager is unable to form next token
52 * and pass it to the parser.
53 * @author Generated automatically by <b>JavaCC</b>
54 * @version Version 0.7pre2
55 */
56 public class TokenMgrError extends Error {
57 /** SerialVersionUID */
58 private static final long serialVersionUID = 5390945290273323564L;
59
60 /*
61 * Ordinals for various reasons why an Error of this type can be thrown.
62 */
63
64 /**
65 * Lexical error occured.
66 */
67 static final int LEXICAL_ERROR = 0;
68
69 /**
70 * An attempt wass made to create a second instance of a static token manager.
71 */
72 static final int STATIC_LEXER_ERROR = 1;
73
74 /**
75 * Tried to change to an invalid lexical state.
76 */
77 static final int INVALID_LEXICAL_STATE = 2;
78
79 /**
80 * Detected (and bailed out of) an infinite loop in the token manager.
81 */
82 static final int LOOP_DETECTED = 3;
83
84 /**
85 * Indicates the reason why the exception is thrown. It will have
86 * one of the above 4 values.
87 */
88 int errorCode;
89
90 /**
91 * Replaces unprintable characters by their espaced (or unicode escaped)
92 * equivalents in the given string
93 */
94 protected static final String addEscapes(String str) {
95 StringBuffer retval = new StringBuffer();
96 char ch;
97 for (int i = 0; i < str.length(); i++) {
98 switch (str.charAt(i))
99 {
100 case 0 :
101 continue;
102 case '\b':
103 retval.append("\\b");
104 continue;
105 case '\t':
106 retval.append("\\t");
107 continue;
108 case '\n':
109 retval.append("\\n");
110 continue;
111 case '\f':
112 retval.append("\\f");
113 continue;
114 case '\r':
115 retval.append("\\r");
116 continue;
117 case '\"':
118 retval.append("\\\"");
119 continue;
120 case '\'':
121 retval.append("\\\'");
122 continue;
123 case '\\':
124 retval.append("\\\\");
125 continue;
126 default:
127 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
128 String s = "0000" + Integer.toString(ch, 16);
129 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
130 } else {
131 retval.append(ch);
132 }
133 continue;
134 }
135 }
136 return retval.toString();
137 }
138
139 /**
140 * Returns a detailed message for the Error when it is thrown by the
141 * token manager to indicate a lexical error.
142 * Parameters :
143 * EOFSeen : indicates if EOF caused the lexicl error
144 * curLexState : lexical state in which this error occured
145 * errorLine : line number when the error occured
146 * errorColumn : column number when the error occured
147 * errorAfter : prefix that was seen before this error occured
148 * curchar : the offending character
149 * Note: You can customize the lexical error message by modifying this method.
150 */
151 private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
152 return("Lexical error at line " +
153 errorLine + ", column " +
154 errorColumn + ". Encountered: " +
155 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
156 "after : \"" + addEscapes(errorAfter) + "\"");
157 }
158
159 /**
160 * You can also modify the body of this method to customize your error messages.
161 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
162 * of end-users concern, so you can return something like :
163 *
164 * "Internal Error : Please file a bug report .... "
165 *
166 * from this method for such cases in the release version of your parser.
167 */
168 public String getMessage() {
169 return super.getMessage();
170 }
171
172 /*
173 * Constructors of various flavors follow.
174 */
175
176 public TokenMgrError() {
177 }
178
179 public TokenMgrError(String message, int reason) {
180 super(message);
181 errorCode = reason;
182 }
183
184 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
185 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
186 }
187 }