src/java.management.rest/share/classes/com/oracle/jmx/remote/rest/json/parser/ParseException.java
author hb
Tue, 29 Aug 2017 13:34:15 +0530
branchjmx-rest-api
changeset 55985 0c5a02edfdef
permissions -rw-r--r--
REST Adapter Initial commit 1. Unit tested and working GET/POST interfaces 2. Unit tested and working JSON parser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55985
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
     1
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
     2
/* JavaCCOptions:KEEP_LINE_COL=null */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
     3
package com.oracle.jmx.remote.rest.json.parser;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
     4
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
     5
/**
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
     6
 * This exception is thrown when parse errors are encountered.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
     7
 * You can explicitly create objects of this exception type by
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
     8
 * calling the method generateParseException in the generated
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
     9
 * parser.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    10
 *
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    11
 * You can modify this class to customize your error reporting
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    12
 * mechanisms so long as you retain the public fields.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    13
 */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    14
public class ParseException extends Exception {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    15
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    16
  /**
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    17
   * The version identifier for this Serializable class.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    18
   * Increment only if the <i>serialized</i> form of the
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    19
   * class changes.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    20
   */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    21
  private static final long serialVersionUID = 1L;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    22
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    23
  /**
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    24
   * This constructor is used by the method "generateParseException"
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    25
   * in the generated parser.  Calling this constructor generates
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    26
   * a new object of this type with the fields "currentToken",
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    27
   * "expectedTokenSequences", and "tokenImage" set.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    28
   */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    29
  public ParseException(Token currentTokenVal,
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    30
                        int[][] expectedTokenSequencesVal,
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    31
                        String[] tokenImageVal
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    32
                       )
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    33
  {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    34
    super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    35
    currentToken = currentTokenVal;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    36
    expectedTokenSequences = expectedTokenSequencesVal;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    37
    tokenImage = tokenImageVal;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    38
  }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    39
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    40
  /**
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    41
   * The following constructors are for use by you for whatever
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    42
   * purpose you can think of.  Constructing the exception in this
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    43
   * manner makes the exception behave in the normal way - i.e., as
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    44
   * documented in the class "Throwable".  The fields "errorToken",
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    45
   * "expectedTokenSequences", and "tokenImage" do not contain
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    46
   * relevant information.  The JavaCC generated code does not use
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    47
   * these constructors.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    48
   */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    49
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    50
  public ParseException() {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    51
    super();
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    52
  }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    53
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    54
  /** Constructor with message. */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    55
  public ParseException(String message) {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    56
    super(message);
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    57
  }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    58
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    59
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    60
  /**
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    61
   * This is the last token that has been consumed successfully.  If
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    62
   * this object has been created due to a parse error, the token
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    63
   * followng this token will (therefore) be the first error token.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    64
   */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    65
  public Token currentToken;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    66
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    67
  /**
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    68
   * Each entry in this array is an array of integers.  Each array
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    69
   * of integers represents a sequence of tokens (by their ordinal
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    70
   * values) that is expected at this point of the parse.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    71
   */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    72
  public int[][] expectedTokenSequences;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    73
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    74
  /**
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    75
   * This is a reference to the "tokenImage" array of the generated
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    76
   * parser within which the parse error occurred.  This array is
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    77
   * defined in the generated ...Constants interface.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    78
   */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    79
  public String[] tokenImage;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    80
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    81
  /**
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    82
   * It uses "currentToken" and "expectedTokenSequences" to generate a parse
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    83
   * error message and returns it.  If this object has been created
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    84
   * due to a parse error, and you do not catch it (it gets thrown
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    85
   * from the parser) the correct error message
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    86
   * gets displayed.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    87
   */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    88
  private static String initialise(Token currentToken,
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    89
                           int[][] expectedTokenSequences,
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    90
                           String[] tokenImage) {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    91
    String eol = System.getProperty("line.separator", "\n");
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    92
    StringBuffer expected = new StringBuffer();
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    93
    int maxSize = 0;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    94
    for (int i = 0; i < expectedTokenSequences.length; i++) {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    95
      if (maxSize < expectedTokenSequences[i].length) {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    96
        maxSize = expectedTokenSequences[i].length;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    97
      }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    98
      for (int j = 0; j < expectedTokenSequences[i].length; j++) {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
    99
        expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   100
      }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   101
      if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   102
        expected.append("...");
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   103
      }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   104
      expected.append(eol).append("    ");
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   105
    }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   106
    String retval = "Encountered \"";
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   107
    Token tok = currentToken.next;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   108
    for (int i = 0; i < maxSize; i++) {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   109
      if (i != 0) retval += " ";
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   110
      if (tok.kind == 0) {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   111
        retval += tokenImage[0];
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   112
        break;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   113
      }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   114
      retval += " " + tokenImage[tok.kind];
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   115
      retval += " \"";
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   116
      retval += add_escapes(tok.image);
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   117
      retval += " \"";
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   118
      tok = tok.next;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   119
    }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   120
    retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   121
    retval += "." + eol;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   122
    if (expectedTokenSequences.length == 1) {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   123
      retval += "Was expecting:" + eol + "    ";
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   124
    } else {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   125
      retval += "Was expecting one of:" + eol + "    ";
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   126
    }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   127
    retval += expected.toString();
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   128
    return retval;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   129
  }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   130
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   131
  /**
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   132
   * The end of line string for this machine.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   133
   */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   134
  protected String eol = System.getProperty("line.separator", "\n");
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   135
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   136
  /**
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   137
   * Used to convert raw characters to their escaped version
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   138
   * when these raw version cannot be used as part of an ASCII
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   139
   * string literal.
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   140
   */
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   141
  static String add_escapes(String str) {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   142
      StringBuffer retval = new StringBuffer();
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   143
      char ch;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   144
      for (int i = 0; i < str.length(); i++) {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   145
        switch (str.charAt(i))
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   146
        {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   147
           case 0 :
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   148
              continue;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   149
           case '\b':
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   150
              retval.append("\\b");
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   151
              continue;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   152
           case '\t':
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   153
              retval.append("\\t");
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   154
              continue;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   155
           case '\n':
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   156
              retval.append("\\n");
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   157
              continue;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   158
           case '\f':
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   159
              retval.append("\\f");
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   160
              continue;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   161
           case '\r':
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   162
              retval.append("\\r");
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   163
              continue;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   164
           case '\"':
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   165
              retval.append("\\\"");
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   166
              continue;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   167
           case '\'':
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   168
              retval.append("\\\'");
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   169
              continue;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   170
           case '\\':
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   171
              retval.append("\\\\");
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   172
              continue;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   173
           default:
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   174
              if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   175
                 String s = "0000" + Integer.toString(ch, 16);
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   176
                 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   177
              } else {
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   178
                 retval.append(ch);
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   179
              }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   180
              continue;
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   181
        }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   182
      }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   183
      return retval.toString();
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   184
   }
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   185
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   186
}
0c5a02edfdef REST Adapter Initial commit
hb
parents:
diff changeset
   187
/* JavaCC - OriginalChecksum=90e796a5f303517657c1e544869a38af (do not edit this line) */