001/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */
002/* JavaCCOptions: */
003/*
004 *  jDTAUS Core RI Client Container
005 *  Copyright (C) 2005 Christian Schulte
006 *  <cs@schulte.it>
007 *
008 *  This library is free software; you can redistribute it and/or
009 *  modify it under the terms of the GNU Lesser General Public
010 *  License as published by the Free Software Foundation; either
011 *  version 2.1 of the License, or any later version.
012 *
013 *  This library is distributed in the hope that it will be useful,
014 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
015 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016 *  Lesser General Public License for more details.
017 *
018 *  You should have received a copy of the GNU Lesser General Public
019 *  License along with this library; if not, write to the Free Software
020 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
021 *
022 *  $JDTAUS: VersionParser.jj 8641 2012-09-27 06:45:17Z schulte $
023 *
024 */
025package org.jdtaus.core.container.ri.client.versioning;
026
027/** Token Manager Error. */
028public class TokenMgrError extends Error
029{
030
031  /**
032   * The version identifier for this Serializable class.
033   * Increment only if the <i>serialized</i> form of the
034   * class changes.
035   */
036  private static final long serialVersionUID = 1L;
037
038  /*
039   * Ordinals for various reasons why an Error of this type can be thrown.
040   */
041
042  /**
043   * Lexical error occurred.
044   */
045  static final int LEXICAL_ERROR = 0;
046
047  /**
048   * An attempt was made to create a second instance of a static token manager.
049   */
050  static final int STATIC_LEXER_ERROR = 1;
051
052  /**
053   * Tried to change to an invalid lexical state.
054   */
055  static final int INVALID_LEXICAL_STATE = 2;
056
057  /**
058   * Detected (and bailed out of) an infinite loop in the token manager.
059   */
060  static final int LOOP_DETECTED = 3;
061
062  /**
063   * Indicates the reason why the exception is thrown. It will have
064   * one of the above 4 values.
065   */
066  int errorCode;
067
068  /**
069   * Replaces unprintable characters by their escaped (or unicode escaped)
070   * equivalents in the given string
071   */
072  protected static final String addEscapes(String str) {
073    StringBuffer retval = new StringBuffer();
074    char ch;
075    for (int i = 0; i < str.length(); i++) {
076      switch (str.charAt(i))
077      {
078        case 0 :
079          continue;
080        case '\b':
081          retval.append("\\b");
082          continue;
083        case '\t':
084          retval.append("\\t");
085          continue;
086        case '\n':
087          retval.append("\\n");
088          continue;
089        case '\f':
090          retval.append("\\f");
091          continue;
092        case '\r':
093          retval.append("\\r");
094          continue;
095        case '\"':
096          retval.append("\\\"");
097          continue;
098        case '\'':
099          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) */