javax.script
Class SimpleScriptContext

java.lang.Object
  extended by javax.script.SimpleScriptContext
All Implemented Interfaces:
ScriptContext
Direct Known Subclasses:
GenericHttpScriptContext

public class SimpleScriptContext
extends Object
implements ScriptContext

A simple implementation of ScriptContext. This class is not synchronized. See Javadoc of Java Scripting API


Field Summary
protected  Bindings engineScope
          This is the scope bindings for ENGINE_SCOPE .
protected  Writer errorWriter
          The writer to be used for displaying error output from scripts
protected  Bindings globalScope
          This is the scope bindings for GLOBAL_SCOPE.
protected  Reader reader
          The reader to be used for input from scripts.
protected  Writer writer
          The writer to be used for displaying output from scripts
 
Fields inherited from interface javax.script.ScriptContext
ENGINE_SCOPE, GLOBAL_SCOPE
 
Constructor Summary
SimpleScriptContext()
          Create a new instance, setting the Reader and Writers from the corresponding System streams.
 
Method Summary
 Object getAttribute(String name)
          Retrieves the value of the getAttribute(String, int) for the lowest scope in which it returns a non-null value.
 Object getAttribute(String name, int scope)
          Retrieves the value of an attribute in the specified scope.
 int getAttributesScope(String name)
          Retrieves the lowest value of the scope for which the attribute is defined.
 Bindings getBindings(int scope)
          Retrieves the Bindings instance associated with the given scope.
 Writer getErrorWriter()
          Returns the Writer to be used to display error output.
 Reader getReader()
          Returns a Reader to be used by the script to read input.
 List getScopes()
          Returns an immutable List of all the valid values for scope in the ScriptContext.
 Writer getWriter()
          Retrieves an instance of java.io.Writer which can be used by scripts to display their output.
 Object removeAttribute(String name, int scope)
          Removes the given attribute from the specified scope.
 void setAttribute(String name, Object value, int scope)
          Associates a specified value with the specifed name in the specified scope.
 void setBindings(Bindings bindings, int scope)
          Associates the specified Bindings with the specified scope.
 void setErrorWriter(Writer writer)
          Sets the Writer for scripts to use when displaying error output.
 void setReader(Reader reader)
          Sets the Reader to be used by the script to read input.
 void setWriter(Writer writer)
          Sets the Writer for scripts to use when displaying output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

globalScope

protected Bindings globalScope
This is the scope bindings for GLOBAL_SCOPE. By default, a null value (which means no global scope) is used.


engineScope

protected Bindings engineScope
This is the scope bindings for ENGINE_SCOPE . By default, a SimpleBindings is used.


reader

protected Reader reader
The reader to be used for input from scripts.


writer

protected Writer writer
The writer to be used for displaying output from scripts


errorWriter

protected Writer errorWriter
The writer to be used for displaying error output from scripts

Constructor Detail

SimpleScriptContext

public SimpleScriptContext()
Create a new instance, setting the Reader and Writers from the corresponding System streams.

Method Detail

getAttribute

public Object getAttribute(String name)
Retrieves the value of the getAttribute(String, int) for the lowest scope in which it returns a non-null value. Returns null if there is no such value exists in any scope.

Specified by:
getAttribute in interface ScriptContext
Parameters:
name - the name of the attribute
Returns:
the associated value with the specified name

getAttribute

public Object getAttribute(String name,
                           int scope)
Retrieves the value of an attribute in the specified scope. Returns null if the no such value exists in the specified scope.

Specified by:
getAttribute in interface ScriptContext
Parameters:
name - the name of the attribute
scope - the value of the scope
Returns:
the associated value for the specified name

getAttributesScope

public int getAttributesScope(String name)
Retrieves the lowest value of the scope for which the attribute is defined.

Specified by:
getAttributesScope in interface ScriptContext
Parameters:
name - the name of attribute
Returns:
the value corresponding to lowest value of the scope or -1 if no associated value exist in any scope

getBindings

public Bindings getBindings(int scope)
Retrieves the Bindings instance associated with the given scope. Returns null if no Bindings is associated with specified scope.

Specified by:
getBindings in interface ScriptContext
Parameters:
scope - the scope
Returns:
the Bindings associated with the specified scope

removeAttribute

public Object removeAttribute(String name,
                              int scope)
Removes the given attribute from the specified scope. Returns the removed object or null if no value is associated with the specified key in the specified scope.

Specified by:
removeAttribute in interface ScriptContext
Parameters:
name - the name of the attribute
scope - the scope from which to remove the attribute
Returns:
previous value associated with specified name

setAttribute

public void setAttribute(String name,
                         Object value,
                         int scope)
Associates a specified value with the specifed name in the specified scope.

Specified by:
setAttribute in interface ScriptContext
Parameters:
name - the name of the attribute
value - the value of the attribute
scope - the scope

setBindings

public void setBindings(Bindings bindings,
                        int scope)
Associates the specified Bindings with the specified scope.

Specified by:
setBindings in interface ScriptContext
Parameters:
bindings - the Bindings to be associated with the specified scope
scope - the scope

getScopes

public List getScopes()
Returns an immutable List of all the valid values for scope in the ScriptContext.

Specified by:
getScopes in interface ScriptContext
Returns:
the list

getReader

public Reader getReader()
Returns a Reader to be used by the script to read input.

Specified by:
getReader in interface ScriptContext
Returns:
the reader

setReader

public void setReader(Reader reader)
Sets the Reader to be used by the script to read input.

Specified by:
setReader in interface ScriptContext
Parameters:
reader - the new reader

getWriter

public Writer getWriter()
Retrieves an instance of java.io.Writer which can be used by scripts to display their output.

Specified by:
getWriter in interface ScriptContext
Returns:
an instance of java.io.Writer

setWriter

public void setWriter(Writer writer)
Sets the Writer for scripts to use when displaying output.

Specified by:
setWriter in interface ScriptContext
Parameters:
writer - the new writer.

getErrorWriter

public Writer getErrorWriter()
Returns the Writer to be used to display error output.

Specified by:
getErrorWriter in interface ScriptContext
Returns:
the error writer

setErrorWriter

public void setErrorWriter(Writer writer)
Sets the Writer for scripts to use when displaying error output.

Specified by:
setErrorWriter in interface ScriptContext
Parameters:
writer - the new writer.


Copyright © 1999-2012 The Apache Software Foundation. All Rights Reserved.