KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > lang > jpath > expression > TokenMgrError


1 /*
2  * Copyright 1999,2004 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
17 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 0.7pre2 */
18 package org.apache.taglibs.standard.lang.jpath.expression;
19
20 public class TokenMgrError extends Error JavaDoc
21 {
22    /*
23     * Ordinals for various reasons why an Error of this type can be thrown.
24     */

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

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

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

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

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

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

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

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

130    public String JavaDoc getMessage() {
131       return super.getMessage();
132    }
133
134    /*
135     * Constructors of various flavors follow.
136     */

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