public class SimpleScriptContext extends Objectimplements ScriptContext
| Modifier and Type | Field and Description |
|---|---|
protected Bindings |
engineScope
This is the engine scope bindings.
|
protected Writer |
errorWriter
This is the writer to be used to output errors from scripts.
|
protected Bindings |
globalScope
This is the global scope bindings.
|
protected Reader |
reader
This is the reader to be used for input from scripts.
|
protected Writer |
writer
This is the writer to be used to output from scripts.
|
ENGINE_SCOPE, GLOBAL_SCOPE| Constructor and Description |
|---|
SimpleScriptContext()
Create a
SimpleScriptContext.
|
| 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)
Returns the value of the
engineScope field if specified scope is
ENGINE_SCOPE.
|
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
Sets a
Bindings of attributes for the given scope.
|
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.
|
protected Writerwriter
PrintWriter based on
System.out is used. Accessor methods getWriter, setWriter are used to manage this field.
System.out ,
PrintWriter
protected WritererrorWriter
PrintWriter based on
System.err is used. Accessor methods getErrorWriter, setErrorWriter are used to manage this field.
System.err ,
PrintWriter
protected Readerreader
InputStreamReader based on
System.in is used and default charset is used by this reader. Accessor methods getReader, setReader are used to manage this field.
System.in ,
InputStreamReader
protected BindingsengineScope
SimpleBindings is used. Accessor methods setBindings, getBindings are used to manage this field.
SimpleBindings
protected BindingsglobalScope
public void setBindings(Bindingsbindings, int scope)
Bindings of attributes for the given scope. If the value of scope is
ENGINE_SCOPE the given
Bindings replaces the
engineScope field. If the value of scope is
GLOBAL_SCOPE the given
Bindings replaces the
globalScope field.
setBindings in interface
ScriptContext
bindings - The
Bindings of attributes to set.
scope - The value of the scope in which the attributes are set.
IllegalArgumentException - if scope is invalid.
NullPointerException - if the value of scope is
ENGINE_SCOPE and the specified
Bindings is null.
public ObjectgetAttribute(String name)
getAttribute in interface
ScriptContext
name - The name of the the attribute to retrieve.
NullPointerException - if the name is null.
IllegalArgumentException - if the name is empty.
public ObjectgetAttribute(String name, int scope)
getAttribute in interface
ScriptContext
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.
public ObjectremoveAttribute(String name, int scope)
removeAttribute in interface
ScriptContext
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.
public void setAttribute(Stringname, Object value, int scope)
setAttribute in interface
ScriptContext
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.
public WritergetWriter()
Writer for scripts to use when displaying output.
getWriter in interface
ScriptContext
Writer.
public ReadergetReader()
Reader to be used by the script to read input.
getReader in interface
ScriptContext
Reader.
public void setReader(Readerreader)
Reader for scripts to read input .
setReader in interface
ScriptContext
reader - The new
Reader.
public void setWriter(Writerwriter)
Writer for scripts to use when displaying output.
setWriter in interface
ScriptContext
writer - The new
Writer.
public WritergetErrorWriter()
Writer used to display error output.
getErrorWriter in interface
ScriptContext
Writer
public void setErrorWriter(Writerwriter)
Writer used to display error output.
setErrorWriter in interface
ScriptContext
writer - The
Writer.
public int getAttributesScope(Stringname)
getAttributesScope in interface
ScriptContext
name - Name of the attribute .
NullPointerException - if name is null.
IllegalArgumentException - if name is empty.
public BindingsgetBindings(int scope)
engineScope field if specified scope is
ENGINE_SCOPE. Returns the value of the
globalScope field if the specified scope is
GLOBAL_SCOPE.
getBindings in interface
ScriptContext
scope - The specified scope
engineScope or
globalScope field.
IllegalArgumentException - if the value of scope is invalid.
public List<Integer > getScopes()
List of all the valid values for scope in the ScriptContext.
getScopes in interface
ScriptContext