KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > query > TokenMgrError


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
13 package com.versant.core.jdo.query;
14
15 public class TokenMgrError extends Error JavaDoc
16 {
17    /*
18     * Ordinals for various reasons why an Error of this type can be thrown.
19     */

20
21    /**
22     * Lexical error occured.
23     */

24    static final int LEXICAL_ERROR = 0;
25
26    /**
27     * An attempt wass made to create a second instance of a static token manager.
28     */

29    static final int STATIC_LEXER_ERROR = 1;
30
31    /**
32     * Tried to change to an invalid lexical state.
33     */

34    static final int INVALID_LEXICAL_STATE = 2;
35
36    /**
37     * Detected (and bailed out of) an infinite loop in the token manager.
38     */

39    static final int LOOP_DETECTED = 3;
40
41    /**
42     * Indicates the reason why the exception is thrown. It will have
43     * one of the above 4 values.
44     */

45    int errorCode;
46
47    /**
48     * Replaces unprintable characters by their espaced (or unicode escaped)
49     * equivalents in the given string
50     */

51    protected static final String JavaDoc addEscapes(String JavaDoc str) {
52       StringBuffer JavaDoc retval = new StringBuffer JavaDoc();
53       char ch;
54       for (int i = 0; i < str.length(); i++) {
55         switch (str.charAt(i))
56         {
57            case 0 :
58               continue;
59            case '\b':
60               retval.append("\\b");
61               continue;
62            case '\t':
63               retval.append("\\t");
64               continue;
65            case '\n':
66               retval.append("\\n");
67               continue;
68            case '\f':
69               retval.append("\\f");
70               continue;
71            case '\r':
72               retval.append("\\r");
73               continue;
74            case '\"':
75               retval.append("\\\"");
76               continue;
77            case '\'':
78               retval.append("\\\'");
79               continue;
80            case '\\':
81               retval.append("\\\\");
82               continue;
83            default:
84               if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
85                  String JavaDoc s = "0000" + Integer.toString(ch, 16);
86                  retval.append("\\u" + s.substring(s.length() - 4, s.length()));
87               } else {
88                  retval.append(ch);
89               }
90               continue;
91         }
92       }
93       return retval.toString();
94    }
95
96    /**
97     * Returns a detailed message for the Error when it is thrown by the
98     * token manager to indicate a lexical error.
99     * Parameters :
100     * EOFSeen : indicates if EOF caused the lexicl error
101     * curLexState : lexical state in which this error occured
102     * errorLine : line number when the error occured
103     * errorColumn : column number when the error occured
104     * errorAfter : prefix that was seen before this error occured
105     * curchar : the offending character
106     * Note: You can customize the lexical error message by modifying this method.
107     */

108    protected static String JavaDoc LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar) {
109       return("Lexical error at line " +
110            errorLine + ", column " +
111            errorColumn + ". Encountered: " +
112            (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
113            "after : \"" + addEscapes(errorAfter) + "\"");
114    }
115
116    /**
117     * You can also modify the body of this method to customize your error messages.
118     * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
119     * of end-users concern, so you can return something like :
120     *
121     * "Internal Error : Please file a bug report .... "
122     *
123     * from this method for such cases in the release version of your parser.
124     */

125    public String JavaDoc getMessage() {
126       return super.getMessage();
127    }
128
129    /*
130     * Constructors of various flavors follow.
131     */

132
133    public TokenMgrError() {
134    }
135
136    public TokenMgrError(String JavaDoc message, int reason) {
137       super(message);
138       errorCode = reason;
139    }
140
141    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String JavaDoc errorAfter, char curChar, int reason) {
142       this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
143    }
144 }
145
Popular Tags