001/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */
002/* JavaCCOptions: */
003/**
004 * Licensed to the Apache Software Foundation (ASF) under one or more
005 * contributor license agreements.  See the NOTICE file distributed with
006 * this work for additional information regarding copyright ownership.
007 * The ASF licenses this file to You under the Apache License, Version 2.0
008 * (the "License"); you may not use this file except in compliance with
009 * the License.  You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020package org.apache.activemq.selector;
021
022/** Token Manager Error. */
023public class TokenMgrError extends Error
024{
025
026  /**
027   * The version identifier for this Serializable class.
028   * Increment only if the <i>serialized</i> form of the
029   * class changes.
030   */
031  private static final long serialVersionUID = 1L;
032
033  /*
034   * Ordinals for various reasons why an Error of this type can be thrown.
035   */
036
037  /**
038   * Lexical error occurred.
039   */
040  static final int LEXICAL_ERROR = 0;
041
042  /**
043   * An attempt was made to create a second instance of a static token manager.
044   */
045  static final int STATIC_LEXER_ERROR = 1;
046
047  /**
048   * Tried to change to an invalid lexical state.
049   */
050  static final int INVALID_LEXICAL_STATE = 2;
051
052  /**
053   * Detected (and bailed out of) an infinite loop in the token manager.
054   */
055  static final int LOOP_DETECTED = 3;
056
057  /**
058   * Indicates the reason why the exception is thrown. It will have
059   * one of the above 4 values.
060   */
061  int errorCode;
062
063  /**
064   * Replaces unprintable characters by their escaped (or unicode escaped)
065   * equivalents in the given string
066   */
067  protected static final String addEscapes(String str) {
068    StringBuffer retval = new StringBuffer();
069    char ch;
070    for (int i = 0; i < str.length(); i++) {
071      switch (str.charAt(i))
072      {
073        case 0 :
074          continue;
075        case '\b':
076          retval.append("\\b");
077          continue;
078        case '\t':
079          retval.append("\\t");
080          continue;
081        case '\n':
082          retval.append("\\n");
083          continue;
084        case '\f':
085          retval.append("\\f");
086          continue;
087        case '\r':
088          retval.append("\\r");
089          continue;
090        case '\"':
091          retval.append("\\\"");
092          continue;
093        case '\'':
094          retval.append("\\\'");
095          continue;
096        case '\\':
097          retval.append("\\\\");
098          continue;
099        default:
100          if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
101            String s = "0000" + Integer.toString(ch, 16);
102            retval.append("\\u" + 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 lexical 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  protected static 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  /** No arg constructor. */
150  public TokenMgrError() {
151  }
152
153  /** Constructor with message and reason. */
154  public TokenMgrError(String message, int reason) {
155    super(message);
156    errorCode = reason;
157  }
158
159  /** Full Constructor. */
160  public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
161    this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
162  }
163}
164/* JavaCC - OriginalChecksum=bd90f157e8a840120134a40848c3a449 (do not edit this line) */