1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ 2 /* JavaCCOptions: */ 3 /* 4 * jDTAUS Core RI Client Container 5 * Copyright (C) 2005 Christian Schulte 6 * <cs@schulte.it> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 * 22 * $JDTAUS: VersionParser.jj 8641 2012-09-27 06:45:17Z schulte $ 23 * 24 */ 25 package org.jdtaus.core.container.ri.client.versioning; 26 27 /** Token Manager Error. */ 28 public class TokenMgrError extends Error 29 { 30 31 /** 32 * The version identifier for this Serializable class. 33 * Increment only if the <i>serialized</i> form of the 34 * class changes. 35 */ 36 private static final long serialVersionUID = 1L; 37 38 /* 39 * Ordinals for various reasons why an Error of this type can be thrown. 40 */ 41 42 /** 43 * Lexical error occurred. 44 */ 45 static final int LEXICAL_ERROR = 0; 46 47 /** 48 * An attempt was made to create a second instance of a static token manager. 49 */ 50 static final int STATIC_LEXER_ERROR = 1; 51 52 /** 53 * Tried to change to an invalid lexical state. 54 */ 55 static final int INVALID_LEXICAL_STATE = 2; 56 57 /** 58 * Detected (and bailed out of) an infinite loop in the token manager. 59 */ 60 static final int LOOP_DETECTED = 3; 61 62 /** 63 * Indicates the reason why the exception is thrown. It will have 64 * one of the above 4 values. 65 */ 66 int errorCode; 67 68 /** 69 * Replaces unprintable characters by their escaped (or unicode escaped) 70 * equivalents in the given string 71 */ 72 protected static final String addEscapes(String str) { 73 StringBuffer retval = new StringBuffer(); 74 char ch; 75 for (int i = 0; i < str.length(); i++) { 76 switch (str.charAt(i)) 77 { 78 case 0 : 79 continue; 80 case '\b': 81 retval.append("\\b"); 82 continue; 83 case '\t': 84 retval.append("\\t"); 85 continue; 86 case '\n': 87 retval.append("\\n"); 88 continue; 89 case '\f': 90 retval.append("\\f"); 91 continue; 92 case '\r': 93 retval.append("\\r"); 94 continue; 95 case '\"': 96 retval.append("\\\""); 97 continue; 98 case '\'': 99 retval.append("\\\'"); 100 continue; 101 case '\\': 102 retval.append("\\\\"); 103 continue; 104 default: 105 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 106 String s = "0000" + Integer.toString(ch, 16); 107 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 108 } else { 109 retval.append(ch); 110 } 111 continue; 112 } 113 } 114 return retval.toString(); 115 } 116 117 /** 118 * Returns a detailed message for the Error when it is thrown by the 119 * token manager to indicate a lexical error. 120 * Parameters : 121 * EOFSeen : indicates if EOF caused the lexical error 122 * curLexState : lexical state in which this error occurred 123 * errorLine : line number when the error occurred 124 * errorColumn : column number when the error occurred 125 * errorAfter : prefix that was seen before this error occurred 126 * curchar : the offending character 127 * Note: You can customize the lexical error message by modifying this method. 128 */ 129 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 130 return("Lexical error at line " + 131 errorLine + ", column " + 132 errorColumn + ". Encountered: " + 133 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 134 "after : \"" + addEscapes(errorAfter) + "\""); 135 } 136 137 /** 138 * You can also modify the body of this method to customize your error messages. 139 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not 140 * of end-users concern, so you can return something like : 141 * 142 * "Internal Error : Please file a bug report .... " 143 * 144 * from this method for such cases in the release version of your parser. 145 */ 146 public String getMessage() { 147 return super.getMessage(); 148 } 149 150 /* 151 * Constructors of various flavors follow. 152 */ 153 154 /** No arg constructor. */ 155 public TokenMgrError() { 156 } 157 158 /** Constructor with message and reason. */ 159 public TokenMgrError(String message, int reason) { 160 super(message); 161 errorCode = reason; 162 } 163 164 /** Full Constructor. */ 165 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { 166 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 167 } 168 } 169 /* JavaCC - OriginalChecksum=513d3d9a37857546228e37a9480555d5 (do not edit this line) */