org.apache.commons.jexl2
Class ExpressionImpl

java.lang.Object
  extended by org.apache.commons.jexl2.ExpressionImpl
All Implemented Interfaces:
Expression, Script

public class ExpressionImpl
extends Object
implements Expression, Script

Instances of ExpressionImpl are created by the JexlEngine, and this is the default implementation of the Expression and Script interface.

Since:
1.0

Field Summary
protected  String expression
          Original expression stripped from leading & trailing spaces.
protected  JexlEngine jexl
          The engine for this expression.
protected  ASTJexlScript script
          The resulting AST we can interpret.
 
Constructor Summary
protected ExpressionImpl(JexlEngine engine, String expr, ASTJexlScript ref)
          Do not let this be generally instantiated with a 'new'.
 
Method Summary
 Callable<Object> callable(JexlContext context)
          Creates a Callable from this script.
 Callable<Object> callable(JexlContext context, Object... args)
          Creates a Callable from this script.
 String dump()
          Returns the JEXL expression by reconstructing it from the parsed tree.
 Object evaluate(JexlContext context)
          Evaluates the expression with the variables contained in the supplied JexlContext.
 Object execute(JexlContext context)
          Executes the script with the variables contained in the supplied JexlContext.
 Object execute(JexlContext context, Object... args)
          Executes the script with the variables contained in the supplied JexlContext and a set of arguments corresponding to the parameters used during parsing.
 String getExpression()
          Returns the JEXL expression this Expression was created with.
 String[] getLocalVariables()
          Gets this script local variables.
 String[] getParameters()
          Gets this script parameters.
 String getText()
          Returns the text of this Script.
 Set<List<String>> getVariables()
          Gets this script variables.
 String toString()
          Provide a string representation of this expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

jexl

protected final JexlEngine jexl
The engine for this expression.


expression

protected final String expression
Original expression stripped from leading & trailing spaces.


script

protected final ASTJexlScript script
The resulting AST we can interpret.

Constructor Detail

ExpressionImpl

protected ExpressionImpl(JexlEngine engine,
                         String expr,
                         ASTJexlScript ref)
Do not let this be generally instantiated with a 'new'.

Parameters:
engine - the interpreter to evaluate the expression
expr - the expression.
ref - the parsed expression.
Method Detail

evaluate

public Object evaluate(JexlContext context)
Evaluates the expression with the variables contained in the supplied JexlContext.

Specified by:
evaluate in interface Expression
Parameters:
context - A JexlContext containing variables.
Returns:
The result of this evaluation

dump

public String dump()
Returns the JEXL expression by reconstructing it from the parsed tree.

Specified by:
dump in interface Expression
Returns:
the JEXL expression

getExpression

public String getExpression()
Returns the JEXL expression this Expression was created with.

Specified by:
getExpression in interface Expression
Returns:
The JEXL expression to be evaluated

toString

public String toString()
Provide a string representation of this expression.

Overrides:
toString in class Object
Returns:
the expression or blank if it's null.

getText

public String getText()
Returns the text of this Script.

Specified by:
getText in interface Script
Returns:
The script to be executed.

execute

public Object execute(JexlContext context)
Executes the script with the variables contained in the supplied JexlContext.

Specified by:
execute in interface Script
Parameters:
context - A JexlContext containing variables.
Returns:
The result of this script, usually the result of the last statement.

execute

public Object execute(JexlContext context,
                      Object... args)
Executes the script with the variables contained in the supplied JexlContext and a set of arguments corresponding to the parameters used during parsing.

Specified by:
execute in interface Script
Parameters:
context - A JexlContext containing variables.
args - the arguments
Returns:
The result of this script, usually the result of the last statement.
Since:
2.1

getParameters

public String[] getParameters()
Gets this script parameters.

Specified by:
getParameters in interface Script
Returns:
the parameters or null
Since:
2.1

getLocalVariables

public String[] getLocalVariables()
Gets this script local variables.

Specified by:
getLocalVariables in interface Script
Returns:
the local variables or null
Since:
2.1

getVariables

public Set<List<String>> getVariables()
Gets this script variables.

Note that since variables can be in an ant-ish form (ie foo.bar.quux), each variable is returned as a list of strings where each entry is a fragment of the variable ({"foo", "bar", "quux"} in the example.

Specified by:
getVariables in interface Script
Returns:
the variables or null
Since:
2.1

callable

public Callable<Object> callable(JexlContext context)
Creates a Callable from this script.

This allows to submit it to an executor pool and provides support for asynchronous calls.

The interpreter will handle interruption/cancellation gracefully if needed.

Specified by:
callable in interface Script
Parameters:
context - the context
Returns:
the callable
Since:
2.1

callable

public Callable<Object> callable(JexlContext context,
                                 Object... args)
Creates a Callable from this script.

This allows to submit it to an executor pool and provides support for asynchronous calls.

The interpreter will handle interruption/cancellation gracefully if needed.

Specified by:
callable in interface Script
Parameters:
context - the context
args - the script arguments
Returns:
the callable
Since:
2.1


Copyright © 2001-2011 The Apache Software Foundation. All Rights Reserved.