- java.lang.Object
-
- javax.script.AbstractScriptEngine
-
- All Implemented Interfaces:
- ScriptEngine
public abstract class AbstractScriptEngine extends Object implements ScriptEngine
Provides a standard implementation for several of the variants of theeval
method.
eval(Reader)
eval(String)
eval(String, Bindings)
eval(Reader, Bindings)
are implemented using the abstract methods
eval(Reader,ScriptContext)
oreval(String, ScriptContext)
with aSimpleScriptContext
.
ASimpleScriptContext
is used as the defaultScriptContext
of theAbstractScriptEngine
..- Since:
- 1.6
-
-
Field Summary
Fields Modifier and Type Field and Description protected ScriptContext
context
The defaultScriptContext
of thisAbstractScriptEngine
.-
Fields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
-
-
Constructor Summary
Constructors Constructor and Description AbstractScriptEngine()
Creates a new instance of AbstractScriptEngine using aSimpleScriptContext
as its defaultScriptContext
.AbstractScriptEngine(Bindings n)
Creates a new instance using the specifiedBindings
as theENGINE_SCOPE
Bindings
in the protectedcontext
field.
-
Method Summary
Methods Modifier and Type Method and Description Object
eval(Reader reader)
eval(Reader)
calls the abstracteval(Reader, ScriptContext)
passing the value of thecontext
field.Object
eval(Reader reader, Bindings bindings)
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.Object
eval(String script)
Same aseval(Reader)
except that the abstracteval(String, ScriptContext)
is used.Object
eval(String script, Bindings bindings)
Same aseval(Reader, Bindings)
except that the abstracteval(String, ScriptContext)
is used.Object
get(String key)
Gets the value for the specified key in theENGINE_SCOPE
of the protectedcontext
field.Bindings
getBindings(int scope)
Returns theBindings
with the specified scope value in the protectedcontext
field.ScriptContext
getContext()
Returns the value of the protectedcontext
field.protected ScriptContext
getScriptContext(Bindings nn)
Returns aSimpleScriptContext
.void
put(String key, Object value)
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 inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.script.ScriptEngine
createBindings, eval, eval, getFactory
-
-
-
-
Field Detail
-
context
protected ScriptContext context
The defaultScriptContext
of thisAbstractScriptEngine
.
-
-
Constructor Detail
-
AbstractScriptEngine
public AbstractScriptEngine()
Creates a new instance of AbstractScriptEngine using aSimpleScriptContext
as its defaultScriptContext
.
-
AbstractScriptEngine
public AbstractScriptEngine(Bindings n)
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 Detail
-
setContext
public void setContext(ScriptContext ctxt)
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
public ScriptContext getContext()
Returns the value of the protectedcontext
field.- Specified by:
getContext
in interfaceScriptEngine
- Returns:
- The value of the protected
context
field.
-
getBindings
public Bindings getBindings(int scope)
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
public void setBindings(Bindings bindings, int scope)
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
public void put(String key, Object value)
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
public Object get(String key)
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
public Object eval(Reader reader, Bindings bindings) throws ScriptException
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
public Object eval(String script, Bindings bindings) throws ScriptException
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
public Object eval(Reader reader) throws ScriptException
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
public Object eval(String script) throws ScriptException
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 occurrs in script.NullPointerException
- if any of the parameters is null.
-
getScriptContext
protected ScriptContext getScriptContext(Bindings nn)
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
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-javax/script/AbstractScriptEngine.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.