KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jexl > parser > TokenMgrError


1 /*
2  * Copyright 2002-2006 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 2.1 */
17 package org.apache.commons.jexl.parser;
18
19 public class TokenMgrError extends Error JavaDoc {
20     /** serialization version id jdk13 generated. */
21     static final long serialVersionUID = 2843513002462329650L;
22
23     /*
24      * Ordinals for various reasons why an Error of this type can be thrown.
25      */

26
27     /**
28      * Lexical error occured.
29      */

30     static final int LEXICAL_ERROR = 0;
31
32     /**
33      * An attempt wass made to create a second instance of a static token
34      * manager.
35      */

36     static final int STATIC_LEXER_ERROR = 1;
37
38     /**
39      * Tried to change to an invalid lexical state.
40      */

41     static final int INVALID_LEXICAL_STATE = 2;
42
43     /**
44      * Detected (and bailed out of) an infinite loop in the token manager.
45      */

46     static final int LOOP_DETECTED = 3;
47
48     /**
49      * Indicates the reason why the exception is thrown. It will have one of the
50      * above 4 values.
51      */

52     int errorCode;
53
54     /**
55      * Replaces unprintable characters by their espaced (or unicode escaped)
56      * equivalents in the given string
57      */

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

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

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

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