Class JsonInputParser.JsonParseResult

java.lang.Object
de.iip_ecosphere.platform.connectors.parser.JsonInputParser.JsonParseResult
All Implemented Interfaces:
InputParser.ParseResult<de.iip_ecosphere.platform.support.json.JsonIterator>
Enclosing class:
JsonInputParser

public static final class JsonInputParser.JsonParseResult extends Object implements InputParser.ParseResult<de.iip_ecosphere.platform.support.json.JsonIterator>
Defines a parse result instance for JSON.
Author:
Holger Eichelberger, SSE
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private de.iip_ecosphere.platform.support.json.JsonIterator
     
    private byte[]
     
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    JsonParseResult(byte[] data)
    Creates a parse result instance.
    private
    JsonParseResult(byte[] data, de.iip_ecosphere.platform.support.json.JsonIterator any, JsonInputParser.JsonParseResult parent)
    Creates a parse result instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    private de.iip_ecosphere.platform.support.json.JsonIterator
    deserializeIfString(de.iip_ecosphere.platform.support.json.JsonIterator tmp)
    Deserializes tmp if it looks like a string.
    private de.iip_ecosphere.platform.support.json.JsonIterator.EntryIterator
    findBy(int index)
    Searches for the entry at position index.
    private de.iip_ecosphere.platform.support.json.JsonIterator.EntryIterator
    findBy(int[] indexes)
    Returns an entry iterator to the element denoted by (nested) indexes.
    private de.iip_ecosphere.platform.support.json.JsonIterator
    get(String name, int... indexes)
    Returns the JSON object representing name or indexes.
    int
    If the actual element is an array, return the size.
    void
    getData(de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonIterator> ifPresent, String name, int... indexes)
    Returns the value of the data field for the given field name or with via the given index.
    de.iip_ecosphere.platform.support.json.JsonIterator
    getData(String name, int... indexes)
    Returns the value of the data field for the given field name or with via the given index.
    int
    Returns the number of parsed data fields.
    getFieldName(de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonIterator> valueCons, int... indexes)
    Returns the name of the field.
    private de.iip_ecosphere.platform.support.json.JsonIterator
    getLocal(String name, int[] indexes)
    Returns the JSON object representing name or indexes without hierarchical name interpretation.
    void
    getLocalData(de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonIterator> ifPresent, String name, int... indexes)
    Returns the value of the data field for the given field name or with via the given index.
    de.iip_ecosphere.platform.support.json.JsonIterator
    getLocalData(String name, int... indexes)
    Returns the value of the data field for the given field name or with via the given index.
    private byte[]
    Returns the original input data array from the top-level parser result.
    stepInto(String name, int index)
    Sets the hierarchical substructure denoted by name as current scope for further resolution.
    Steps out of the actual context set by InputParser.ParseResult.stepInto(String, int).

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface de.iip_ecosphere.platform.connectors.parser.InputParser.ParseResult

    getFieldName
  • Field Details

  • Constructor Details

    • JsonParseResult

      private JsonParseResult(byte[] data)
      Creates a parse result instance.
      Parameters:
      data - the data to parse/deserialize
    • JsonParseResult

      private JsonParseResult(byte[] data, de.iip_ecosphere.platform.support.json.JsonIterator any, JsonInputParser.JsonParseResult parent)
      Creates a parse result instance.
      Parameters:
      data - the data to parse/deserialize
      any - the jsoniter object representing the context
      parent - the parent parse result to jump back to in stepOut().
  • Method Details

    • getDataCount

      public int getDataCount()
      Description copied from interface: InputParser.ParseResult
      Returns the number of parsed data fields.
      Specified by:
      getDataCount in interface InputParser.ParseResult<de.iip_ecosphere.platform.support.json.JsonIterator>
      Returns:
      the number of data fields (non-negative)
    • getFieldName

      public String getFieldName(de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonIterator> valueCons, int... indexes) throws IOException
      Description copied from interface: InputParser.ParseResult
      Returns the name of the field. This operation may not be efficient on all input parsers, in particular if no index positions are recorded. However, for generically parsing back some structures, this operation is required.
      Specified by:
      getFieldName in interface InputParser.ParseResult<de.iip_ecosphere.platform.support.json.JsonIterator>
      Parameters:
      valueCons - a value consumer to handle the value of the field (if found) in the same step, may be null for none
      indexes - the path of (nested) 0-based indexes to the field, the sum must be less than InputParser.ParseResult.getDataCount()
      Returns:
      the name of the field or empty if not known
      Throws:
      IOException - if applying valueCons leads to an exception
    • findBy

      private de.iip_ecosphere.platform.support.json.JsonIterator.EntryIterator findBy(int[] indexes)
      Returns an entry iterator to the element denoted by (nested) indexes.
      Parameters:
      indexes - the path of (nested) 0-based indexes to the field, the sum must be less than getDataCount()
      Returns:
      the input iterator, null for not found
    • deserializeIfString

      private de.iip_ecosphere.platform.support.json.JsonIterator deserializeIfString(de.iip_ecosphere.platform.support.json.JsonIterator tmp)
      Deserializes tmp if it looks like a string.
      Parameters:
      tmp - the any to be considered
      Returns:
      tmp or deserialized any
    • findBy

      private de.iip_ecosphere.platform.support.json.JsonIterator.EntryIterator findBy(int index)
      Searches for the entry at position index.
      Parameters:
      index - the index to search for
      Returns:
      the entry iterator pointing to the index or null for none
    • getData

      public de.iip_ecosphere.platform.support.json.JsonIterator getData(String name, int... indexes) throws IOException
      Description copied from interface: InputParser.ParseResult
      Returns the value of the data field for the given field name or with via the given index. Primary index goes via name and if not given/mapped, index-based access shall be used as fallback. Names may be hierarchical. May be overridden if direct access to names is provided by the parsed structure, e.g., in JSON. Thus, no index-access is provided in the first place by this interface.
      Specified by:
      getData in interface InputParser.ParseResult<de.iip_ecosphere.platform.support.json.JsonIterator>
      Parameters:
      name - the name of the data field, may contain hierarchical names separated by InputParser.SEPARATOR, may be based on the scope set by InputParser.ParseResult.stepInto(String, int)
      indexes - the path of (nested) 0-based indexes to the field, the sum must be less than InputParser.ParseResult.getDataCount()
      Returns:
      the data value
      Throws:
      IOException - if the mapped index or the given index<0 || index >= InputParser.ParseResult.getDataCount()
    • get

      private de.iip_ecosphere.platform.support.json.JsonIterator get(String name, int... indexes)
      Returns the JSON object representing name or indexes.
      Parameters:
      name - the name of the data field, may contain hierarchical names separated by InputParser.SEPARATOR, may be based on the scope set by stepInto(String, int)
      indexes - the path of (nested) 0-based indexes to the field, the sum must be less than getDataCount()
      Returns:
      the JSON object, may be null for not found
    • getData

      public void getData(de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonIterator> ifPresent, String name, int... indexes) throws IOException
      Description copied from interface: InputParser.ParseResult
      Returns the value of the data field for the given field name or with via the given index. Primary index goes via name and if not given/mapped, index-based access shall be used as fallback. Names may be hierarchical. May be overridden if direct access to names is provided by the parsed structure, e.g., in JSON. Thus, no index-access is provided in the first place by this interface. This method shall not throw any exception.
      Specified by:
      getData in interface InputParser.ParseResult<de.iip_ecosphere.platform.support.json.JsonIterator>
      Parameters:
      ifPresent - consumer called if a data value was found. The value is passed to ifPresent for further processing
      name - the name of the data field, may contain hierarchical names separated by InputParser.SEPARATOR, may be based on the scope set by InputParser.ParseResult.stepInto(String, int)
      indexes - the path of (nested) 0-based indexes to the field, the sum must be less than InputParser.ParseResult.getDataCount()
      Throws:
      IOException - if an
    • getLocal

      private de.iip_ecosphere.platform.support.json.JsonIterator getLocal(String name, int[] indexes)
      Returns the JSON object representing name or indexes without hierarchical name interpretation.
      Parameters:
      name - the name of the data field
      indexes - the path of (nested) 0-based indexes to the field, the sum must be less than getDataCount()
      Returns:
      the JSON object, may be null for not found
    • getLocalData

      public de.iip_ecosphere.platform.support.json.JsonIterator getLocalData(String name, int... indexes) throws IOException
      Description copied from interface: InputParser.ParseResult
      Returns the value of the data field for the given field name or with via the given index. Primary index goes via name and if not given/mapped, index-based access shall be used as fallback. No hierarchical name interpretation happens here (local). In combination with InputParser.ParseResult.stepInto(String, int), this method shall be faster than InputParser.ParseResult.getData(String, int...).
      Specified by:
      getLocalData in interface InputParser.ParseResult<de.iip_ecosphere.platform.support.json.JsonIterator>
      Parameters:
      name - the name of the data field
      indexes - the path of (nested) 0-based indexes to the field, the sum must be less than InputParser.ParseResult.getDataCount()
      Returns:
      the data value
      Throws:
      IOException - if the mapped index or the given index<0 || index >= InputParser.ParseResult.getDataCount()
    • getLocalData

      public void getLocalData(de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonIterator> ifPresent, String name, int... indexes) throws IOException
      Description copied from interface: InputParser.ParseResult
      Returns the value of the data field for the given field name or with via the given index. Primary index goes via name and if not given/mapped, index-based access shall be used as fallback. No hierarchical name interpretation happens here (local). In combination with InputParser.ParseResult.stepInto(String, int), this method shall be faster than InputParser.ParseResult.getData(IOConsumer, String, int...).
      Specified by:
      getLocalData in interface InputParser.ParseResult<de.iip_ecosphere.platform.support.json.JsonIterator>
      Parameters:
      ifPresent - consumer called if a data value was found. The value is passed to ifPresent for further processing
      name - the name of the data field
      indexes - the path of (nested) 0-based indexes to the field, the sum must be less than InputParser.ParseResult.getDataCount()
      Throws:
      IOException - if an exception occurred in ifPresent
    • stepInto

      public JsonInputParser.JsonParseResult stepInto(String name, int index) throws IOException
      Description copied from interface: InputParser.ParseResult
      Sets the hierarchical substructure denoted by name as current scope for further resolution. When overriding, declare the actual type as result type.
      Specified by:
      stepInto in interface InputParser.ParseResult<de.iip_ecosphere.platform.support.json.JsonIterator>
      Parameters:
      name - non-hierarchical name of contained substructure
      index - the 0-based indexes to the field, must be less than InputParser.ParseResult.getDataCount()
      Returns:
      the sub parse-result taking name as context, use #stepOut() to leave that context
      Throws:
      IOException - if stepping into fails for some reason
    • getTopData

      private byte[] getTopData()
      Returns the original input data array from the top-level parser result.
      Returns:
      the data
    • stepOut

      Description copied from interface: InputParser.ParseResult
      Steps out of the actual context set by InputParser.ParseResult.stepInto(String, int). When overriding, declare the actual type as result type.
      Specified by:
      stepOut in interface InputParser.ParseResult<de.iip_ecosphere.platform.support.json.JsonIterator>
      Returns:
      the actual (parent) context, may be null if this step out was illegal in a non-nested context
    • getArraySize

      public int getArraySize()
      Description copied from interface: InputParser.ParseResult
      If the actual element is an array, return the size.
      Specified by:
      getArraySize in interface InputParser.ParseResult<de.iip_ecosphere.platform.support.json.JsonIterator>
      Returns:
      the size, may be negative