1 /*
2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
27 package com.sun.xml.internal.xsom.impl.scd;
28 
29 public class TokenMgrError extends Error
30 {
31    /*
32     * Ordinals for various reasons why an Error of this type can be thrown.
33     */
34 
35    /**
36     * Lexical error occured.
37     */
38    static final int LEXICAL_ERROR = 0;
39 
40    /**
41     * An attempt wass made to create a second instance of a static token manager.
42     */
43    static final int STATIC_LEXER_ERROR = 1;
44 
45    /**
46     * Tried to change to an invalid lexical state.
47     */
48    static final int INVALID_LEXICAL_STATE = 2;
49 
50    /**
51     * Detected (and bailed out of) an infinite loop in the token manager.
52     */
53    static final int LOOP_DETECTED = 3;
54 
55    /**
56     * Indicates the reason why the exception is thrown. It will have
57     * one of the above 4 values.
58     */
59    int errorCode;
60 
61    /**
62     * Replaces unprintable characters by their espaced (or unicode escaped)
63     * equivalents in the given string
64     */
addEscapes(String str)65    protected static final String addEscapes(String str) {
66       StringBuffer retval = new StringBuffer();
67       char ch;
68       for (int i = 0; i < str.length(); i++) {
69         switch (str.charAt(i))
70         {
71            case 0 :
72               continue;
73            case '\b':
74               retval.append("\\b");
75               continue;
76            case '\t':
77               retval.append("\\t");
78               continue;
79            case '\n':
80               retval.append("\\n");
81               continue;
82            case '\f':
83               retval.append("\\f");
84               continue;
85            case '\r':
86               retval.append("\\r");
87               continue;
88            case '\"':
89               retval.append("\\\"");
90               continue;
91            case '\'':
92               retval.append("\\\'");
93               continue;
94            case '\\':
95               retval.append("\\\\");
96               continue;
97            default:
98               if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
99                  String s = "0000" + Integer.toString(ch, 16);
100                  retval.append("\\u" + s.substring(s.length() - 4, s.length()));
101               } else {
102                  retval.append(ch);
103               }
104               continue;
105         }
106       }
107       return retval.toString();
108    }
109 
110    /**
111     * Returns a detailed message for the Error when it is thrown by the
112     * token manager to indicate a lexical error.
113     * Parameters :
114     *    EOFSeen     : indicates if EOF caused the lexicl error
115     *    curLexState : lexical state in which this error occured
116     *    errorLine   : line number when the error occured
117     *    errorColumn : column number when the error occured
118     *    errorAfter  : prefix that was seen before this error occured
119     *    curchar     : the offending character
120     * Note: You can customize the lexical error message by modifying this method.
121     */
LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar)122    protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
123       return("Lexical error at line " +
124            errorLine + ", column " +
125            errorColumn + ".  Encountered: " +
126            (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
127            "after : \"" + addEscapes(errorAfter) + "\"");
128    }
129 
130    /**
131     * You can also modify the body of this method to customize your error messages.
132     * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
133     * of end-users concern, so you can return something like :
134     *
135     *     "Internal Error : Please file a bug report .... "
136     *
137     * from this method for such cases in the release version of your parser.
138     */
getMessage()139    public String getMessage() {
140       return super.getMessage();
141    }
142 
143    /*
144     * Constructors of various flavors follow.
145     */
146 
TokenMgrError()147    public TokenMgrError() {
148    }
149 
TokenMgrError(String message, int reason)150    public TokenMgrError(String message, int reason) {
151       super(message);
152       errorCode = reason;
153    }
154 
TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason)155    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
156       this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
157    }
158 }
159