AbstractScriptEngine (Java Platform SE 6) (original) (raw)
javax.script
Class AbstractScriptEngine
java.lang.Object
javax.script.AbstractScriptEngine
All Implemented Interfaces:
public abstract class AbstractScriptEngine
extends Object
implements 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 | |
---|---|
protected ScriptContext | context The default ScriptContext of this AbstractScriptEngine. |
Fields inherited from interface javax.script.ScriptEngine |
---|
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME |
Constructor Summary |
---|
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 theENGINE_SCOPE Bindings in the protected context field. |
Method Summary | |
---|---|
Object | eval(Reader reader) eval(Reader) calls the abstracteval(Reader, ScriptContext) passing the value of the context field. |
Object | [eval](../../javax/script/AbstractScriptEngine.html#eval%28java.io.Reader, javax.script.Bindings%29)(Reader reader,Bindings bindings) eval(Reader, Bindings) calls the abstracteval(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 abstracteval(String, ScriptContext) is used. |
Object | [eval](../../javax/script/AbstractScriptEngine.html#eval%28java.lang.String, javax.script.Bindings%29)(String script,Bindings bindings) Same as eval(Reader, Bindings) except that the abstracteval(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](../../javax/script/AbstractScriptEngine.html#put%28java.lang.String, java.lang.Object%29)(String key,Object value) Sets the specified value with the specified key in the ENGINE_SCOPE Bindings of the protected context field. |
void | [setBindings](../../javax/script/AbstractScriptEngine.html#setBindings%28javax.script.Bindings, int%29)(Bindings bindings, int scope) Sets the Bindings with the corresponding scope value in thecontext field. |
void | setContext(ScriptContext ctxt) Sets the value of the protected context field to the specifiedScriptContext. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29) |
Methods inherited from interface javax.script.ScriptEngine |
---|
createBindings, [eval](../../javax/script/ScriptEngine.html#eval%28java.io.Reader, javax.script.ScriptContext%29), [eval](../../javax/script/ScriptEngine.html#eval%28java.lang.String, javax.script.ScriptContext%29), getFactory |
Field Detail |
---|
context
protected ScriptContext context
The default ScriptContext
of this AbstractScriptEngine
.
Constructor Detail |
---|
AbstractScriptEngine
public AbstractScriptEngine()
Creates a new instance of AbstractScriptEngine using a SimpleScriptContext
as its default ScriptContext
.
AbstractScriptEngine
public AbstractScriptEngine(Bindings n)
Creates a new instance using the specified Bindings
as theENGINE_SCOPE
Bindings
in the protected context
field.
Parameters:
n
- The specified Bindings
.
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if n is null.
Method Detail |
---|
setContext
public void setContext(ScriptContext ctxt)
Sets the value of the protected context
field to the specifiedScriptContext
.
Specified by:
[setContext](../../javax/script/ScriptEngine.html#setContext%28javax.script.ScriptContext%29)
in interface [ScriptEngine](../../javax/script/ScriptEngine.html "interface in javax.script")
Parameters:
ctxt
- The specified ScriptContext
.
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if ctxt is null.
getContext
public ScriptContext getContext()
Returns the value of the protected context
field.
Specified by:
[getContext](../../javax/script/ScriptEngine.html#getContext%28%29)
in interface [ScriptEngine](../../javax/script/ScriptEngine.html "interface in javax.script")
Returns:
The value of the protected context
field.
getBindings
public Bindings getBindings(int scope)
Returns the Bindings
with the specified scope value in the protected context
field.
Specified by:
[getBindings](../../javax/script/ScriptEngine.html#getBindings%28int%29)
in interface [ScriptEngine](../../javax/script/ScriptEngine.html "interface in javax.script")
Parameters:
scope
- The specified scope
Returns:
The corresponding Bindings
.
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if the value of scope is invalid for the type the protected context
field.
setBindings
public void setBindings(Bindings bindings, int scope)
Sets the Bindings
with the corresponding scope value in thecontext
field.
Specified by:
[setBindings](../../javax/script/ScriptEngine.html#setBindings%28javax.script.Bindings, int%29)
in interface [ScriptEngine](../../javax/script/ScriptEngine.html "interface in javax.script")
Parameters:
bindings
- The specified Bindings
.
scope
- The specified scope.
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if the value of scope is invalid for the type the context
field.
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if the bindings is null and the scope isScriptContext.ENGINE_SCOPE
put
public void put(String key, Object value)
Sets the specified value with the specified key in the ENGINE_SCOPE
Bindings
of the protected context
field.
Specified by:
[put](../../javax/script/ScriptEngine.html#put%28java.lang.String, java.lang.Object%29)
in interface [ScriptEngine](../../javax/script/ScriptEngine.html "interface in javax.script")
Parameters:
key
- The specified key.
value
- The specified value.
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if key is null.
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if key is empty.
get
Gets the value for the specified key in the ENGINE_SCOPE
of the protected context
field.
Specified by:
[get](../../javax/script/ScriptEngine.html#get%28java.lang.String%29)
in interface [ScriptEngine](../../javax/script/ScriptEngine.html "interface in javax.script")
Parameters:
key
- The key whose value is to be returned
Returns:
The value for the specified key.
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if key is null.
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if key is empty.
eval
public Object eval(Reader reader, Bindings bindings) throws ScriptException
eval(Reader, Bindings)
calls the abstracteval(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 specifiedBindings
is used instead of the ENGINE_SCOPE
Bindings
of the context
field.
Specified by:
[eval](../../javax/script/ScriptEngine.html#eval%28java.io.Reader, javax.script.Bindings%29)
in interface [ScriptEngine](../../javax/script/ScriptEngine.html "interface in javax.script")
Parameters:
reader
- A Reader
containing the source of the script.
bindings
- A Bindings
to use for the ENGINE_SCOPE
while the script executes.
Returns:
The return value from eval(Reader, ScriptContext)
Throws:
[ScriptException](../../javax/script/ScriptException.html "class in javax.script")
- if an error occurs in script.
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if any of the parameters is null.
eval
public Object eval(String script, Bindings bindings) throws ScriptException
Same as eval(Reader, Bindings)
except that the abstracteval(String, ScriptContext)
is used.
Specified by:
[eval](../../javax/script/ScriptEngine.html#eval%28java.lang.String, javax.script.Bindings%29)
in interface [ScriptEngine](../../javax/script/ScriptEngine.html "interface in javax.script")
Parameters:
script
- A String
containing the source of the script.
bindings
- A Bindings
to use as the ENGINE_SCOPE
while the script executes.
Returns:
The return value from eval(String, ScriptContext)
Throws:
[ScriptException](../../javax/script/ScriptException.html "class in javax.script")
- if an error occurs in script.
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if any of the parameters is null.
eval
public Object eval(Reader reader) throws ScriptException
eval(Reader)
calls the abstracteval(Reader, ScriptContext)
passing the value of the context
field.
Specified by:
[eval](../../javax/script/ScriptEngine.html#eval%28java.io.Reader%29)
in interface [ScriptEngine](../../javax/script/ScriptEngine.html "interface in javax.script")
Parameters:
reader
- A Reader
containing the source of the script.
Returns:
The return value from eval(Reader, ScriptContext)
Throws:
[ScriptException](../../javax/script/ScriptException.html "class in javax.script")
- if an error occurs in script.
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if any of the parameters is null.
eval
public Object eval(String script) throws ScriptException
Same as eval(Reader)
except that the abstracteval(String, ScriptContext)
is used.
Specified by:
[eval](../../javax/script/ScriptEngine.html#eval%28java.lang.String%29)
in interface [ScriptEngine](../../javax/script/ScriptEngine.html "interface in javax.script")
Parameters:
script
- A String
containing the source of the script.
Returns:
The return value from eval(String, ScriptContext)
Throws:
[ScriptException](../../javax/script/ScriptException.html "class in javax.script")
- if an error occurrs in script.
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if any of the parameters is null.
getScriptContext
protected ScriptContext getScriptContext(Bindings nn)
Returns a SimpleScriptContext
. The SimpleScriptContext
:
- 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
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 to use for the ENGINE_SCOPE
Returns:
The SimpleScriptContext
Submit a bug or feature
For further API reference and developer documentation, see Java SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2015, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
Scripting on this page tracks web page traffic, but does not change the content in any way.