Top Description Inners Fields Constructors Methods
org.apache.commons.jexl2.scripting

public Class JexlScriptEngine

extends AbstractScriptEngine
implements Compilable
Class Inheritance
All Implemented Interfaces
javax.script.Compilable
Imports
java.io.IOException, .PrintWriter, .Reader, .Writer, javax.script.AbstractScriptEngine, .Bindings, .Compilable, .CompiledScript, .ScriptContext, .ScriptEngine, .ScriptEngineFactory, .ScriptException, .SimpleBindings, org.apache.commons.jexl2.JexlContext, .JexlEngine, .Script, org.apache.commons.logging.Log, .LogFactory

Implements the Jexl ScriptEngine for JSF-223.

This implementation gives access to both ENGINE_SCOPE and GLOBAL_SCOPE bindings. When a JEXL script accesses a variable for read or write, this implementation checks first ENGINE and then GLOBAL scope. The first one found is used. If no variable is found, and the JEXL script is writing to a variable, it will be stored in the ENGINE scope.

The implementation also creates the "JEXL" script object as an instance of the class JexlScriptObject for access to utility methods and variables.

See Java Scripting API Javadoc.
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
JexlScriptEngine.EngineSingletonHolder

Holds singleton JexlScriptEngine (IODH).

private static class
JexlScriptEngine.FactorySingletonHolder

Holds singleton JexlScriptEngineFactory (IODH).

private class
JexlScriptEngine.JexlCompiledScript

Wrapper to help convert a Jexl Script into a JSR-223 CompiledScript.

private class
JexlScriptEngine.JexlContextWrapper

Wrapper to help convert a JSR-223 ScriptContext into a JexlContext.

public class
JexlScriptEngine.JexlScriptObject

Implements engine and engine context properties for use by JEXL scripts.

Field Summary

Modifier and TypeField and Description
private static final int
CACHE_SIZE

The shared expression cache size.

public static final String
CONTEXT_KEY

Reserved key for context (mandated by JSR-223).

public static final String
JEXL_OBJECT_KEY

Reserved key for JexlScriptObject.

private final JexlEngine
jexlEngine

The JEXL EL engine.

private final JexlScriptEngine.JexlScriptObject
jexlObject

The JexlScriptObject instance.

private static final Log
LOG

The logger.

private final ScriptEngineFactory
parentFactory

The factory which created this instance.

Inherited from javax.script.AbstractScriptEngine:
context

Constructor Summary

AccessConstructor and Description
public
JexlScriptEngine()

Default constructor.

public
JexlScriptEngine(final ScriptEngineFactory
the factory which created this instance.
factory
)

Create a scripting engine using the supplied factory.

Method Summary

Modifier and TypeMethod and Description
public CompiledScript
compile(final String
The source of the script, represented as a String.
script
)

Implements javax.script.Compilable.compile.

Compiles the script (source represented as a String) for later execution.
public CompiledScript
compile(final Reader
The reader from which the script source is obtained.
script
)

Implements javax.script.Compilable.compile.

Compiles the script (source read from Reader) for later execution.
public Bindings
createBindings()

Implements javax.script.ScriptEngine.createBindings.

Returns an uninitialized Bindings.
public Object
eval(final Reader
The source of the script to be executed by the script engine.
reader
,
final ScriptContext
The ScriptContext passed to the script engine.
context
)

Implements javax.script.ScriptEngine.eval.

Same as eval(String, ScriptContext) where the source of the script is read from a Reader.
public Object
eval(final String
The script to be executed by the script engine.
script
,
final ScriptContext
A ScriptContext exposing sets of attributes in different scopes. The meanings of the scopes ScriptContext.GLOBAL_SCOPE, and ScriptContext.ENGINE_SCOPE are defined in the specification.

The ENGINE_SCOPE Bindings of the ScriptContext contains the bindings of scripting variables to application objects to be used during this script execution.
context
)

Implements javax.script.ScriptEngine.eval.

Causes the immediate execution of the script whose source is the String passed as the first argument.
public ScriptEngineFactory
getFactory()

Implements javax.script.ScriptEngine.getFactory.

Returns a ScriptEngineFactory for the class to which this ScriptEngine belongs.
private String

Returns:

the script as a string
readerToString
(final Reader
the script reader
script
)

Reads a script.

Inherited from javax.script.AbstractScriptEngine:
evalevalevalevalgetgetBindingsgetContextgetScriptContextputsetBindingssetContext

Field Detail

CACHE_SIZEback to summary
private static final int CACHE_SIZE

The shared expression cache size.

CONTEXT_KEYback to summary
public static final String CONTEXT_KEY

Reserved key for context (mandated by JSR-223).

JEXL_OBJECT_KEYback to summary
public static final String JEXL_OBJECT_KEY

Reserved key for JexlScriptObject.

jexlEngineback to summary
private final JexlEngine jexlEngine

The JEXL EL engine.

jexlObjectback to summary
private final JexlScriptEngine.JexlScriptObject jexlObject

The JexlScriptObject instance.

LOGback to summary
private static final Log LOG

The logger.

parentFactoryback to summary
private final ScriptEngineFactory parentFactory

The factory which created this instance.

Constructor Detail

JexlScriptEngineback to summary
public JexlScriptEngine()

Default constructor.

Only intended for use when not using a factory. Sets the factory to JexlScriptEngineFactory.

JexlScriptEngineback to summary
public JexlScriptEngine(final ScriptEngineFactory factory)

Create a scripting engine using the supplied factory.

Parameters
factory:ScriptEngineFactory

the factory which created this instance.

Exceptions
NullPointerException:
if factory is null

Method Detail

compileback to summary
public CompiledScript compile(final String script) throws ScriptException

Implements javax.script.Compilable.compile.

Doc from javax.script.Compilable.compile.

Compiles the script (source represented as a String) for later execution.

Parameters
script:String

The source of the script, represented as a String.

Returns:CompiledScript

An instance of a subclass of CompiledScript to be executed later using one of the eval methods of CompiledScript.

Exceptions
ScriptException:
if compilation fails.
compileback to summary
public CompiledScript compile(final Reader script) throws ScriptException

Implements javax.script.Compilable.compile.

Doc from javax.script.Compilable.compile.

Compiles the script (source read from Reader) for later execution. Functionality is identical to compile(String) other than the way in which the source is passed.

Parameters
script:Reader

The reader from which the script source is obtained.

Returns:CompiledScript

An instance of a subclass of CompiledScript to be executed later using one of its eval methods of CompiledScript.

Exceptions
ScriptException:
if compilation fails.
createBindingsback to summary
public Bindings createBindings()

Implements javax.script.ScriptEngine.createBindings.

Doc from javax.script.ScriptEngine.createBindings.

Returns an uninitialized Bindings.

Returns:Bindings

A Bindings that can be used to replace the state of this ScriptEngine.

evalback to summary
public Object eval(final Reader reader, final ScriptContext context) throws ScriptException

Implements javax.script.ScriptEngine.eval.

Doc from javax.script.ScriptEngine.eval.

Same as eval(String, ScriptContext) where the source of the script is read from a Reader.

Parameters
reader:Reader

The source of the script to be executed by the script engine.

context:ScriptContext

The ScriptContext passed to the script engine.

Returns:Object

The value returned from the execution of the script.

Exceptions
ScriptException:
if an error occurs in script. ScriptEngines should create and throw ScriptException wrappers for checked Exceptions thrown by underlying scripting implementations.
evalback to summary
public Object eval(final String script, final ScriptContext context) throws ScriptException

Implements javax.script.ScriptEngine.eval.

Doc from javax.script.ScriptEngine.eval.

Causes the immediate execution of the script whose source is the String passed as the first argument. The script may be reparsed or recompiled before execution. State left in the engine from previous executions, including variable values and compiled procedures may be visible during this execution.

Parameters
script:String

The script to be executed by the script engine.

context:ScriptContext

A ScriptContext exposing sets of attributes in different scopes. The meanings of the scopes ScriptContext.GLOBAL_SCOPE, and ScriptContext.ENGINE_SCOPE are defined in the specification.

The ENGINE_SCOPE Bindings of the ScriptContext contains the bindings of scripting variables to application objects to be used during this script execution.

Returns:Object

The value returned from the execution of the script.

Exceptions
ScriptException:
if an error occurs in script. ScriptEngines should create and throw ScriptException wrappers for checked Exceptions thrown by underlying scripting implementations.
getFactoryback to summary
public ScriptEngineFactory getFactory()

Implements javax.script.ScriptEngine.getFactory.

Doc from javax.script.ScriptEngine.getFactory.

Returns a ScriptEngineFactory for the class to which this ScriptEngine belongs.

Returns:ScriptEngineFactory

The ScriptEngineFactory

readerToStringback to summary
private String readerToString(final Reader script) throws ScriptException

Reads a script.

Parameters
script:Reader

the script reader

Returns:String

the script as a string

Exceptions
ScriptException:
if an exception occurs during read
org.apache.commons.jexl2.scripting back to summary

private Class JexlScriptEngine.EngineSingletonHolder

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.jexl2.scripting.JexlScriptEngine.EngineSingletonHolder

Holds singleton JexlScriptEngine (IODH).

A single JEXL engine and Uberspect is shared by all instances of JexlScriptEngine.

Field Summary

Modifier and TypeField and Description
private static final JexlEngine
DEFAULT_ENGINE

The JEXL engine singleton instance.

Constructor Summary

AccessConstructor and Description
private
EngineSingletonHolder()

non instantiable.

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_ENGINEback to summary
private static final JexlEngine DEFAULT_ENGINE

The JEXL engine singleton instance.

Constructor Detail

EngineSingletonHolderback to summary
private EngineSingletonHolder()

non instantiable.

org.apache.commons.jexl2.scripting back to summary

private Class JexlScriptEngine.FactorySingletonHolder

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.jexl2.scripting.JexlScriptEngine.FactorySingletonHolder

Holds singleton JexlScriptEngineFactory (IODH).

Field Summary

Modifier and TypeField and Description
private static final JexlScriptEngineFactory
DEFAULT_FACTORY

The engine factory singleton instance.

Constructor Summary

AccessConstructor and Description
private
FactorySingletonHolder()

non instantiable.

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_FACTORYback to summary
private static final JexlScriptEngineFactory DEFAULT_FACTORY

The engine factory singleton instance.

Constructor Detail

FactorySingletonHolderback to summary
private FactorySingletonHolder()

non instantiable.

org.apache.commons.jexl2.scripting back to summary

private final Class JexlScriptEngine.JexlCompiledScript

extends CompiledScript
Class Inheritance

Wrapper to help convert a Jexl Script into a JSR-223 CompiledScript.

Field Summary

Modifier and TypeField and Description
private final Script
script

The underlying Jexl expression instance.

Constructor Summary

AccessConstructor and Description
private
JexlCompiledScript(final Script
to wrap
theScript
)

Creates an instance.

Method Summary

Modifier and TypeMethod and Description
public Object
eval(final ScriptContext
A ScriptContext that is used in the same way as the ScriptContext passed to the eval methods of ScriptEngine.
context
)

Implements abstract javax.script.CompiledScript.eval.

Executes the program stored in this CompiledScript object.
public ScriptEngine
getEngine()

Implements abstract javax.script.CompiledScript.getEngine.

Returns the ScriptEngine whose compile method created this CompiledScript.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from javax.script.CompiledScript:
evaleval

Field Detail

scriptback to summary
private final Script script

The underlying Jexl expression instance.

Constructor Detail

JexlCompiledScriptback to summary
private JexlCompiledScript(final Script theScript)

Creates an instance.

Parameters
theScript:Script

to wrap

Method Detail

evalback to summary
public Object eval(final ScriptContext context) throws ScriptException

Implements abstract javax.script.CompiledScript.eval.

Doc from javax.script.CompiledScript.eval.

Executes the program stored in this CompiledScript object.

Parameters
context:ScriptContext

A ScriptContext that is used in the same way as the ScriptContext passed to the eval methods of ScriptEngine.

Returns:Object

The value returned by the script execution, if any. Should return null if no value is returned by the script execution.

Annotations
@Override
Exceptions
ScriptException:
if an error occurs.
getEngineback to summary
public ScriptEngine getEngine()

Implements abstract javax.script.CompiledScript.getEngine.

Doc from javax.script.CompiledScript.getEngine.

Returns the ScriptEngine whose compile method created this CompiledScript. The CompiledScript will execute in this engine.

Returns:ScriptEngine

The ScriptEngine that created this CompiledScript

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.apache.commons.jexl2.scripting back to summary

private final Class JexlScriptEngine.JexlContextWrapper

extends Object
implements JexlContext
Class Inheritance
  • java.lang.Object
  • org.apache.commons.jexl2.scripting.JexlScriptEngine.JexlContextWrapper
All Implemented Interfaces
org.apache.commons.jexl2.JexlContext

Wrapper to help convert a JSR-223 ScriptContext into a JexlContext. Current implementation only gives access to ENGINE_SCOPE binding.

Field Summary

Modifier and TypeField and Description
private final ScriptContext
scriptContext

The wrapped script context.

Constructor Summary

AccessConstructor and Description
private
JexlContextWrapper(final ScriptContext
the engine context.
theContext
)

Creates a context wrapper.

Method Summary

Modifier and TypeMethod and Description
public Object
get(final String
the variable's name
name
)

Implements org.apache.commons.jexl2.JexlContext.get.

Gets the value of a variable.
public boolean
has(final String
the variable's name
name
)

Implements org.apache.commons.jexl2.JexlContext.has.

Checks whether a variable is defined in this context.
public void
set(final String
the variable's name
name
,
final Object
the variable's value
value
)

Implements org.apache.commons.jexl2.JexlContext.set.

Sets the value of a variable.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

scriptContextback to summary
private final ScriptContext scriptContext

The wrapped script context.

Constructor Detail

JexlContextWrapperback to summary
private JexlContextWrapper(final ScriptContext theContext)

Creates a context wrapper.

Parameters
theContext:ScriptContext

the engine context.

Method Detail

getback to summary
public Object get(final String name)

Implements org.apache.commons.jexl2.JexlContext.get.

Doc from org.apache.commons.jexl2.JexlContext.get.

Gets the value of a variable.

Parameters
name:String

the variable's name

Returns:Object

the value

hasback to summary
public boolean has(final String name)

Implements org.apache.commons.jexl2.JexlContext.has.

Doc from org.apache.commons.jexl2.JexlContext.has.

Checks whether a variable is defined in this context.

A variable may be defined with a null value; this method checks whether the value is null or if the variable is undefined.

Parameters
name:String

the variable's name

Returns:boolean

true if it exists, false otherwise

setback to summary
public void set(final String name, final Object value)

Implements org.apache.commons.jexl2.JexlContext.set.

Doc from org.apache.commons.jexl2.JexlContext.set.

Sets the value of a variable.

Parameters
name:String

the variable's name

value:Object

the variable's value

org.apache.commons.jexl2.scripting back to summary

public Class JexlScriptEngine.JexlScriptObject

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.jexl2.scripting.JexlScriptEngine.JexlScriptObject

Implements engine and engine context properties for use by JEXL scripts. Those properties are allways bound to the default engine scope context.

The following properties are defined:

Since
2.0

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public JexlEngine

Returns:

the shared underlying JEXL engine
getEngine
()

Gives access to the underlying JEXL engine shared between all ScriptEngine instances.

public PrintWriter

Returns:

the engine error writer
getErr
()

Gives access to the engine scope error writer (defaults to System.err).

public Reader

Returns:

the engine input reader
getIn
()

Gives access to the engine scope input reader (defaults to System.in).

public Log

Returns:

the JexlScriptEngine logger
getLogger
()

Gives access to the engine logger.

public PrintWriter

Returns:

the engine output writer
getOut
()

Gives access to the engine scope output writer (defaults to System.out).

public Class<System>

Returns:

System.class
getSystem
()

Gives access to System class.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

JexlScriptObjectback to summary
public JexlScriptObject()

Method Detail

getEngineback to summary
public JexlEngine getEngine()

Gives access to the underlying JEXL engine shared between all ScriptEngine instances.

Although this allows to manipulate various engine flags (lenient, debug, cache...) for all JexlScriptEngine instances, you probably should only do so if you are in strict control and sole user of the Jexl scripting feature.

Returns:JexlEngine

the shared underlying JEXL engine

getErrback to summary
public PrintWriter getErr()

Gives access to the engine scope error writer (defaults to System.err).

Returns:PrintWriter

the engine error writer

getInback to summary
public Reader getIn()

Gives access to the engine scope input reader (defaults to System.in).

Returns:Reader

the engine input reader

getLoggerback to summary
public Log getLogger()

Gives access to the engine logger.

Returns:Log

the JexlScriptEngine logger

getOutback to summary
public PrintWriter getOut()

Gives access to the engine scope output writer (defaults to System.out).

Returns:PrintWriter

the engine output writer

getSystemback to summary
public Class<System> getSystem()

Gives access to System class.

Returns:Class<System>

System.class