public 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 and Description |
|---|---|
static int |
ENGINE_SCOPE
EngineScope attributes are visible during the lifetime of a single
ScriptEngine 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.
|
| Modifier and Type | Method and Description |
|---|---|
Object |
getAttribute(String
Retrieves the value of the attribute with the given name in the scope occurring earliest in the search order.
|
Object |
getAttribute(String
Gets the value of an attribute in a given scope.
|
int |
getAttributesScope(String
Get the lowest scope in which an attribute is defined.
|
Bindings |
getBindings(int scope)
Gets the
Bindings associated with the given scope in this
ScriptContext.
|
Writer |
getErrorWriter()
Returns the
Writer used to display error output.
|
Reader |
getReader()
Returns a
Reader to be used by the script to read input.
|
List |
getScopes()
Returns immutable
List of all the valid values for scope in the ScriptContext.
|
Writer |
getWriter()
Returns the
Writer for scripts to use when displaying output.
|
Object |
removeAttribute(String
Remove an attribute in a given scope.
|
void |
setAttribute(String
Sets the value of an attribute in a given scope.
|
void |
setBindings(Bindings
Associates a
Bindings instance with a particular scope in this
ScriptContext.
|
void |
setErrorWriter(Writer
Sets the
Writer used to display error output.
|
void |
setReader(Reader
Sets the
Reader for scripts to read input .
|
void |
setWriter(Writer
Sets the
Writer for 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(Bindingsbindings, 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 scope
scope - The scope
IllegalArgumentException - 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.
BindingsgetBindings(int scope)
Bindings associated with the given scope in this
ScriptContext.
scope - The scope
Bindings. 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(Stringname, Object value, int scope)
name - The name of the attribute to set
value - The value of the attribute
scope - The scope in which to set the attribute
IllegalArgumentException - if the name is empty or if the scope is invalid.
NullPointerException - if the name is null.
ObjectgetAttribute(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.
ObjectremoveAttribute(String name, int scope)
name - The name of the attribute to remove
scope - The scope in which to remove the attribute
IllegalArgumentException - if the name is empty or if the scope is invalid.
NullPointerException - if the name is null.
ObjectgetAttribute(String name)
name - The name of the the attribute to retrieve.
NullPointerException - if the name is null.
IllegalArgumentException - if the name is empty.
int getAttributesScope(Stringname)
name - Name of the attribute .
NullPointerException - if name is null.
IllegalArgumentException - if name is empty.
WritergetWriter()
Writer for scripts to use when displaying output.
Writer.
WritergetErrorWriter()
Writer used to display error output.
Writer
void setWriter(Writerwriter)
Writer for scripts to use when displaying output.
writer - The new
Writer.
void setErrorWriter(Writerwriter)
Writer used to display error output.
writer - The
Writer.
ReadergetReader()
Reader to be used by the script to read input.
Reader.
void setReader(Readerreader)
Reader for scripts to read input .
reader - The new
Reader.