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