TokenMgrError.java

  1. /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */
  2. /* JavaCCOptions: */
  3. package org.apache.commons.configuration2.plist;

  4. /** Token Manager Error. */
  5. public class TokenMgrError extends Error
  6. {

  7.   /**
  8.    * The version identifier for this Serializable class.
  9.    * Increment only if the <i>serialized</i> form of the
  10.    * class changes.
  11.    */
  12.   private static final long serialVersionUID = 1L;

  13.   /*
  14.    * Ordinals for various reasons why an Error of this type can be thrown.
  15.    */

  16.   /**
  17.    * Lexical error occurred.
  18.    */
  19.   static final int LEXICAL_ERROR = 0;

  20.   /**
  21.    * An attempt was made to create a second instance of a static token manager.
  22.    */
  23.   static final int STATIC_LEXER_ERROR = 1;

  24.   /**
  25.    * Tried to change to an invalid lexical state.
  26.    */
  27.   static final int INVALID_LEXICAL_STATE = 2;

  28.   /**
  29.    * Detected (and bailed out of) an infinite loop in the token manager.
  30.    */
  31.   static final int LOOP_DETECTED = 3;

  32.   /**
  33.    * Indicates the reason why the exception is thrown. It will have
  34.    * one of the above 4 values.
  35.    */
  36.   int errorCode;

  37.   /**
  38.    * Replaces unprintable characters by their escaped (or unicode escaped)
  39.    * equivalents in the given string
  40.    */
  41.   protected static final String addEscapes(String str) {
  42.     StringBuffer retval = new StringBuffer();
  43.     char ch;
  44.     for (int i = 0; i < str.length(); i++) {
  45.       switch (str.charAt(i))
  46.       {
  47.         case 0 :
  48.           continue;
  49.         case '\b':
  50.           retval.append("\\b");
  51.           continue;
  52.         case '\t':
  53.           retval.append("\\t");
  54.           continue;
  55.         case '\n':
  56.           retval.append("\\n");
  57.           continue;
  58.         case '\f':
  59.           retval.append("\\f");
  60.           continue;
  61.         case '\r':
  62.           retval.append("\\r");
  63.           continue;
  64.         case '\"':
  65.           retval.append("\\\"");
  66.           continue;
  67.         case '\'':
  68.           retval.append("\\\'");
  69.           continue;
  70.         case '\\':
  71.           retval.append("\\\\");
  72.           continue;
  73.         default:
  74.           if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
  75.             String s = "0000" + Integer.toString(ch, 16);
  76.             retval.append("\\u" + s.substring(s.length() - 4, s.length()));
  77.           } else {
  78.             retval.append(ch);
  79.           }
  80.           continue;
  81.       }
  82.     }
  83.     return retval.toString();
  84.   }

  85.   /**
  86.    * Returns a detailed message for the Error when it is thrown by the
  87.    * token manager to indicate a lexical error.
  88.    * Parameters :
  89.    *    EOFSeen     : indicates if EOF caused the lexical error
  90.    *    curLexState : lexical state in which this error occurred
  91.    *    errorLine   : line number when the error occurred
  92.    *    errorColumn : column number when the error occurred
  93.    *    errorAfter  : prefix that was seen before this error occurred
  94.    *    curchar     : the offending character
  95.    * Note: You can customize the lexical error message by modifying this method.
  96.    */
  97.   protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
  98.     return("Lexical error at line " +
  99.           errorLine + ", column " +
  100.           errorColumn + ".  Encountered: " +
  101.           (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
  102.           "after : \"" + addEscapes(errorAfter) + "\"");
  103.   }

  104.   /**
  105.    * You can also modify the body of this method to customize your error messages.
  106.    * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
  107.    * of end-users concern, so you can return something like :
  108.    *
  109.    *     "Internal Error : Please file a bug report .... "
  110.    *
  111.    * from this method for such cases in the release version of your parser.
  112.    */
  113.   public String getMessage() {
  114.     return super.getMessage();
  115.   }

  116.   /*
  117.    * Constructors of various flavors follow.
  118.    */

  119.   /** No arg constructor. */
  120.   public TokenMgrError() {
  121.   }

  122.   /** Constructor with message and reason. */
  123.   public TokenMgrError(String message, int reason) {
  124.     super(message);
  125.     errorCode = reason;
  126.   }

  127.   /** Full Constructor. */
  128.   public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
  129.     this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
  130.   }
  131. }
  132. /* JavaCC - OriginalChecksum=26de2aeebd0c731dde20532229d715f6 (do not edit this line) */