1 22 23 package org.enhydra.spi.conf.util; 24 25 public class TokenMgrError extends Error 26 { 27 30 31 34 static final int LEXICAL_ERROR = 0; 35 36 39 static final int STATIC_LEXER_ERROR = 1; 40 41 44 static final int INVALID_LEXICAL_STATE = 2; 45 46 49 static final int LOOP_DETECTED = 3; 50 51 55 int errorCode; 56 57 64 protected static final String addEscapes(String str) { 65 StringBuffer retval = new StringBuffer (); 66 char ch; 67 for (int i = 0; i < str.length(); i++) { 68 switch (str.charAt(i)) 69 { 70 case 0 : 71 continue; 72 case '\b': 73 retval.append("\\b"); 74 continue; 75 case '\t': 76 retval.append("\\t"); 77 continue; 78 case '\n': 79 retval.append("\\n"); 80 continue; 81 case '\f': 82 retval.append("\\f"); 83 continue; 84 case '\r': 85 retval.append("\\r"); 86 continue; 87 case '\"': 88 retval.append("\\\""); 89 continue; 90 case '\'': 91 retval.append("\\\'"); 92 continue; 93 case '\\': 94 retval.append("\\\\"); 95 continue; 96 default: 97 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 98 String s = "0000" + Integer.toString(ch, 16); 99 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 100 } else { 101 retval.append(ch); 102 } 103 continue; 104 } 105 } 106 return retval.toString(); 107 } 108 109 122 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 123 return("Lexical error at line " + 124 errorLine + ", column " + 125 errorColumn + ". Encountered: " + 126 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 127 "after : \"" + addEscapes(errorAfter) + "\""); 128 } 129 130 141 public String getMessage() { 142 return super.getMessage(); 143 } 144 145 148 149 public TokenMgrError() { 150 } 151 152 public TokenMgrError(String message, int reason) { 153 super(message); 154 errorCode = reason; 155 } 156 157 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 158 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 159 } 160 } 161 | Popular Tags |