Class AbstractScriptEngine
- All Implemented Interfaces:
ScriptEngine
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..
- Since:
- 1.6
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
protected ScriptContext |
context |
The default ScriptContext of this AbstractScriptEngine. |
Fields declared in interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
Constructor Summary
| Constructor | Description |
|---|---|
AbstractScriptEngine() |
Creates a new instance of AbstractScriptEngine using a SimpleScriptContext as its default ScriptContext. |
AbstractScriptEngine |
Creates a new instance using the specified Bindings as the ENGINE_SCOPE Bindings in the protected context field. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
Object |
eval |
eval(Reader) calls the abstract eval(Reader, ScriptContext) passing the value of the context field. |
Object |
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. |
Object |
eval |
Same as eval(Reader) except that the abstract eval(String, ScriptContext) is used. |
Object |
eval |
Same as eval(Reader, Bindings) except that the abstract eval(String, ScriptContext) is used. |
Object |
get |
Gets the value for the specified key in the ENGINE_SCOPE of the protected context field. |
Bindings |
getBindings |
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 |
Returns a SimpleScriptContext. |
void |
put |
Sets the specified value with the specified key in the ENGINE_SCOPE Bindings of the protected context field. |
void |
setBindings |
Sets the Bindings with the corresponding scope value in the context field. |
void |
setContext |
Sets the value of the protected context field to the specified ScriptContext. |
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods declared in interface javax.script.ScriptEngine
createBindings, eval, eval, getFactory
Field Details
context
protected ScriptContext context
ScriptContext of this AbstractScriptEngine.Constructor Details
AbstractScriptEngine
public AbstractScriptEngine()
SimpleScriptContext as its default ScriptContext.AbstractScriptEngine
public AbstractScriptEngine(Bindings n)
Bindings as the ENGINE_SCOPE Bindings in the protected context field.- Parameters:
-
n- The specifiedBindings. - Throws:
-
NullPointerException- if n is null.
Method Details
setContext
public void setContext(ScriptContext ctxt)
context field to the specified ScriptContext.- Specified by:
-
setContextin interfaceScriptEngine - Parameters:
-
ctxt- The specifiedScriptContext. - Throws:
-
NullPointerException- if ctxt is null.
getContext
public ScriptContext getContext()
context field.- Specified by:
-
getContextin interfaceScriptEngine - Returns:
- The value of the protected
contextfield.
getBindings
public Bindings getBindings(int scope)
Bindings with the specified scope value in the protected context field.- Specified by:
-
getBindingsin interfaceScriptEngine - Parameters:
-
scope- The specified scope - Returns:
- The corresponding
Bindings. - Throws:
-
IllegalArgumentException- if the value of scope is invalid for the type the protectedcontextfield.
setBindings
public void setBindings(Bindings bindings, int scope)
Bindings with the corresponding scope value in the context field.- Specified by:
-
setBindingsin interfaceScriptEngine - Parameters:
-
bindings- The specifiedBindings. -
scope- The specified scope. - Throws:
-
IllegalArgumentException- if the value of scope is invalid for the type thecontextfield. -
NullPointerException- if the bindings is null and the scope isScriptContext.ENGINE_SCOPE
put
public void put(String key, Object value)
ENGINE_SCOPE Bindings of the protected context field.- Specified by:
-
putin interfaceScriptEngine - Parameters:
-
key- The specified key. -
value- The specified value. - Throws:
-
NullPointerException- if key is null. -
IllegalArgumentException- if key is empty.
get
public Object get(String key)
ENGINE_SCOPE of the protected context field.- Specified by:
-
getin 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
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.- Specified by:
-
evalin interfaceScriptEngine - Parameters:
-
reader- AReadercontaining the source of the script. -
bindings- ABindingsto use for theENGINE_SCOPEwhile 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
public Object eval(String script, Bindings bindings) throws ScriptException
eval(Reader, Bindings) except that the abstract eval(String, ScriptContext) is used.- Specified by:
-
evalin interfaceScriptEngine - Parameters:
-
script- AStringcontaining the source of the script. -
bindings- ABindingsto use as theENGINE_SCOPEwhile 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
public Object eval(Reader reader) throws ScriptException
eval(Reader) calls the abstract eval(Reader, ScriptContext) passing the value of the context field.- Specified by:
-
evalin interfaceScriptEngine - Parameters:
-
reader- AReadercontaining 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
public Object eval(String script) throws ScriptException
eval(Reader) except that the abstract eval(String, ScriptContext) is used.- Specified by:
-
evalin interfaceScriptEngine - Parameters:
-
script- AStringcontaining 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
protected ScriptContext getScriptContext(Bindings nn)
SimpleScriptContext. The SimpleScriptContext: - Uses the specified
Bindingsfor itsENGINE_SCOPE - Uses the
Bindingsreturned by the abstractgetGlobalScopemethod as itsGLOBAL_SCOPE - Uses the Reader and Writer in the default
ScriptContextof 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 theENGINE_SCOPE - Returns:
- The
SimpleScriptContext
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.scripting/javax/script/AbstractScriptEngine.html