001:
002:/*
003: * Copyright (c) 1998 - 2005 Versant Corporation
004: * All rights reserved. This program and the accompanying materials
005: * are made available under the terms of the Eclipse Public License v1.0
006: * which accompanies this distribution, and is available at
007: * http://www.eclipse.org/legal/epl-v10.html
008: *
009: * Contributors:
010: * Versant Corporation - initial API and implementation
011: */
012:/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
013:package com.versant.core.ejb.query;
014:
015:public class TokenMgrError extends Error
016:{
017: /*
018: * Ordinals for various reasons why an Error of this type can be thrown.
019: */
020:
021: /**
022: * Lexical error occured.
023: */
024: static final int LEXICAL_ERROR = 0;
025:
026: /**
027: * An attempt wass made to create a second instance of a static token manager.
028: */
029: static final int STATIC_LEXER_ERROR = 1;
030:
031: /**
032: * Tried to change to an invalid lexical state.
033: */
034: static final int INVALID_LEXICAL_STATE = 2;
035:
036: /**
037: * Detected (and bailed out of) an infinite loop in the token manager.
038: */
039: static final int LOOP_DETECTED = 3;
040:
041: /**
042: * Indicates the reason why the exception is thrown. It will have
043: * one of the above 4 values.
044: */
045: int errorCode;
046:
047: /**
048: * Replaces unprintable characters by their espaced (or unicode escaped)
049: * equivalents in the given string
050: */
051: protected static final String addEscapes(String str) {
052: StringBuffer retval = new StringBuffer();
053: char ch;
054: for (int i = 0; i < str.length(); i++) {
055: switch (str.charAt(i))
056: {
057: case 0 :
058: continue;
059: case '\b':
060: retval.append("\\b");
061: continue;
062: case '\t':
063: retval.append("\\t");
064: continue;
065: case '\n':
066: retval.append("\\n");
067: continue;
068: case '\f':
069: retval.append("\\f");
070: continue;
071: case '\r':
072: retval.append("\\r");
073: continue;
074: case '\"':
075: retval.append("\\\"");
076: continue;
077: case '\'':
078: retval.append("\\\'");
079: continue;
080: case '\\':
081: retval.append("\\\\");
082: continue;
083: default:
084: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
085: String s = "0000" + Integer.toString(ch, 16);
086: retval.append("\\u" + s.substring(s.length() - 4, s.length()));
087: } else {
088: retval.append(ch);
089: }
090: continue;
091: }
092: }
093: return retval.toString();
094: }
095:
096: /**
097: * Returns a detailed message for the Error when it is thrown by the
098: * token manager to indicate a lexical error.
099: * 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 LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String 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 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 message, int reason) {
137: super (message);
138: errorCode = reason;
139: }
140:
141: public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
142: this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
143: }
144:}
|