org.infinispan.schematic.internal.document

## Class JsonReader.Parser

- java.lang.Object
- - org.infinispan.schematic.internal.document.JsonReader.Parser

- Enclosing class:
    JsonReader

      @NotThreadSafe
      public static class JsonReader.Parser
      extends Object

  The component that parses a tokenized JSON stream.
  Since:
    5.1

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `JsonReader.Parser.FunctionCall`
    `protected static class` | `JsonReader.Parser.FunctionParameter`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JsonReader.Parser(JsonReader.Tokenizer tokenizer, DocumentValueFactory values, JsonReader.ValueMatcher valueMatcher)` Create a new JsonReader that uses the supplied `JsonReader.Tokenizer` instance.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `evaluateFunction(JsonReader.Parser.FunctionCall function)` Method that is called to evaluate the supplied function.
    `protected Object` | `evaluateUnknownFunction(JsonReader.Parser.FunctionCall function)` Method that is called when the function call described by the parameter could not be evaluated.
    `protected boolean` | `isReservedFieldName(String fieldName)`
    `protected BasicDocument` | `newDocument()`
    `BasicArray` | `parseArray()` Parse the JSON array on the stream, beginning with the '[' character until the ']' character, which is consumed.
    `Document` | `parseDocument()` Parse the stream for the next JSON document.
    `protected Document` | `parseDocument(AtomicBoolean hasReservedFieldNames, boolean failIfNotValidDocument)` Parse the stream for the next JSON document.
    `Document` | `parseDocument(boolean failIfNotValidDocument)` Parse the stream for the next JSON document.
    `Object` | `parseFunction()` Parse a function call on the stream.
    `protected Number` | `parseNumber(String value)` Parse the number represented by the supplied value.
    `protected Object` | `parseUnknownValue(String value, int lineNumber, int columnNumber)` Override this method if custom value types are expected.
    `Object` | `parseValue()` Parse the stream for the next field value, which can be one of the following values: a nested document an array of values a string literal, surrounded by single-quote characters a string literal, surrounded by double-quote characters a string literal date of the form `"yyyy-MM-ddTHH:mm:ss"` where `T` is a literal character a string literal date of the form `"yyyy-MM-ddTHH:mm:ssZ"` where `T` and `Z` are literal characters a string literal date of the form `"yyyy-MM-ddTHH:mm:ssGMT+00:00"` where `T`, and `GMT` are literal characters a string literal date of the form `"/Date(millisOrIso)/"` a string literal date of the form `"\/Date(millisOrIso)\/"` a date literal of the form `new Date(millisOrIso)` a date literal of the form `Date(millisOrIso)` a function of the form `new functionName(parameters)` where `parameters` consists of one or more values as parsed by this method Note that in the date forms listed above, `millisOrIso` is either a long value representing the number of milliseconds since epoch or a string literal in ISO-8601 format representing a date and time.
    `Object` | `parseValue(String value, int lineNumber, int columnNumber)` Parse the value given by the supplied string located at the supplied line and column numbers.
    `protected Object` | `processDocumentWithReservedFieldNames(Document doc)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JsonReader.Parser

          public JsonReader.Parser(JsonReader.Tokenizer tokenizer,
                           DocumentValueFactory values,
                           JsonReader.ValueMatcher valueMatcher)

      Create a new JsonReader that uses the supplied `JsonReader.Tokenizer` instance.
      Parameters:
        `tokenizer` - the tokenizer that tokenizes the stream of JSON content; may not be null
        `values` - the factory for creating value objects; may not be null
        `valueMatcher` - the component that looks for patterns within string values to create alternative objects; may not be null

  - ### Method Detail

    - #### parseDocument

          public Document parseDocument()
                                 throws ParsingException

      Parse the stream for the next JSON document.
      Returns:
        the document, or null if there are no more documents
      Throws:
        `ParsingException` - if there is a problem parsing the value

    - #### parseDocument

          public Document parseDocument(boolean failIfNotValidDocument)
                                 throws ParsingException

      Parse the stream for the next JSON document.
      Parameters:
        `failIfNotValidDocument` - true if this method should throw an exception if the stream does not contain a valid document, or false if null should be returned if there is no valid document on the stream
      Returns:
        the document, or null if there are no more documents
      Throws:
        `ParsingException` - if there is a problem parsing the value

    - #### newDocument

          protected BasicDocument newDocument()

    - #### parseDocument

          protected Document parseDocument(AtomicBoolean hasReservedFieldNames,
                               boolean failIfNotValidDocument)
                                    throws ParsingException

      Parse the stream for the next JSON document.
      Parameters:
        `hasReservedFieldNames` - the flag that should be set if this document contains field names that are reserved
        `failIfNotValidDocument` - true if this method should throw an exception if the stream does not contain a valid document, or false if null should be returned if there is no valid document on the stream
      Returns:
        the document, or null if there are no more documents
      Throws:
        `ParsingException` - if there is a problem parsing the value

    - #### isReservedFieldName

          protected final boolean isReservedFieldName(String fieldName)

    - #### parseArray

          public BasicArray parseArray()
                                throws ParsingException

      Parse the JSON array on the stream, beginning with the '[' character until the ']' character, which is consumed.
      Returns:
        the array representation; never null but possibly an empty array
      Throws:
        `ParsingException` - if there is a problem parsing the value

    - #### parseValue

          public Object parseValue()
                            throws ParsingException

      Parse the stream for the next field value, which can be one of the following values:
      - a nested document
      - an array of values
      - a string literal, surrounded by single-quote characters
      - a string literal, surrounded by double-quote characters
      - a string literal date of the form `"yyyy-MM-ddTHH:mm:ss"` where `T` is a literal character
      - a string literal date of the form `"yyyy-MM-ddTHH:mm:ssZ"` where `T` and `Z` are literal characters
      - a string literal date of the form `"yyyy-MM-ddTHH:mm:ssGMT+00:00"` where `T`, and `GMT` are literal characters
      - a string literal date of the form `"/Date(millisOrIso)/"`
      - a string literal date of the form `"\/Date(millisOrIso)\/"`
      - a date literal of the form `new Date(millisOrIso)`
      - a date literal of the form `Date(millisOrIso)`
      - a function of the form `new functionName(parameters)` where `parameters` consists of one or more values as parsed by this method
      Note that in the date forms listed above, `millisOrIso` is either a long value representing the number of milliseconds since epoch or a string literal in ISO-8601 format representing a date and time.
      Returns:
        the field value
      Throws:
        `ParsingException` - if there is a problem parsing the value

    - #### parseValue

          public Object parseValue(String value,
                          int lineNumber,
                          int columnNumber)
                            throws ParsingException

      Parse the value given by the supplied string located at the supplied line and column numbers. This method looks for known constant values, then attempts to parse the value as a number, and then calls `parseUnknownValue(String, int, int)`.
      Parameters:
        `value` - the string representation of the value
        `lineNumber` - the line number for the beginning of the value
        `columnNumber` - the column number for the beginning of the value
      Returns:
        the value
      Throws:
        `ParsingException` - if there is a problem parsing the value

    - #### parseNumber

          protected Number parseNumber(String value)

      Parse the number represented by the supplied value. This method is called by the `parseValue(String, int, int)` method.
      Parameters:
        `value` - the string representation of the value
      Returns:
        the number, or null if the value could not be parsed

    - #### parseUnknownValue

          protected Object parseUnknownValue(String value,
                                 int lineNumber,
                                 int columnNumber)
                                      throws ParsingException

      Override this method if custom value types are expected.
      Parameters:
        `value` - the string representation of the value
        `lineNumber` - the line number at which the value starts
        `columnNumber` - the column number at which the value starts
      Returns:
        the value
      Throws:
        `ParsingException` - if there is a problem parsing the value

    - #### parseFunction

          public Object parseFunction()
                               throws ParsingException

      Parse a function call on the stream. The 'new' keyword has already been processed.
      Returns:
        the result of the evaluation of the function
      Throws:
        `ParsingException` - if there is a problem parsing the value

    - #### evaluateFunction

          public Object evaluateFunction(JsonReader.Parser.FunctionCall function)
                                  throws ParsingException

      Method that is called to evaluate the supplied function. This method may be overridden by subclasses to handle custom functions.
      Parameters:
        `function` - the function definition
      Returns:
        the value that resulted from evaluating the function, or null if the function call could not be evaluated
      Throws:
        `ParsingException` - if there is a problem parsing the value

    - #### evaluateUnknownFunction

          protected Object evaluateUnknownFunction(JsonReader.Parser.FunctionCall function)
                                            throws ParsingException

      Method that is called when the function call described by the parameter could not be evaluated. By default, the string representation of the function is returned.
      Parameters:
        `function` - the function definition
      Returns:
        the value that resulted from evaluating the function
      Throws:
        `ParsingException` - if there is a problem parsing the value

    - #### processDocumentWithReservedFieldNames

          protected Object processDocumentWithReservedFieldNames(Document doc)

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.