-
- All Known Implementing Classes:
- SimpleScriptContext
public interface ScriptContext
The interface whose implementing classes are used to connect Script Engines with objects, such as scoped Bindings, in hosting applications. Each scope is a set of named attributes whose values can be set and retrieved using theScriptContext
methods. ScriptContexts also expose Readers and Writers that can be used by the ScriptEngines for input and output.- Since:
- 1.6
-
-
Field Summary
Fields Modifier and Type Field and Description static int
ENGINE_SCOPE
EngineScope attributes are visible during the lifetime of a singleScriptEngine
and a set of attributes is maintained for each engine.static int
GLOBAL_SCOPE
GlobalScope attributes are visible to all engines created by same ScriptEngineFactory.
-
Method Summary
Methods Modifier and Type Method and Description Object
getAttribute(String name)
Retrieves the value of the attribute with the given name in the scope occurring earliest in the search order.Object
getAttribute(String name, int scope)
Gets the value of an attribute in a given scope.int
getAttributesScope(String name)
Get the lowest scope in which an attribute is defined.Bindings
getBindings(int scope)
Gets theBindings
associated with the given scope in thisScriptContext
.Writer
getErrorWriter()
Returns theWriter
used to display error output.Reader
getReader()
Returns aReader
to be used by the script to read input.List<Integer>
getScopes()
Returns immutableList
of all the valid values for scope in the ScriptContext.Writer
getWriter()
Returns theWriter
for scripts to use when displaying output.Object
removeAttribute(String name, int scope)
Remove an attribute in a given scope.void
setAttribute(String name, Object value, int scope)
Sets the value of an attribute in a given scope.void
setBindings(Bindings bindings, int scope)
Associates aBindings
instance with a particular scope in thisScriptContext
.void
setErrorWriter(Writer writer)
Sets theWriter
used to display error output.void
setReader(Reader reader)
Sets theReader
for scripts to read input .void
setWriter(Writer writer)
Sets theWriter
for scripts to use when displaying output.
-
-
-
Field Detail
-
ENGINE_SCOPE
static final int ENGINE_SCOPE
EngineScope attributes are visible during the lifetime of a singleScriptEngine
and a set of attributes is maintained for each engine.- See Also:
- Constant Field Values
-
GLOBAL_SCOPE
static final int GLOBAL_SCOPE
GlobalScope attributes are visible to all engines created by same ScriptEngineFactory.- See Also:
- Constant Field Values
-
-
Method Detail
-
setBindings
void setBindings(Bindings bindings, int scope)
Associates aBindings
instance with a particular scope in thisScriptContext
. Calls to thegetAttribute
andsetAttribute
methods must map to theget
andput
methods of theBindings
for the specified scope.- Parameters:
bindings
- TheBindings
to associate with the given scopescope
- The scope- Throws:
IllegalArgumentException
- If noBindings
is defined for the specified scope value in ScriptContexts of this type.NullPointerException
- if value of scope isENGINE_SCOPE
and the specifiedBindings
is null.
-
getBindings
Bindings getBindings(int scope)
Gets theBindings
associated with the given scope in thisScriptContext
.- Returns:
- The associated
Bindings
. Returnsnull
if it has not been set. - Throws:
IllegalArgumentException
- If noBindings
is defined for the specified scope value inScriptContext
of this type.
-
setAttribute
void setAttribute(String name, Object value, int scope)
Sets the value of an attribute in a given scope.- Parameters:
name
- The name of the attribute to setvalue
- The value of the attributescope
- The scope in which to set the attribute- Throws:
IllegalArgumentException
- if the name is empty or if the scope is invalid.NullPointerException
- if the name is null.
-
getAttribute
Object getAttribute(String name, int scope)
Gets the value of an attribute in a given scope.- Parameters:
name
- The name of the attribute to retrieve.scope
- The scope in which to retrieve the attribute.- Returns:
- The value of the attribute. Returns
null
is the name does not exist in the given scope. - Throws:
IllegalArgumentException
- if the name is empty or if the value of scope is invalid.NullPointerException
- if the name is null.
-
removeAttribute
Object removeAttribute(String name, int scope)
Remove an attribute in a given scope.- Parameters:
name
- The name of the attribute to removescope
- The scope in which to remove the attribute- Returns:
- The removed value.
- Throws:
IllegalArgumentException
- if the name is empty or if the scope is invalid.NullPointerException
- if the name is null.
-
getAttribute
Object getAttribute(String name)
Retrieves the value of the attribute with the given name in the scope occurring earliest in the search order. The order is determined by the numeric value of the scope parameter (lowest scope values first.)- Parameters:
name
- The name of the the attribute to retrieve.- Returns:
- The value of the attribute in the lowest scope for which an attribute with the given name is defined. Returns null if no attribute with the name exists in any scope.
- Throws:
NullPointerException
- if the name is null.IllegalArgumentException
- if the name is empty.
-
getAttributesScope
int getAttributesScope(String name)
Get the lowest scope in which an attribute is defined.- Parameters:
name
- Name of the attribute .- Returns:
- The lowest scope. Returns -1 if no attribute with the given name is defined in any scope.
- Throws:
NullPointerException
- if name is null.IllegalArgumentException
- if name is empty.
-
getWriter
Writer getWriter()
Returns theWriter
for scripts to use when displaying output.- Returns:
- The
Writer
.
-
getErrorWriter
Writer getErrorWriter()
Returns theWriter
used to display error output.- Returns:
- The
Writer
-
setWriter
void setWriter(Writer writer)
Sets theWriter
for scripts to use when displaying output.- Parameters:
writer
- The newWriter
.
-
setErrorWriter
void setErrorWriter(Writer writer)
Sets theWriter
used to display error output.- Parameters:
writer
- TheWriter
.
-
getReader
Reader getReader()
Returns aReader
to be used by the script to read input.- Returns:
- The
Reader
.
-
setReader
void setReader(Reader reader)
Sets theReader
for scripts to read input .- Parameters:
reader
- The newReader
.
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-javax/script/scriptcontext.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.