public abstract class AbstractScriptEngine extends Object implements ScriptEngine
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
..
Modifier and Type | Field and Description |
---|---|
protected ScriptContext |
context
The default
ScriptContext of this AbstractScriptEngine . |
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
Constructor and Description |
---|
AbstractScriptEngine()
Creates a new instance of AbstractScriptEngine using a
SimpleScriptContext
as its default ScriptContext . |
AbstractScriptEngine(Bindings n)
Creates a new instance using the specified
Bindings as the
ENGINE_SCOPE Bindings in the protected context field. |
Modifier and Type | Method and Description |
---|---|
Object |
eval(Reader reader)
eval(Reader) calls the abstract
eval(Reader, ScriptContext) passing the value of the context
field. |
Object |
eval(Reader reader,
Bindings bindings)
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. |
Object |
eval(String script)
Same as
eval(Reader) except that the abstract
eval(String, ScriptContext) is used. |
Object |
eval(String script,
Bindings bindings)
Same as
eval(Reader, Bindings) except that the abstract
eval(String, ScriptContext) is used. |
Object |
get(String key)
Gets the value for the specified key in the
ENGINE_SCOPE of the
protected context field. |
Bindings |
getBindings(int scope)
Returns the
Bindings with the specified scope value in
the protected context field. |
ScriptContext |
getContext()
Returns the value of the protected
context field. |
protected ScriptContext |
getScriptContext(Bindings nn)
Returns a
SimpleScriptContext . |
void |
put(String key,
Object value)
Sets the specified value with the specified key in the
ENGINE_SCOPE
Bindings of the protected context field. |
void |
setBindings(Bindings bindings,
int scope)
Sets the
Bindings with the corresponding scope value in the
context field. |
void |
setContext(ScriptContext ctxt)
Sets the value of the protected
context field to the specified
ScriptContext . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createBindings, eval, eval, getFactory
protected ScriptContext context
ScriptContext
of this AbstractScriptEngine
.public AbstractScriptEngine()
SimpleScriptContext
as its default ScriptContext
.public AbstractScriptEngine(Bindings n)
Bindings
as the
ENGINE_SCOPE
Bindings
in the protected context
field.n
- The specified Bindings
.NullPointerException
- if n is null.public void setContext(ScriptContext ctxt)
context
field to the specified
ScriptContext
.setContext
in interface ScriptEngine
ctxt
- The specified ScriptContext
.NullPointerException
- if ctxt is null.public ScriptContext getContext()
context
field.getContext
in interface ScriptEngine
context
field.public Bindings getBindings(int scope)
Bindings
with the specified scope value in
the protected context
field.getBindings
in interface ScriptEngine
scope
- The specified scopeBindings
.IllegalArgumentException
- if the value of scope is
invalid for the type the protected context
field.public void setBindings(Bindings bindings, int scope)
Bindings
with the corresponding scope value in the
context
field.setBindings
in interface ScriptEngine
bindings
- The specified Bindings
.scope
- The specified scope.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
public void put(String key, Object value)
ENGINE_SCOPE
Bindings
of the protected context
field.put
in interface ScriptEngine
key
- The specified key.value
- The specified value.NullPointerException
- if key is null.IllegalArgumentException
- if key is empty.public Object get(String key)
ENGINE_SCOPE
of the
protected context
field.get
in interface ScriptEngine
key
- The key whose value is to be returnedNullPointerException
- if key is null.IllegalArgumentException
- if key is empty.public Object eval(Reader reader, Bindings bindings) throws ScriptException
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.eval
in interface ScriptEngine
reader
- A Reader
containing the source of the script.bindings
- A Bindings
to use for the ENGINE_SCOPE
while the script executes.eval(Reader, ScriptContext)
ScriptException
- if an error occurs in script.NullPointerException
- if any of the parameters is null.public Object eval(String script, Bindings bindings) throws ScriptException
eval(Reader, Bindings)
except that the abstract
eval(String, ScriptContext)
is used.eval
in interface ScriptEngine
script
- A String
containing the source of the script.bindings
- A Bindings
to use as the ENGINE_SCOPE
while the script executes.eval(String, ScriptContext)
ScriptException
- if an error occurs in script.NullPointerException
- if any of the parameters is null.public Object eval(Reader reader) throws ScriptException
eval(Reader)
calls the abstract
eval(Reader, ScriptContext)
passing the value of the context
field.eval
in interface ScriptEngine
reader
- A Reader
containing the source of the script.eval(Reader, ScriptContext)
ScriptException
- if an error occurs in script.NullPointerException
- if any of the parameters is null.public Object eval(String script) throws ScriptException
eval(Reader)
except that the abstract
eval(String, ScriptContext)
is used.eval
in interface ScriptEngine
script
- A String
containing the source of the script.eval(String, ScriptContext)
ScriptException
- if an error occurs in script.NullPointerException
- if any of the parameters is null.protected ScriptContext getScriptContext(Bindings nn)
SimpleScriptContext
. The SimpleScriptContext
:
Bindings
for its ENGINE_SCOPE
Bindings
returned by the abstract getGlobalScope
method as its GLOBAL_SCOPE
ScriptContext
of this
ScriptEngine
SimpleScriptContext
returned by this method is used to implement eval methods
using the abstract eval(Reader,Bindings)
and eval(String,Bindings)
versions.nn
- Bindings to use for the ENGINE_SCOPE
SimpleScriptContext
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2023, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.