1. /*
  2. * @(#)TokenMgrError.java 4.11 04/07/26
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 0.7pre2 */
  8. package com.sun.jmx.snmp.IPAcl;
  9. class TokenMgrError extends Error
  10. {
  11. /*
  12. * Ordinals for various reasons why an Error of this type can be thrown.
  13. */
  14. /**
  15. * Lexical error occured.
  16. */
  17. static final int LEXICAL_ERROR = 0;
  18. /**
  19. * An attempt wass made to create a second instance of a static token manager.
  20. */
  21. static final int STATIC_LEXER_ERROR = 1;
  22. /**
  23. * Tried to change to an invalid lexical state.
  24. */
  25. static final int INVALID_LEXICAL_STATE = 2;
  26. /**
  27. * Detected (and bailed out of) an infinite loop in the token manager.
  28. */
  29. static final int LOOP_DETECTED = 3;
  30. /**
  31. * Indicates the reason why the exception is thrown. It will have
  32. * one of the above 4 values.
  33. */
  34. int errorCode;
  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. {
  45. case 0 :
  46. continue;
  47. case '\b':
  48. retval.append("\\b");
  49. continue;
  50. case '\t':
  51. retval.append("\\t");
  52. continue;
  53. case '\n':
  54. retval.append("\\n");
  55. continue;
  56. case '\f':
  57. retval.append("\\f");
  58. continue;
  59. case '\r':
  60. retval.append("\\r");
  61. continue;
  62. case '\"':
  63. retval.append("\\\"");
  64. continue;
  65. case '\'':
  66. retval.append("\\\'");
  67. continue;
  68. case '\\':
  69. retval.append("\\\\");
  70. continue;
  71. default:
  72. if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
  73. String s = "0000" + Integer.toString(ch, 16);
  74. retval.append("\\u" + s.substring(s.length() - 4, s.length()));
  75. } else {
  76. retval.append(ch);
  77. }
  78. continue;
  79. }
  80. }
  81. return retval.toString();
  82. }
  83. /**
  84. * Returns a detailed message for the Error when it is thrown by the
  85. * token manager to indicate a lexical error.
  86. * Parameters :
  87. * EOFSeen : indicates if EOF caused the lexicl error
  88. * curLexState : lexical state in which this error occured
  89. * errorLine : line number when the error occured
  90. * errorColumn : column number when the error occured
  91. * errorAfter : prefix that was seen before this error occured
  92. * curchar : the offending character
  93. * Note: You can customize the lexical error message by modifying this method.
  94. */
  95. private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
  96. return("Lexical error at line " +
  97. errorLine + ", column " +
  98. errorColumn + ". Encountered: " +
  99. (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
  100. "after : \"" + addEscapes(errorAfter) + "\"");
  101. }
  102. /**
  103. * You can also modify the body of this method to customize your error messages.
  104. * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
  105. * of end-users concern, so you can return something like :
  106. *
  107. * "Internal Error : Please file a bug report .... "
  108. *
  109. * from this method for such cases in the release version of your parser.
  110. */
  111. public String getMessage() {
  112. return super.getMessage();
  113. }
  114. /*
  115. * Constructors of various flavors follow.
  116. */
  117. public TokenMgrError() {
  118. }
  119. public TokenMgrError(String message, int reason) {
  120. super(message);
  121. errorCode = reason;
  122. }
  123. public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
  124. this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
  125. }
  126. }