SimpleScriptContextpublic interface ScriptContext
ScriptContext methods. ScriptContexts also expose Readers and Writers that can be used by the ScriptEngines for input and output.| Modifier and Type | Field | Description | 
|---|---|---|
| static final int | ENGINE_SCOPE | EngineScope attributes are visible during the lifetime of a single  ScriptEngineand a set of attributes is maintained for each engine. | 
| static final int | GLOBAL_SCOPE | GlobalScope attributes are visible to all engines created by same ScriptEngineFactory. | 
| Modifier and Type | Method | Description | 
|---|---|---|
| Object | getAttribute | Retrieves the value of the attribute with the given name in the scope occurring earliest in the search order. | 
| Object | getAttribute | Gets the value of an attribute in a given scope. | 
| int | getAttributesScope | Get the lowest scope in which an attribute is defined. | 
| Bindings | getBindings | Gets the  Bindingsassociated with the given scope in thisScriptContext. | 
| Writer | getErrorWriter() | Returns the  Writerused to display error output. | 
| Reader | getReader() | Returns a  Readerto be used by the script to read input. | 
| List | getScopes() | Returns immutable  Listof all the valid values for scope in the ScriptContext. | 
| Writer | getWriter() | Returns the  Writerfor scripts to use when displaying output. | 
| Object | removeAttribute | Remove an attribute in a given scope. | 
| void | setAttribute | Sets the value of an attribute in a given scope. | 
| void | setBindings | Associates a  Bindingsinstance with a particular scope in thisScriptContext. | 
| void | setErrorWriter | Sets the  Writerused to display error output. | 
| void | setReader | Sets the  Readerfor scripts to read input . | 
| void | setWriter | Sets the  Writerfor scripts to use when displaying output. | 
static final int ENGINE_SCOPE
ScriptEngine and a set of attributes is maintained for each engine.static final int GLOBAL_SCOPE
void setBindings(Bindings bindings, int scope)
Bindings instance with a particular scope in this ScriptContext. Calls to the getAttribute and setAttribute methods must map to the get and put methods of the Bindings for the specified scope.bindings - The Bindings to associate with the given scopescope - The scopeIllegalArgumentException - If no Bindings is defined for the specified scope value in ScriptContexts of this type.NullPointerException - if value of scope is ENGINE_SCOPE and the specified Bindings is null.Bindings getBindings(int scope)
Bindings associated with the given scope in this ScriptContext.scope - The scopeBindings. Returns null if it has not been set.IllegalArgumentException - If no Bindings is defined for the specified scope value in ScriptContext of this type.void setAttribute(String name, Object value, int scope)
GLOBAL_SCOPE and no Bindings is set for GLOBAL_SCOPE, then setAttribute call is a no-op.name - The name of the attribute to setvalue - The value of the attributescope - The scope in which to set the attributeIllegalArgumentException - if the name is empty or if the scope is invalid.NullPointerException - if the name is null.Object getAttribute(String name, int scope)
name - The name of the attribute to retrieve.scope - The scope in which to retrieve the attribute.null is the name does not exist in the given scope.IllegalArgumentException - if the name is empty or if the value of scope is invalid.NullPointerException - if the name is null.Object removeAttribute(String name, int scope)
name - The name of the attribute to removescope - The scope in which to remove the attributeIllegalArgumentException - if the name is empty or if the scope is invalid.NullPointerException - if the name is null.Object getAttribute(String name)
name - The name of the attribute to retrieve.NullPointerException - if the name is null.IllegalArgumentException - if the name is empty.int getAttributesScope(String name)
name - Name of the attribute .NullPointerException - if name is null.IllegalArgumentException - if name is empty.Writer getWriter()
Writer for scripts to use when displaying output.Writer.Writer getErrorWriter()
Writer used to display error output.Writer
void setWriter(Writer writer)
Writer for scripts to use when displaying output.writer - The new Writer.void setErrorWriter(Writer writer)
Writer used to display error output.writer - The Writer.Reader getReader()
Reader to be used by the script to read input.Reader.void setReader(Reader reader)
Reader for scripts to read input .reader - The new Reader.List<Integer> getScopes()
List of all the valid values for scope in the ScriptContext.
    © 1993, 2023, 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/21/docs/api/java.scripting/javax/script/ScriptContext.html