APIdia Launch Partner
Top Description Fields Constructors Methods
javax.script

public abstract Class AbstractScriptEngine

extends Object
implements ScriptEngine
Class Inheritance
All Implemented Interfaces
javax.script.ScriptEngine
Imports
java.io.Reader

Provides a standard implementation for several of the variants of the eval method.

eval(Reader)

eval(String)

eval(String, Bindings)

eval(Reader, Bindings)

are implemented using the abstract methods

eval(Reader,ScriptContext) or eval(String, ScriptContext)

with a SimpleScriptContext.

A SimpleScriptContext is used as the default ScriptContext of the AbstractScriptEngine..

Author
Mike Grogan
Since
1.6

Field Summary

Modifier and TypeField and Description
protected ScriptContext
context

The default ScriptContext of this AbstractScriptEngine.

Constructor Summary

AccessConstructor and Description
public
AbstractScriptEngine()

Creates a new instance of AbstractScriptEngine using a SimpleScriptContext as its default ScriptContext.

public
AbstractScriptEngine(Bindings
The specified Bindings.
n
)

Creates a new instance using the specified Bindings as the ENGINE_SCOPE Bindings in the protected context field.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

The return value from eval(Reader, ScriptContext)
eval
(Reader
A Reader containing the source of the script.
reader
,
Bindings
A Bindings to use for the ENGINE_SCOPE while the script executes.
bindings
)

Implements javax.script.ScriptEngine.eval.

eval(Reader, Bindings) calls the abstract eval(Reader, ScriptContext) method, passing it a ScriptContext whose Reader, Writers and Bindings for scopes other that ENGINE_SCOPE are identical to those members of the protected context field.

public Object

Returns:

The return value from eval(String, ScriptContext)
eval
(String
A String containing the source of the script.
script
,
Bindings
A Bindings to use as the ENGINE_SCOPE while the script executes.
bindings
)

Implements javax.script.ScriptEngine.eval.

Same as eval(Reader, Bindings) except that the abstract eval(String, ScriptContext) is used.

public Object

Returns:

The return value from eval(Reader, ScriptContext)
eval
(Reader
A Reader containing the source of the script.
reader
)

Implements javax.script.ScriptEngine.eval.

eval(Reader) calls the abstract eval(Reader, ScriptContext) passing the value of the context field.

public Object

Returns:

The return value from eval(String, ScriptContext)
eval
(String
A String containing the source of the script.
script
)

Implements javax.script.ScriptEngine.eval.

Same as eval(Reader) except that the abstract eval(String, ScriptContext) is used.

public Object

Returns:

The value for the specified key.
get
(String key)

Implements javax.script.ScriptEngine.get.

Gets the value for the specified key in the ENGINE_SCOPE of the protected context field.

public Bindings

Returns:

The corresponding Bindings.
getBindings
(int
The specified scope
scope
)

Implements javax.script.ScriptEngine.getBindings.

Returns the Bindings with the specified scope value in the protected context field.

public ScriptContext

Returns:

The value of the protected context field.
getContext
()

Implements javax.script.ScriptEngine.getContext.

Returns the value of the protected context field.

protected ScriptContext

Returns:

The SimpleScriptContext
getScriptContext
(Bindings
Bindings to use for the ENGINE_SCOPE
nn
)

Returns a SimpleScriptContext.

public void
put(String
The specified key.
key
,
Object
The specified value.
value
)

Implements javax.script.ScriptEngine.put.

Sets the specified value with the specified key in the ENGINE_SCOPE Bindings of the protected context field.

public void
setBindings(Bindings
The specified Bindings.
bindings
,
int
The specified scope.
scope
)

Implements javax.script.ScriptEngine.setBindings.

Sets the Bindings with the corresponding scope value in the context field.

public void
setContext(ScriptContext
The specified ScriptContext.
ctxt
)

Implements javax.script.ScriptEngine.setContext.

Sets the value of the protected context field to the specified ScriptContext.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
protected ScriptContext context

The default ScriptContext of this AbstractScriptEngine.

Constructor Detail

AbstractScriptEngineback to summary
public AbstractScriptEngine()

Creates a new instance of AbstractScriptEngine using a SimpleScriptContext as its default ScriptContext.

AbstractScriptEngineback to summary
public AbstractScriptEngine(Bindings n)

Creates a new instance using the specified Bindings as the ENGINE_SCOPE Bindings in the protected context field.

Parameters
n:Bindings

The specified Bindings.

Exceptions
NullPointerException:
if n is null.

Method Detail

evalback to summary
public Object eval(Reader reader, Bindings bindings) throws ScriptException

Implements javax.script.ScriptEngine.eval.

eval(Reader, Bindings) calls the abstract eval(Reader, ScriptContext) method, passing it a ScriptContext whose Reader, Writers and Bindings for scopes other that ENGINE_SCOPE are identical to those members of the protected context field. The specified Bindings is used instead of the ENGINE_SCOPE Bindings of the context field.

Parameters
reader:Reader

A Reader containing the source of the script.

bindings:Bindings

A Bindings to use for the ENGINE_SCOPE while the script executes.

Returns:Object

The return value from eval(Reader, ScriptContext)

Exceptions
ScriptException:
if an error occurs in script.
NullPointerException:
if any of the parameters is null.
evalback to summary
public Object eval(String script, Bindings bindings) throws ScriptException

Implements javax.script.ScriptEngine.eval.

Same as eval(Reader, Bindings) except that the abstract eval(String, ScriptContext) is used.

Parameters
script:String

A String containing the source of the script.

bindings:Bindings

A Bindings to use as the ENGINE_SCOPE while the script executes.

Returns:Object

The return value from eval(String, ScriptContext)

Exceptions
ScriptException:
if an error occurs in script.
NullPointerException:
if any of the parameters is null.
evalback to summary
public Object eval(Reader reader) throws ScriptException

Implements javax.script.ScriptEngine.eval.

eval(Reader) calls the abstract eval(Reader, ScriptContext) passing the value of the context field.

Parameters
reader:Reader

A Reader containing the source of the script.

Returns:Object

The return value from eval(Reader, ScriptContext)

Exceptions
ScriptException:
if an error occurs in script.
NullPointerException:
if any of the parameters is null.
evalback to summary
public Object eval(String script) throws ScriptException

Implements javax.script.ScriptEngine.eval.

Same as eval(Reader) except that the abstract eval(String, ScriptContext) is used.

Parameters
script:String

A String containing the source of the script.

Returns:Object

The return value from eval(String, ScriptContext)

Exceptions
ScriptException:
if an error occurs in script.
NullPointerException:
if any of the parameters is null.
getback to summary
public Object get(String key)

Implements javax.script.ScriptEngine.get.

Gets the value for the specified key in the ENGINE_SCOPE of the protected context field.

Returns:Object

The value for the specified key.

Exceptions
NullPointerException:
if key is null.
IllegalArgumentException:
if key is empty.
getBindingsback to summary
public Bindings getBindings(int scope)

Implements javax.script.ScriptEngine.getBindings.

Returns the Bindings with the specified scope value in the protected context field.

Parameters
scope:int

The specified scope

Returns:Bindings

The corresponding Bindings.

Exceptions
IllegalArgumentException:
if the value of scope is invalid for the type the protected context field.
getContextback to summary
public ScriptContext getContext()

Implements javax.script.ScriptEngine.getContext.

Returns the value of the protected context field.

Returns:ScriptContext

The value of the protected context field.

getScriptContextback to summary
protected ScriptContext getScriptContext(Bindings nn)

Returns a SimpleScriptContext. The SimpleScriptContext:

  • Uses the specified Bindings for its ENGINE_SCOPE
  • Uses the Bindings returned by the abstract getGlobalScope method as its GLOBAL_SCOPE
  • Uses the Reader and Writer in the default ScriptContext of this ScriptEngine


A SimpleScriptContext returned by this method is used to implement eval methods using the abstract eval(Reader,Bindings) and eval(String,Bindings) versions.
Parameters
nn:Bindings

Bindings to use for the ENGINE_SCOPE

Returns:ScriptContext

The SimpleScriptContext

putback to summary
public void put(String key, Object value)

Implements javax.script.ScriptEngine.put.

Sets the specified value with the specified key in the ENGINE_SCOPE Bindings of the protected context field.

Parameters
key:String

The specified key.

value:Object

The specified value.

Exceptions
NullPointerException:
if key is null.
IllegalArgumentException:
if key is empty.
setBindingsback to summary
public void setBindings(Bindings bindings, int scope)

Implements javax.script.ScriptEngine.setBindings.

Sets the Bindings with the corresponding scope value in the context field.

Parameters
bindings:Bindings

The specified Bindings.

scope:int

The specified scope.

Exceptions
IllegalArgumentException:
if the value of scope is invalid for the type the context field.
NullPointerException:
if the bindings is null and the scope is ScriptContext.ENGINE_SCOPE
setContextback to summary
public void setContext(ScriptContext ctxt)

Implements javax.script.ScriptEngine.setContext.

Sets the value of the protected context field to the specified ScriptContext.

Parameters
ctxt:ScriptContext

The specified ScriptContext.

Exceptions
NullPointerException:
if ctxt is null.