001:/*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
018:
019:package org.apache.harmony.jndi.provider.ldap.parser;
020:
021:public class TokenMgrError extends Error
022:{
023: /*
024: * Ordinals for various reasons why an Error of this type can be thrown.
025: */
026:
027: /**
028: * Lexical error occured.
029: */
030: static final int LEXICAL_ERROR = 0;
031:
032: /**
033: * An attempt wass made to create a second instance of a static token manager.
034: */
035: static final int STATIC_LEXER_ERROR = 1;
036:
037: /**
038: * Tried to change to an invalid lexical state.
039: */
040: static final int INVALID_LEXICAL_STATE = 2;
041:
042: /**
043: * Detected (and bailed out of) an infinite loop in the token manager.
044: */
045: static final int LOOP_DETECTED = 3;
046:
047: /**
048: * Indicates the reason why the exception is thrown. It will have
049: * one of the above 4 values.
050: */
051: int errorCode;
052:
053: /**
054: * Replaces unprintable characters by their espaced (or unicode escaped)
055: * equivalents in the given string
056: */
057: protected static final String addEscapes(String str) {
058: StringBuffer retval = new StringBuffer();
059: char ch;
060: for (int i = 0; i < str.length(); i++) {
061: switch (str.charAt(i))
062: {
063: case 0 :
064: continue;
065: case '\b':
066: retval.append("\\b");
067: continue;
068: case '\t':
069: retval.append("\\t");
070: continue;
071: case '\n':
072: retval.append("\\n");
073: continue;
074: case '\f':
075: retval.append("\\f");
076: continue;
077: case '\r':
078: retval.append("\\r");
079: continue;
080: case '\"':
081: retval.append("\\\"");
082: continue;
083: case '\'':
084: retval.append("\\\'");
085: continue;
086: case '\\':
087: retval.append("\\\\");
088: continue;
089: default:
090: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
091: String s = "0000" + Integer.toString(ch, 16);
092: retval.append("\\u" + s.substring(s.length() - 4, s.length()));
093: } else {
094: retval.append(ch);
095: }
096: continue;
097: }
098: }
099: return retval.toString();
100: }
101:
102: /**
103: * Returns a detailed message for the Error when it is thrown by the
104: * token manager to indicate a lexical error.
105: * Parameters :
106: * EOFSeen : indicates if EOF caused the lexicl error
107: * curLexState : lexical state in which this error occured
108: * errorLine : line number when the error occured
109: * errorColumn : column number when the error occured
110: * errorAfter : prefix that was seen before this error occured
111: * curchar : the offending character
112: * Note: You can customize the lexical error message by modifying this method.
113: */
114: protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
115: return("Lexical error at line " +
116: errorLine + ", column " +
117: errorColumn + ". Encountered: " +
118: (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
119: "after : \"" + addEscapes(errorAfter) + "\"");
120: }
121:
122: /**
123: * You can also modify the body of this method to customize your error messages.
124: * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
125: * of end-users concern, so you can return something like :
126: *
127: * "Internal Error : Please file a bug report .... "
128: *
129: * from this method for such cases in the release version of your parser.
130: */
131: public String getMessage() {
132: return super .getMessage();
133: }
134:
135: /*
136: * Constructors of various flavors follow.
137: */
138:
139: public TokenMgrError() {
140: }
141:
142: public TokenMgrError(String message, int reason) {
143: super (message);
144: errorCode = reason;
145: }
146:
147: public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
148: this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
149: }
150:}
|