Class ExpressionEngine


  • public final class ExpressionEngine
    extends Object
    It is a Utility class for XpressionEngine Framework. It provides utility methods for accessing various functionalities of the Framework. A few points to consider -If any of the sub-expression is returning Type.ANY_TYPE, i.e. type will be decided at runtime. -If any of the sub-expression is returning Type.ANY_TYPE, the whole expression will return Type.ANY_TYPE -If expression contains XML expression, XML document 'URL' should be set as property to Context before executing the expression -In case of XML expression, it will always return the String value as it does not have any way to identify the required type of the value - To override all above, currently we are getting only string type value from XML expressions
    Since:
    3.1
    • Method Detail

      • getGrammar

        public static Grammar getGrammar()
      • evaluate

        public static Object evaluate​(String expression,
                                      ExpressionContext expressionContext)
                               throws ExpressionEngineException
        Evaluates the expression and returns the result
        Parameters:
        expression - the expression to evaluate
        expressionContext - the object contains the contextual information, which may be required for expression evaluation. It may be like an Java Bean in case of property expression
        Returns:
        the result of expression
        Throws:
        ExpressionEngineException - if unable to parse the expression
      • compileExpression

        public static Expression compileExpression​(String expression,
                                                   ExpressionContext expressionContext,
                                                   boolean validate)
                                            throws ExpressionEngineException
        Compiles the expression string and prepares the expression tree with relevant Expression's objects.
        Parameters:
        expression - the expression to compile
        expressionContext - the object contains the contextual information, which may be required for expression evaluation. It may be like an Java Bean in case of property expression
        validate - true if the operands should be validated
        Returns:
        compiled Expression object. It is actually a tree of Expression Objects
        Throws:
        ExpressionEngineException - if unable to compile the expression
      • getVariableNames

        public static Set<String> getVariableNames​(String expression)
                                            throws ExpressionEngineException
        Retrieves a set of variable names contained within the specified expression string
        Parameters:
        expression - the expression to extract the variable names for
        Returns:
        a set of variable names contained within the specified expression string
        Throws:
        ExpressionEngineException