Class Expression

    • Constructor Summary

      Constructors 
      Constructor Description
      Expression​(String expression)
      Constructor for Expression
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void assign​(Binding binding)
      Assign the binding to the environment preparing for evaluation
      void assign​(String varname, String expression)
      Assign the expression (variable or function declaration) to the variable name supplied
      void clear()
      Remove all bindings
      static List<Binding> createBindings​(com.fasterxml.jackson.databind.JsonNode bindingObj)
      Establish a list of bindings for the given json object
      com.fasterxml.jackson.databind.JsonNode evaluate​(com.fasterxml.jackson.databind.JsonNode rootContext)
      Generate a result form the Expression's parsed expression and variable assignments or registered functions
      com.fasterxml.jackson.databind.JsonNode evaluate​(com.fasterxml.jackson.databind.JsonNode rootContext, com.fasterxml.jackson.databind.JsonNode bindingObj)
      Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the bindings object
      com.fasterxml.jackson.databind.JsonNode evaluate​(com.fasterxml.jackson.databind.JsonNode rootContext, List<Binding> bindings)
      Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings
      static Expression jsonata​(String expression)
      Genearte a new Expression based on evaluating the supplied expression
      static void main​(String[] args)
      Testing the various methods based on https://docs.jsonata.org/embedding-extending#expressionregisterfunctionname-implementation-signature
      void registerFunction​(String fctName, String implementation)
      Registers a function implementation (declaration) by name
    • Method Detail

      • jsonata

        public static Expression jsonata​(String expression)
                                  throws ParseException,
                                         IOException
        Genearte a new Expression based on evaluating the supplied expression
        Parameters:
        expression - the logic to be parsed for later execution via the evaluate methods
        Returns:
        new Expression object
        Throws:
        ParseException
        IOException
      • createBindings

        public static List<Binding> createBindings​(com.fasterxml.jackson.databind.JsonNode bindingObj)
        Establish a list of bindings for the given json object
        Parameters:
        bindingObj - the json to calculate the bindings for
        Returns:
        the list of bindings for the provided json
      • main

        public static void main​(String[] args)
        Testing the various methods based on https://docs.jsonata.org/embedding-extending#expressionregisterfunctionname-implementation-signature
        Parameters:
        args - not used
      • assign

        public void assign​(Binding binding)
        Assign the binding to the environment preparing for evaluation
        Parameters:
        binding -
      • clear

        public void clear()
        Remove all bindings
      • assign

        public void assign​(String varname,
                           String expression)
                    throws ParseException,
                           IOException
        Assign the expression (variable or function declaration) to the variable name supplied
        Parameters:
        varname - name of the variable to map to a variable expression or function declaration expression
        expression - logic to be assigned to the variable name
        Throws:
        ParseException
        IOException
      • evaluate

        public com.fasterxml.jackson.databind.JsonNode evaluate​(com.fasterxml.jackson.databind.JsonNode rootContext)
                                                         throws ParseException
        Generate a result form the Expression's parsed expression and variable assignments or registered functions
        Parameters:
        rootContext - JSON object specifying the content used to evaluate the expression
        Returns:
        the result from executing the Expression's parsed expression and variable assignments or registered functions
        Throws:
        ParseException
      • evaluate

        public com.fasterxml.jackson.databind.JsonNode evaluate​(com.fasterxml.jackson.databind.JsonNode rootContext,
                                                                List<Binding> bindings)
                                                         throws ParseException
        Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings
        Parameters:
        rootContext - JSON object specifying the content used to evaluate the expression
        bindings - assignments of variable names to variable expressions or function declarations
        Returns:
        the result from executing the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings
        Throws:
        ParseException
      • evaluate

        public com.fasterxml.jackson.databind.JsonNode evaluate​(com.fasterxml.jackson.databind.JsonNode rootContext,
                                                                com.fasterxml.jackson.databind.JsonNode bindingObj)
                                                         throws ParseException,
                                                                IOException
        Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the bindings object
        Parameters:
        rootContext - JSON object specifying the content used to evaluate the expression
        bindingObj - a JSON object containing the assignments of variable names to variable expressions or function declarations
        Returns:
        the result from executing the Expression's parsed expression and variable assignments or registered functions specified in the bindings object
        Throws:
        ParseException
        IOException
      • registerFunction

        public void registerFunction​(String fctName,
                                     String implementation)
                              throws ParseException,
                                     IOException
        Registers a function implementation (declaration) by name
        Parameters:
        fctName - the name of the function
        implementation - the function declaration
        Throws:
        ParseException
        IOException