001:/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 2.1 */
002:/*
003: * $Id : $
004: * $Source : $
005: * $Log: TokenMgrError.java,v $
006: * Revision 1.3 2005/11/30 11:27:26 ss150821
007: * 6356996 - Srap Code base needs to save files in the unix file format and not windows
008: *
009: * Revision 1.2 2005/02/23 09:03:11 ss150821
010: * RFE 6223490 - SRA Should use JDK based logging
011: *
012: * Revision 1.1 2003/04/15 05:22:11 mm132998
013: * WebDAV support
014: *
015: *
016: */
017:package com.sun.portal.rproxy.connectionhandler.webdav;
018:
019:public class TokenMgrError extends Error {
020: /*
021: * Ordinals for various reasons why an Error of this type can be thrown.
022: */
023:
024: /**
025: * Lexical error occured.
026: */
027: static final int LEXICAL_ERROR = 0;
028:
029: /**
030: * An attempt wass made to create a second instance of a static token
031: * manager.
032: */
033: static final int STATIC_LEXER_ERROR = 1;
034:
035: /**
036: * Tried to change to an invalid lexical state.
037: */
038: static final int INVALID_LEXICAL_STATE = 2;
039:
040: /**
041: * Detected (and bailed out of) an infinite loop in the token manager.
042: */
043: static final int LOOP_DETECTED = 3;
044:
045: /**
046: * Indicates the reason why the exception is thrown. It will have one of the
047: * above 4 values.
048: */
049: int errorCode;
050:
051: /**
052: * Replaces unprintable characters by their espaced (or unicode escaped)
053: * equivalents in the given string
054: */
055: protected static final String addEscapes(String str) {
056: StringBuffer retval = new StringBuffer();
057: char ch;
058: for (int i = 0; i < str.length(); i++) {
059: switch (str.charAt(i)) {
060: case 0:
061: continue;
062: case '\b':
063: retval.append("\\b");
064: continue;
065: case '\t':
066: retval.append("\\t");
067: continue;
068: case '\n':
069: retval.append("\\n");
070: continue;
071: case '\f':
072: retval.append("\\f");
073: continue;
074: case '\r':
075: retval.append("\\r");
076: continue;
077: case '\"':
078: retval.append("\\\"");
079: continue;
080: case '\'':
081: retval.append("\\\'");
082: continue;
083: case '\\':
084: retval.append("\\\\");
085: continue;
086: default:
087: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
088: String s = "0000" + Integer.toString(ch, 16);
089: retval.append("\\u" + s.substring(s.length() - 4, s.length()));
090: } else {
091: retval.append(ch);
092: }
093: continue;
094: }
095: }
096: return retval.toString();
097: }
098:
099: /**
100: * Returns a detailed message for the Error when it is thrown by the token
101: * manager to indicate a lexical error. Parameters : EOFSeen : indicates if
102: * EOF caused the lexicl error curLexState : lexical state in which this
103: * error occured errorLine : line number when the error occured errorColumn :
104: * column number when the error occured errorAfter : prefix that was seen
105: * before this error occured curchar : the offending character Note: You can
106: * customize the lexical error message by modifying this method.
107: */
108: private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn,
109: String errorAfter, char curChar) {
110: return ("Lexical error at line "
111: + errorLine
112: + ", column "
113: + errorColumn
114: + ". Encountered: "
115: + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar
116: + "), ") + "after : \"" + addEscapes(errorAfter) + "\"");
117: }
118:
119: /**
120: * You can also modify the body of this method to customize your error
121: * messages. For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE
122: * are not of end-users concern, so you can return something like :
123: *
124: * "Internal Error : Please file a bug report .... "
125: *
126: * from this method for such cases in the release version of your parser.
127: */
128: public String getMessage() {
129: return super .getMessage();
130: }
131:
132: /*
133: * Constructors of various flavors follow.
134: */
135:
136: public TokenMgrError() {
137: }
138:
139: public TokenMgrError(String message, int reason) {
140: super (message);
141: errorCode = reason;
142: }
143:
144: public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter,
145: char curChar, int reason) {
146: this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
147: }
148:}
|