Class AbstractScriptEngine
java.lang.Object
javax.script.AbstractScriptEngine
- All Implemented Interfaces:
ScriptEngine
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
..
- Since:
- 1.6
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ScriptContext
The defaultScriptContext
of thisAbstractScriptEngine
.Fields declared in interface ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
Modifier and TypeFieldDescriptionstatic final String
Reserved key for a named value that passes an array of positional arguments to a script.static final String
Reserved key for a named value that is the name of theScriptEngine
implementation.static final String
Reserved key for a named value that identifies the version of theScriptEngine
implementation.static final String
Reserved key for a named value that is the name of the file being executed.static final String
Reserved key for a named value that is the full name of Scripting Language supported by the implementation.static final String
Reserved key for the named value that identifies the version of the scripting language supported by the implementation.static final String
Reserved key for a named value that identifies the short name of the scripting language. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of AbstractScriptEngine using aSimpleScriptContext
as its defaultScriptContext
.Creates a new instance using the specifiedBindings
as theENGINE_SCOPE
Bindings
in the protectedcontext
field. -
Method Summary
Modifier and TypeMethodDescriptioneval(Reader)
calls the abstracteval(Reader, ScriptContext)
passing the value of thecontext
field.eval(Reader, Bindings)
calls the abstracteval(Reader, ScriptContext)
method, passing it aScriptContext
whose Reader, Writers and Bindings for scopes other thatENGINE_SCOPE
are identical to those members of the protectedcontext
field.Same aseval(Reader)
except that the abstracteval(String, ScriptContext)
is used.Same aseval(Reader, Bindings)
except that the abstracteval(String, ScriptContext)
is used.Gets the value for the specified key in theENGINE_SCOPE
of the protectedcontext
field.getBindings
(int scope) Returns theBindings
with the specified scope value in the protectedcontext
field.Returns the value of the protectedcontext
field.protected ScriptContext
Returns aSimpleScriptContext
.void
Sets the specified value with the specified key in theENGINE_SCOPE
Bindings
of the protectedcontext
field.void
setBindings
(Bindings bindings, int scope) Sets theBindings
with the corresponding scope value in thecontext
field.void
setContext
(ScriptContext ctxt) Sets the value of the protectedcontext
field to the specifiedScriptContext
.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Modifier and TypeMethodDescriptionprotected Object
clone()
Creates and returns a copy of this object.boolean
Indicates whether some other object is "equal to" this one.protected void
finalize()
Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class
<?> getClass()
Returns the runtime class of thisObject
.int
hashCode()
Returns a hash code value for this object.final void
notify()
Wakes up a single thread that is waiting on this object's monitor.final void
Wakes up all threads that are waiting on this object's monitor.toString()
Returns a string representation of the object.final void
wait()
Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final void
wait
(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final void
wait
(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.Methods declared in interface ScriptEngine
createBindings, eval, eval, getFactory
Modifier and TypeMethodDescriptionReturns an uninitializedBindings
.eval
(Reader reader, ScriptContext context) Same aseval(String, ScriptContext)
where the source of the script is read from aReader
.eval
(String script, ScriptContext context) Causes the immediate execution of the script whose source is the String passed as the first argument.Returns aScriptEngineFactory
for the class to which thisScriptEngine
belongs.
-
Field Details
-
context
The defaultScriptContext
of thisAbstractScriptEngine
.
-
-
Constructor Details
-
AbstractScriptEngine
public AbstractScriptEngine()Creates a new instance of AbstractScriptEngine using aSimpleScriptContext
as its defaultScriptContext
. -
AbstractScriptEngine
Creates a new instance using the specifiedBindings
as theENGINE_SCOPE
Bindings
in the protectedcontext
field.- Parameters:
n
- The specifiedBindings
.- Throws:
NullPointerException
- if n is null.
-
-
Method Details
-
setContext
Sets the value of the protectedcontext
field to the specifiedScriptContext
.- Specified by:
setContext
in interfaceScriptEngine
- Parameters:
ctxt
- The specifiedScriptContext
.- Throws:
NullPointerException
- if ctxt is null.
-
getContext
Returns the value of the protectedcontext
field.- Specified by:
getContext
in interfaceScriptEngine
- Returns:
- The value of the protected
context
field.
-
getBindings
Returns theBindings
with the specified scope value in the protectedcontext
field.- Specified by:
getBindings
in interfaceScriptEngine
- Parameters:
scope
- The specified scope- Returns:
- The corresponding
Bindings
. - Throws:
IllegalArgumentException
- if the value of scope is invalid for the type the protectedcontext
field.
-
setBindings
Sets theBindings
with the corresponding scope value in thecontext
field.- Specified by:
setBindings
in interfaceScriptEngine
- Parameters:
bindings
- The specifiedBindings
.scope
- The specified scope.- Throws:
IllegalArgumentException
- if the value of scope is invalid for the type thecontext
field.NullPointerException
- if the bindings is null and the scope isScriptContext.ENGINE_SCOPE
-
put
Sets the specified value with the specified key in theENGINE_SCOPE
Bindings
of the protectedcontext
field.- Specified by:
put
in interfaceScriptEngine
- Parameters:
key
- The specified key.value
- The specified value.- Throws:
NullPointerException
- if key is null.IllegalArgumentException
- if key is empty.
-
get
Gets the value for the specified key in theENGINE_SCOPE
of the protectedcontext
field.- Specified by:
get
in interfaceScriptEngine
- Parameters:
key
- The key whose value is to be returned- Returns:
- The value for the specified key.
- Throws:
NullPointerException
- if key is null.IllegalArgumentException
- if key is empty.
-
eval
eval(Reader, Bindings)
calls the abstracteval(Reader, ScriptContext)
method, passing it aScriptContext
whose Reader, Writers and Bindings for scopes other thatENGINE_SCOPE
are identical to those members of the protectedcontext
field. The specifiedBindings
is used instead of theENGINE_SCOPE
Bindings
of thecontext
field.- Specified by:
eval
in interfaceScriptEngine
- Parameters:
reader
- AReader
containing the source of the script.bindings
- ABindings
to use for theENGINE_SCOPE
while the script executes.- Returns:
- The return value from
eval(Reader, ScriptContext)
- Throws:
ScriptException
- if an error occurs in script.NullPointerException
- if any of the parameters is null.
-
eval
Same aseval(Reader, Bindings)
except that the abstracteval(String, ScriptContext)
is used.- Specified by:
eval
in interfaceScriptEngine
- Parameters:
script
- AString
containing the source of the script.bindings
- ABindings
to use as theENGINE_SCOPE
while the script executes.- Returns:
- The return value from
eval(String, ScriptContext)
- Throws:
ScriptException
- if an error occurs in script.NullPointerException
- if any of the parameters is null.
-
eval
eval(Reader)
calls the abstracteval(Reader, ScriptContext)
passing the value of thecontext
field.- Specified by:
eval
in interfaceScriptEngine
- Parameters:
reader
- AReader
containing the source of the script.- Returns:
- The return value from
eval(Reader, ScriptContext)
- Throws:
ScriptException
- if an error occurs in script.NullPointerException
- if any of the parameters is null.
-
eval
Same aseval(Reader)
except that the abstracteval(String, ScriptContext)
is used.- Specified by:
eval
in interfaceScriptEngine
- Parameters:
script
- AString
containing the source of the script.- Returns:
- The return value from
eval(String, ScriptContext)
- Throws:
ScriptException
- if an error occurs in script.NullPointerException
- if any of the parameters is null.
-
getScriptContext
Returns aSimpleScriptContext
. TheSimpleScriptContext
:
- Uses the specified
Bindings
for itsENGINE_SCOPE
- Uses the
Bindings
returned by the abstractgetGlobalScope
method as itsGLOBAL_SCOPE
- Uses the Reader and Writer in the default
ScriptContext
of thisScriptEngine
ASimpleScriptContext
returned by this method is used to implement eval methods using the abstracteval(Reader,Bindings)
andeval(String,Bindings)
versions.- Parameters:
nn
- Bindings to use for theENGINE_SCOPE
- Returns:
- The
SimpleScriptContext
- Uses the specified
-