Class Script
- java.lang.Object
-
- org.apache.commons.jexl3.internal.Script
-
- All Implemented Interfaces:
JexlExpression
,JexlScript
- Direct Known Subclasses:
Closure
public class Script extends java.lang.Object implements JexlScript, JexlExpression
A JexlScript implementation.
- Since:
- 1.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Script.Callable
Implements the Future and Callable interfaces to help delegation.
-
Field Summary
Fields Modifier and Type Field Description protected Engine
jexl
The engine for this expression.protected ASTJexlScript
script
The resulting AST we can interpret.protected java.lang.String
source
Original expression stripped from leading and trailing spaces.protected int
version
The engine version (as class loader change count) that last evaluated this script.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Script(Engine engine, java.lang.String expr, ASTJexlScript ref)
Do not let this be generally instantiated with a 'new'.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Script.Callable
callable(JexlContext context)
Creates a Callable from this script.Script.Callable
callable(JexlContext context, java.lang.Object... args)
Creates a Callable from this script.protected void
checkCacheVersion()
Checks that this script cached methods (wrt introspection) matches the engine version.protected Frame
createFrame(java.lang.Object[] args)
Creates this script frame for evaluation.protected Interpreter
createInterpreter(JexlContext context, Frame frame)
Creates this script interpreter.protected Interpreter
createInterpreter(JexlContext context, Frame frame, JexlOptions options)
Creates this script interpreter.JexlScript
curry(java.lang.Object... args)
Curries this script, returning a script with bound arguments.boolean
equals(java.lang.Object obj)
java.lang.Object
evaluate(JexlContext context)
Evaluates the expression with the variables contained in the suppliedJexlContext
.java.lang.Object
execute(JexlContext context)
Executes the script with the variables contained in the suppliedJexlContext
.java.lang.Object
execute(JexlContext context, java.lang.Object... args)
Executes the script with the variables contained in the suppliedJexlContext
and a set of arguments corresponding to the parameters used during parsing.java.lang.String[]
getCapturedVariables()
Gets this script captured variable, i.e.JexlEngine
getEngine()
JexlFeatures
getFeatures()
JexlInfo
getInfo()
java.lang.String[]
getLocalVariables()
Gets this script local variables.java.lang.String[]
getParameters()
Gets this script parameters.java.lang.String
getParsedText()
Recreates the source text of this expression from the internal syntactic tree.java.lang.String
getParsedText(int indent)
Recreates the source text of this expression from the internal syntactic tree.java.util.Map<java.lang.String,java.lang.Object>
getPragmas()
Gets this script pragmasprotected ASTJexlScript
getScript()
java.lang.String
getSourceText()
Returns the source text of this expression.java.lang.String[]
getUnboundParameters()
Gets this script unbound parameters.java.util.Set<java.util.List<java.lang.String>>
getVariables()
Gets this script variables.int
hashCode()
java.lang.String
toString()
-
-
-
Field Detail
-
jexl
protected final Engine jexl
The engine for this expression.
-
source
protected final java.lang.String source
Original expression stripped from leading and trailing spaces.
-
script
protected final ASTJexlScript script
The resulting AST we can interpret.
-
version
protected int version
The engine version (as class loader change count) that last evaluated this script.
-
-
Constructor Detail
-
Script
protected Script(Engine engine, java.lang.String expr, ASTJexlScript ref)
Do not let this be generally instantiated with a 'new'.- Parameters:
engine
- the interpreter to evaluate the expressionexpr
- the expression source.ref
- the parsed expression.
-
-
Method Detail
-
callable
public Script.Callable 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 interfaceJexlExpression
- Specified by:
callable
in interfaceJexlScript
- Parameters:
context
- the context- Returns:
- the callable
-
callable
public Script.Callable callable(JexlContext context, java.lang.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 interfaceJexlScript
- Parameters:
context
- the contextargs
- the script arguments- Returns:
- the callable
-
checkCacheVersion
protected void checkCacheVersion()
Checks that this script cached methods (wrt introspection) matches the engine version.If the engine class loader has changed since we last evaluated this script, the script local cache is invalidated to drop references to obsolete methods. It is not strictly necessary since the tryExecute will fail because the class won't match but it seems cleaner nevertheless.
-
createFrame
protected Frame createFrame(java.lang.Object[] args)
Creates this script frame for evaluation.- Parameters:
args
- the arguments to bind to parameters- Returns:
- the frame (may be null)
-
createInterpreter
protected Interpreter createInterpreter(JexlContext context, Frame frame)
Creates this script interpreter.- Parameters:
context
- the contextframe
- the calling frame- Returns:
- the interpreter
-
createInterpreter
protected Interpreter createInterpreter(JexlContext context, Frame frame, JexlOptions options)
Creates this script interpreter.- Parameters:
context
- the contextframe
- the calling frameoptions
- the interpreter options- Returns:
- the interpreter
-
curry
public JexlScript curry(java.lang.Object... args)
Description copied from interface:JexlScript
Curries this script, returning a script with bound arguments.If this script does not declare parameters or if all of them are already bound, no error is generated and this script is returned.
- Specified by:
curry
in interfaceJexlScript
- Parameters:
args
- the arguments to bind- Returns:
- the curried script or this script if no binding can occur
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
evaluate
public java.lang.Object evaluate(JexlContext context)
Description copied from interface:JexlExpression
Evaluates the expression with the variables contained in the suppliedJexlContext
.- Specified by:
evaluate
in interfaceJexlExpression
- Parameters:
context
- A JexlContext containing variables.- Returns:
- The result of this evaluation
-
execute
public java.lang.Object execute(JexlContext context)
Description copied from interface:JexlScript
Executes the script with the variables contained in the suppliedJexlContext
.- Specified by:
execute
in interfaceJexlScript
- Parameters:
context
- A JexlContext containing variables.- Returns:
- The result of this script, usually the result of the last statement.
-
execute
public java.lang.Object execute(JexlContext context, java.lang.Object... args)
Description copied from interface:JexlScript
Executes the script with the variables contained in the suppliedJexlContext
and a set of arguments corresponding to the parameters used during parsing.- Specified by:
execute
in interfaceJexlScript
- Parameters:
context
- A JexlContext containing variables.args
- the arguments- Returns:
- The result of this script, usually the result of the last statement.
-
getCapturedVariables
public java.lang.String[] getCapturedVariables()
Gets this script captured variable, i.e. symbols captured from outer scopes.- Returns:
- the captured variable names
-
getEngine
public JexlEngine getEngine()
- Returns:
- the engine that created this script
-
getFeatures
public JexlFeatures getFeatures()
- Returns:
- the script features
-
getInfo
public JexlInfo getInfo()
- Returns:
- the info
-
getLocalVariables
public java.lang.String[] getLocalVariables()
Description copied from interface:JexlScript
Gets this script local variables.- Specified by:
getLocalVariables
in interfaceJexlScript
- Returns:
- the local variables or null
-
getParameters
public java.lang.String[] getParameters()
Description copied from interface:JexlScript
Gets this script parameters.- Specified by:
getParameters
in interfaceJexlScript
- Returns:
- the parameters or null
-
getParsedText
public java.lang.String getParsedText()
Description copied from interface:JexlScript
Recreates the source text of this expression from the internal syntactic tree.- Specified by:
getParsedText
in interfaceJexlExpression
- Specified by:
getParsedText
in interfaceJexlScript
- Returns:
- the source text
-
getParsedText
public java.lang.String getParsedText(int indent)
Description copied from interface:JexlScript
Recreates the source text of this expression from the internal syntactic tree.- Specified by:
getParsedText
in interfaceJexlScript
- Parameters:
indent
- the number of spaces for indentation, 0 meaning no indentation- Returns:
- the source text
-
getPragmas
public java.util.Map<java.lang.String,java.lang.Object> getPragmas()
Gets this script pragmasPragma keys are ant-ish variables, their values are scalar literals..
- Specified by:
getPragmas
in interfaceJexlScript
- Returns:
- the pragmas
-
getScript
protected ASTJexlScript getScript()
- Returns:
- the script AST
-
getSourceText
public java.lang.String getSourceText()
Description copied from interface:JexlScript
Returns the source text of this expression.- Specified by:
getSourceText
in interfaceJexlExpression
- Specified by:
getSourceText
in interfaceJexlScript
- Returns:
- the source text
-
getUnboundParameters
public java.lang.String[] getUnboundParameters()
Description copied from interface:JexlScript
Gets this script unbound parameters.Parameters that haven't been bound by a previous call to curry().
- Specified by:
getUnboundParameters
in interfaceJexlScript
- Returns:
- the parameters or null
-
getVariables
public java.util.Set<java.util.List<java.lang.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 interfaceJexlScript
- Returns:
- the variables or null
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-