Class ElementPathEvaluator

java.lang.Object
com.inductiveautomation.ignition.common.expressions.ElementPathEvaluator

public class ElementPathEvaluator extends Object
Evaluates a JSON-style path (e.g. event.data.foo[0].bar) against a document-like object, using an ElementExtractor to navigate whatever concrete representation the object has (JSON, Document, Python dictionary, etc.).

The caller resolves the object for some number of leading elements (possibly zero) and passes that count; traversal skips that many elements and walks the rest. The path is parsed and its per-element path strings precomputed once at construction, so a single instance can cheaply evaluate many objects (e.g. one per event).

  • Method Details

    • fromString

      public static ElementPathEvaluator fromString(String jsonPath) throws IllegalArgumentException
      Creates an evaluator for the given path.
      Parameters:
      jsonPath - the path to evaluate, e.g. event.data.foo[0].bar.
      Returns:
      a new evaluator for the path.
      Throws:
      IllegalArgumentException - if the path cannot be parsed.
    • jsonPath

      public JsonPath jsonPath()
      Returns:
      the parsed path
    • keys

      public Object[] keys()
      Returns:
      the key of each path element in order: a String for map keys, an Integer for array indices. Empty if the path could not be parsed.
    • extractData

      public <T> QualifiedValue extractData(int skipCount, @Nullable T dict, ElementExtractor<T> extractor)
      Traverses this evaluator's path into the given object, skipping the leading elements the caller already resolved.
      Parameters:
      skipCount - the number of leading path elements already resolved to dict (e.g. 2 when dict is the object at event.data of path event.data.foo), or 0 if dict is the root of the whole path.
      dict - the object the remaining path elements are traversed into, possibly null.
      extractor - the extractor that knows how to navigate dict's representation.
      Returns:
      the value at the path, converted to a plain Java object if primitive; or an QualifiedValue.EXPRESSION_EVAL_ERROR-derived value if dict is null, the skip count is out of the path's range, or an element along the path is missing, null, or not the expected map/array type.