public class

SimpleScriptContext

extends Object
implements ScriptContext
java.lang.Object
   ↳ javax.script.SimpleScriptContext

Class Overview

Simple implementation of ScriptContext.

Summary

[Expand]
Inherited Constants
From interface javax.script.ScriptContext
Fields
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.
Public Constructors
SimpleScriptContext()
Public Methods
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)
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<Integer> 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 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)
Sets a Bindings of attributes for the given scope.
void setErrorWriter(Writer writer)
Sets the Writer used to display error output.
void setReader(Reader reader)
Sets the Reader for scripts to read input .
void setWriter(Writer writer)
Sets the Writer for scripts to use when displaying output.
[Expand]
Inherited Methods
From class java.lang.Object
From interface javax.script.ScriptContext

Fields

protected Bindings engineScope

This is the engine scope bindings. By default, a SimpleBindings is used. Accessor methods setBindings, getBindings are used to manage this field.

See Also

protected Writer errorWriter

This is the writer to be used to output errors from scripts. By default, a PrintWriter based on System.err is used. Accessor methods getErrorWriter, setErrorWriter are used to manage this field.

See Also

protected Bindings globalScope

This is the global scope bindings. By default, a null value (which means no global scope) is used. Accessor methods setBindings, getBindings are used to manage this field.

protected Reader reader

This is the reader to be used for input from scripts. By default, a 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.

protected Writer writer

This is the writer to be used to output from scripts. By default, a PrintWriter based on System.out is used. Accessor methods getWriter, setWriter are used to manage this field.

See Also

Public Constructors

public SimpleScriptContext ()

Public Methods

public 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.

public 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.

public 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.

public Bindings getBindings (int scope)

Returns the value of the engineScope field if specified scope is ENGINE_SCOPE. Returns the value of the globalScope field if the specified scope is GLOBAL_SCOPE.

Parameters
scope The specified scope
Returns
  • The value of either the engineScope or globalScope field.
Throws
IllegalArgumentException if the value of scope is invalid.

public Writer getErrorWriter ()

Returns the Writer used to display error output.

Returns
  • The Writer

public Reader getReader ()

Returns a Reader to be used by the script to read input.

Returns
  • The Reader.

public List<Integer> getScopes ()

Returns immutable List of all the valid values for scope in the ScriptContext.

Returns
  • list of scope values

public Writer getWriter ()

Returns the Writer for scripts to use when displaying output.

Returns
  • The Writer.

public Object removeAttribute (String name, int scope)

Remove an attribute in a given scope.

Parameters
name The name of the attribute to remove
scope 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.

public 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 set
value The value of the attribute
scope 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.

public void setBindings (Bindings bindings, int scope)

Sets a 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.

Parameters
bindings The Bindings of attributes to set.
scope The value of the scope in which the attributes are set.
Throws
IllegalArgumentException if scope is invalid.
NullPointerException if the value of scope is ENGINE_SCOPE and the specified Bindings is null.

public void setErrorWriter (Writer writer)

Sets the Writer used to display error output.

Parameters
writer The Writer.

public void setReader (Reader reader)

Sets the Reader for scripts to read input .

Parameters
reader The new Reader.

public void setWriter (Writer writer)

Sets the Writer for scripts to use when displaying output.

Parameters
writer The new Writer.