001/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 7.0 */
002/* JavaCCOptions: */
003/****************************************************************
004 * Licensed to the Apache Software Foundation (ASF) under one   *
005 * or more contributor license agreements.  See the NOTICE file *
006 * distributed with this work for additional information        *
007 * regarding copyright ownership.  The ASF licenses this file   *
008 * to you under the Apache License, Version 2.0 (the            *
009 * "License"); you may not use this file except in compliance   *
010 * with the License.  You may obtain a copy of the License at   *
011 *                                                              *
012 *   http://www.apache.org/licenses/LICENSE-2.0                 *
013 *                                                              *
014 * Unless required by applicable law or agreed to in writing,   *
015 * software distributed under the License is distributed on an  *
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
017 * KIND, either express or implied.  See the License for the    *
018 * specific language governing permissions and limitations      *
019 * under the License.                                           *
020 ****************************************************************/
021package org.apache.james.mime4j.field.address;
022
023/** Token Manager Error. */
024public class TokenMgrError extends Error
025{
026
027  /**
028   * The version identifier for this Serializable class.
029   * Increment only if the <i>serialized</i> form of the
030   * class changes.
031   */
032  private static final long serialVersionUID = 1L;
033
034  /*
035   * Ordinals for various reasons why an Error of this type can be thrown.
036   */
037
038  /**
039   * Lexical error occurred.
040   */
041  public static final int LEXICAL_ERROR = 0;
042
043  /**
044   * An attempt was made to create a second instance of a static token manager.
045   */
046  public static final int STATIC_LEXER_ERROR = 1;
047
048  /**
049   * Tried to change to an invalid lexical state.
050   */
051  public static final int INVALID_LEXICAL_STATE = 2;
052
053  /**
054   * Detected (and bailed out of) an infinite loop in the token manager.
055   */
056  public static final int LOOP_DETECTED = 3;
057
058  /**
059   * Indicates the reason why the exception is thrown. It will have
060   * one of the above 4 values.
061   */
062  int errorCode;
063
064  /**
065   * Replaces unprintable characters by their escaped (or unicode escaped)
066   * equivalents in the given string
067   */
068  protected static final String addEscapes(String str) {
069    StringBuffer retval = new StringBuffer();
070    char ch;
071    for (int i = 0; i < str.length(); i++) {
072      switch (str.charAt(i))
073      {
074        case '\b':
075          retval.append("\\b");
076          continue;
077        case '\t':
078          retval.append("\\t");
079          continue;
080        case '\n':
081          retval.append("\\n");
082          continue;
083        case '\f':
084          retval.append("\\f");
085          continue;
086        case '\r':
087          retval.append("\\r");
088          continue;
089        case '\"':
090          retval.append("\\\"");
091          continue;
092        case '\'':
093          retval.append("\\\'");
094          continue;
095        case '\\':
096          retval.append("\\\\");
097          continue;
098        default:
099          if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
100            String s = "0000" + Integer.toString(ch, 16);
101            retval.append("\\u" + s.substring(s.length() - 4, s.length()));
102          } else {
103            retval.append(ch);
104          }
105          continue;
106      }
107    }
108    return retval.toString();
109  }
110
111  /**
112   * Returns a detailed message for the Error when it is thrown by the
113   * token manager to indicate a lexical error.
114   * Parameters :
115   *    EOFSeen     : indicates if EOF caused the lexical error
116   *    curLexState : lexical state in which this error occurred
117   *    errorLine   : line number when the error occurred
118   *    errorColumn : column number when the error occurred
119   *    errorAfter  : prefix that was seen before this error occurred
120   *    curchar     : the offending character
121   * Note: You can customize the lexical error message by modifying this method.
122   */
123  protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) {
124    char curChar1 = (char)curChar;
125    return("Lexical error at line " +
126          errorLine + ", column " +
127          errorColumn + ".  Encountered: " +
128          (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + (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, int curChar, int reason) {
161    this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
162  }
163}
164/* JavaCC - OriginalChecksum=a8c50e31dc41b27bd5fe08b2265c4466 (do not edit this line) */