1 /* 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 0.7pre2 */ 27 package com.sun.jmx.snmp.IPAcl; 28 29 class TokenMgrError extends Error 30 { 31 private static final long serialVersionUID = -6373071623408870347L; 32 33 /* 34 * Ordinals for various reasons why an Error of this type can be thrown. 35 */ 36 37 /** 38 * Lexical error occurred. 39 */ 40 static final int LEXICAL_ERROR = 0; 41 42 /** 43 * An attempt wass made to create a second instance of a static token manager. 44 */ 45 static final int STATIC_LEXER_ERROR = 1; 46 47 /** 48 * Tried to change to an invalid lexical state. 49 */ 50 static final int INVALID_LEXICAL_STATE = 2; 51 52 /** 53 * Detected (and bailed out of) an infinite loop in the token manager. 54 */ 55 static final int LOOP_DETECTED = 3; 56 57 /** 58 * Indicates the reason why the exception is thrown. It will have 59 * one of the above 4 values. 60 */ 61 int errorCode; 62 63 /** 64 * Replaces unprintable characters by their espaced (or unicode escaped) 65 * equivalents in the given string 66 */ 67 protected static final String addEscapes(String str) { 68 StringBuilder retval = new StringBuilder(); 69 char ch; 70 for (int i = 0; i < str.length(); i++) { 71 switch (str.charAt(i)) 72 { 73 case 0 : 74 continue; 75 case '\b': 76 retval.append("\\b"); 77 continue; 78 case '\t': 79 retval.append("\\t"); 80 continue; 81 case '\n': 82 retval.append("\\n"); 83 continue; 84 case '\f': 85 retval.append("\\f"); 86 continue; 87 case '\r': 88 retval.append("\\r"); 89 continue; 90 case '\"': 91 retval.append("\\\""); 92 continue; 93 case '\'': 94 retval.append("\\\'"); 95 continue; 96 case '\\': 97 retval.append("\\\\"); 98 continue; 99 default: 100 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { 101 String s = "0000" + Integer.toString(ch, 16); 102 retval.append("\\u").append(s.substring(s.length() - 4, s.length())); 103 } else { 104 retval.append(ch); 105 } 106 continue; 107 } 108 } 109 return retval.toString(); 110 } 111 112 /** 113 * Returns a detailed message for the Error when it is thrown by the 114 * token manager to indicate a lexical error. 115 * Parameters : 116 * EOFSeen : indicates if EOF caused the lexicl error 117 * curLexState : lexical state in which this error occurred 118 * errorLine : line number when the error occurred 119 * errorColumn : column number when the error occurred 120 * errorAfter : prefix that was seen before this error occurred 121 * curchar : the offending character 122 * Note: You can customize the lexical error message by modifying this method. 123 */ 124 private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { 125 return("Lexical error at line " + 126 errorLine + ", column " + 127 errorColumn + ". Encountered: " + 128 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + 129 "after : \"" + addEscapes(errorAfter) + "\""); 130 } 131 132 /** 133 * You can also modify the body of this method to customize your error messages. 134 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not 135 * of end-users concern, so you can return something like : 136 * 137 * "Internal Error : Please file a bug report .... " 138 * 139 * from this method for such cases in the release version of your parser. 140 */ 141 public String getMessage() { 142 return super.getMessage(); 143 } 144 145 /* 146 * Constructors of various flavors follow. 147 */ 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 }