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   *
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     ****************************************************************/
021    package org.apache.james.mime4j.field.address;
022    
023    /** Token Manager Error. */
024    public 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      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      static final int STATIC_LEXER_ERROR = 1;
047    
048      /**
049       * Tried to change to an invalid lexical state.
050       */
051      static final int INVALID_LEXICAL_STATE = 2;
052    
053      /**
054       * Detected (and bailed out of) an infinite loop in the token manager.
055       */
056      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 0 :
075              continue;
076            case '\b':
077              retval.append("\\b");
078              continue;
079            case '\t':
080              retval.append("\\t");
081              continue;
082            case '\n':
083              retval.append("\\n");
084              continue;
085            case '\f':
086              retval.append("\\f");
087              continue;
088            case '\r':
089              retval.append("\\r");
090              continue;
091            case '\"':
092              retval.append("\\\"");
093              continue;
094            case '\'':
095              retval.append("\\\'");
096              continue;
097            case '\\':
098              retval.append("\\\\");
099              continue;
100            default:
101              if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
102                String s = "0000" + Integer.toString(ch, 16);
103                retval.append("\\u" + s.substring(s.length() - 4, s.length()));
104              } else {
105                retval.append(ch);
106              }
107              continue;
108          }
109        }
110        return retval.toString();
111      }
112    
113      /**
114       * Returns a detailed message for the Error when it is thrown by the
115       * token manager to indicate a lexical error.
116       * Parameters :
117       *    EOFSeen     : indicates if EOF caused the lexical error
118       *    curLexState : lexical state in which this error occurred
119       *    errorLine   : line number when the error occurred
120       *    errorColumn : column number when the error occurred
121       *    errorAfter  : prefix that was seen before this error occurred
122       *    curchar     : the offending character
123       * Note: You can customize the lexical error message by modifying this method.
124       */
125      protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
126        return("Lexical error at line " +
127              errorLine + ", column " +
128              errorColumn + ".  Encountered: " +
129              (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
130              "after : \"" + addEscapes(errorAfter) + "\"");
131      }
132    
133      /**
134       * You can also modify the body of this method to customize your error messages.
135       * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
136       * of end-users concern, so you can return something like :
137       *
138       *     "Internal Error : Please file a bug report .... "
139       *
140       * from this method for such cases in the release version of your parser.
141       */
142      public String getMessage() {
143        return super.getMessage();
144      }
145    
146      /*
147       * Constructors of various flavors follow.
148       */
149    
150      /** No arg constructor. */
151      public TokenMgrError() {
152      }
153    
154      /** Constructor with message and reason. */
155      public TokenMgrError(String message, int reason) {
156        super(message);
157        errorCode = reason;
158      }
159    
160      /** Full Constructor. */
161      public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
162        this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
163      }
164    }
165    /* JavaCC - OriginalChecksum=dba00f059ee889ef89f778e01622bb7c (do not edit this line) */