View Javadoc

    1   /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 2.1 */
    2   package org.codehaus.activemq.selector;
    3
    4   public class TokenMgrError extends Error {
    5       /*
    6        * Ordinals for various reasons why an Error of this type can be thrown.
    7        */
    8
    9       /***
    10       * Lexical error occured.
    11       */
    12      static final int LEXICAL_ERROR = 0;
    13
    14      /***
    15       * An attempt wass made to create a second instance of a static token manager.
    16       */
    17      static final int STATIC_LEXER_ERROR = 1;
    18
    19      /***
    20       * Tried to change to an invalid lexical state.
    21       */
    22      static final int INVALID_LEXICAL_STATE = 2;
    23
    24      /***
    25       * Detected (and bailed out of) an infinite loop in the token manager.
    26       */
    27      static final int LOOP_DETECTED = 3;
    28
    29      /***
    30       * Indicates the reason why the exception is thrown. It will have
    31       * one of the above 4 values.
    32       */
    33      int errorCode;
    34
    35      /***
    36       * Replaces unprintable characters by their espaced (or unicode escaped)
    37       * equivalents in the given string
    38       */
    39      protected static final String addEscapes(String str) {
    40          StringBuffer retval = new StringBuffer();
    41          char ch;
    42          for (int i = 0; i < str.length(); i++) {
    43              switch (str.charAt(i)) {
    44                  case 0:
    45                      continue;
    46                  case '\b':
    47                      retval.append("//b");
    48                      continue;
    49                  case '\t':
    50                      retval.append("//t");
    51                      continue;
    52                  case '\n':
    53                      retval.append("//n");
    54                      continue;
    55                  case '\f':
    56                      retval.append("//f");
    57                      continue;
    58                  case '\r':
    59                      retval.append("//r");
    60                      continue;
    61                  case '\"':
    62                      retval.append("//\"");
    63                      continue;
    64                  case '\'':
    65                      retval.append("//\'");
    66                      continue;
    67                  case '//':
    68                      retval.append("////");
    69                      continue;
    70                  default:
    71                      if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
    72                          String s = "0000" + Integer.toString(ch, 16);
    73                          retval.append("//u" + s.substring(s.length() - 4, s.length()));
    74                      }
    75                      else {
    76                          retval.append(ch);
    77                      }
    78                      continue;
    79              }
    80          }
    81          return retval.toString();
    82      }
    83
    84      /***
    85       * Returns a detailed message for the Error when it is thrown by the
    86       * token manager to indicate a lexical error.
    87       * Parameters :
    88       * EOFSeen     : indicates if EOF caused the lexicl error
    89       * curLexState : lexical state in which this error occured
    90       * errorLine   : line number when the error occured
    91       * errorColumn : column number when the error occured
    92       * errorAfter  : prefix that was seen before this error occured
    93       * curchar     : the offending character
    94       * Note: You can customize the lexical error message by modifying this method.
    95       */
    96      private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
    97          return ("Lexical error at line " +
    98                  errorLine + ", column " +
    99                  errorColumn + ".  Encountered: " +
    100                 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") +
    101                 "after : \"" + addEscapes(errorAfter) + "\"");
    102     }
    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      * <p/>
    109      * "Internal Error : Please file a bug report .... "
    110      * <p/>
    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     /*
    118      * Constructors of various flavors follow.
    119      */
    120
    121     public TokenMgrError() {
    122     }
    123
    124     public TokenMgrError(String message, int reason) {
    125         super(message);
    126         errorCode = reason;
    127     }
    128
    129     public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
    130         this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
    131     }
    132 }