javax.script
Class SimpleScriptContext

java.lang.Object
  extended by javax.script.SimpleScriptContext
All Implemented Interfaces:
ScriptContext

public class SimpleScriptContext
extends java.lang.Object
implements ScriptContext

The GenericScriptContext is a simple implementation of ScriptContext.

Author:
Nandika Jayawardana , Sanka Samaranayake

Field Summary
 
Fields inherited from interface javax.script.ScriptContext
ENGINE_SCOPE, GLOBAL_SCOPE
 
Constructor Summary
SimpleScriptContext()
          Create a simple script context
 
Method Summary
 java.lang.Object getAttribute(java.lang.String name)
          Retrieves the value for getAttribute(String, int) for the lowest scope in which it returns a non-null value.
 java.lang.Object getAttribute(java.lang.String name, int scope)
          Retrieves the value associated with specified name in the specified level of scope.
 int getAttributesScope(java.lang.String name)
          Retrieves the lowest value of scopes for which the attribute is defined.
 Bindings getBindings(int scope)
          Retrieves the Namespace instance associated with the specified level of scope.
 java.io.Writer getErrorWriter()
          Returns the Writer used to display error output.
 java.io.Reader getReader()
          Returns a Reader to be used by the script to read input.
 java.util.List getScopes()
          Returns immutable List of all the valid values for scope in the ScriptContext.
 java.io.Writer getWriter()
          Returns the Writer for scripts to use when displaying output.
 java.lang.Object removeAttribute(java.lang.String name, int scope)
          Removes the specified attribute form the specified level of scope.
 void setAttribute(java.lang.String name, java.lang.Object value, int scope)
          Sets an attribute specified by the name in specified level of scope.
 void setBindings(Bindings namespace, int scope)
          Associates the specified namespace with specified level of scope.
 void setErrorWriter(java.io.Writer writer)
          Sets the Writer used to display error output.
 void setReader(java.io.Reader reader)
          Sets the Reader for scripts to read input .
 void setWriter(java.io.Writer writer)
          Sets the Writer for scripts to use when displaying output.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleScriptContext

public SimpleScriptContext()
Create a simple script context

Method Detail

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
                              throws java.lang.IllegalArgumentException
Retrieves the value for getAttribute(String, int) for the lowest scope in which it returns a non-null value.

Specified by:
getAttribute in interface ScriptContext
Parameters:
name - the name of the attribute
Returns:
the value of the attribute
Throws:
java.lang.IllegalArgumentException

getAttribute

public java.lang.Object getAttribute(java.lang.String name,
                                     int scope)
                              throws java.lang.IllegalArgumentException
Retrieves the value associated with specified name in the specified level of scope. Returns null if no value is associated with specified key in specified level of scope.

Specified by:
getAttribute in interface ScriptContext
Parameters:
name - the name of the attribute
scope - the level of scope
Returns:
the value value associated with the specified name in specified level of scope
Throws:
java.lang.IllegalArgumentException

getAttributesScope

public int getAttributesScope(java.lang.String name)
Retrieves the lowest value of scopes for which the attribute is defined. If there is no associate scope with the given attribute (-1) is returned.

Specified by:
getAttributesScope in interface ScriptContext
Parameters:
name - the name of attribute
Returns:
the value of level of scope

getBindings

public Bindings getBindings(int scope)
Retrieves the Namespace instance associated with the specified level of scope.

Specified by:
getBindings in interface ScriptContext
Parameters:
scope - the level of the scope
Returns:
the namespace associated with the specified level of scope

removeAttribute

public java.lang.Object removeAttribute(java.lang.String name,
                                        int scope)
                                 throws java.lang.IllegalArgumentException
Removes the specified attribute form the specified level of scope.

Specified by:
removeAttribute in interface ScriptContext
Parameters:
name - the name of the attribute
scope - the level of scope
Returns:
value which is removed
Throws:
java.lang.IllegalArgumentException

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value,
                         int scope)
                  throws java.lang.IllegalArgumentException
Sets an attribute specified by the name in specified level of scope.

Specified by:
setAttribute in interface ScriptContext
Parameters:
name - the name of the attribute
value - the value of the attribute
scope - the level of the scope
Throws:
java.lang.IllegalArgumentException - if the name is null scope is invalid

setBindings

public void setBindings(Bindings namespace,
                        int scope)
                 throws java.lang.IllegalArgumentException
Associates the specified namespace with specified level of scope.

Specified by:
setBindings in interface ScriptContext
Parameters:
namespace - the namespace to be associated with specified level of scope
scope - the level of scope
Throws:
java.lang.IllegalArgumentException

getScopes

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

Specified by:
getScopes in interface ScriptContext
Returns:
list of scope values

getErrorWriter

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

Specified by:
getErrorWriter in interface ScriptContext
Returns:
The Writer

setErrorWriter

public void setErrorWriter(java.io.Writer writer)
Sets the Writer used to display error output.

Specified by:
setErrorWriter in interface ScriptContext
Parameters:
writer - The Writer.

getReader

public java.io.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(java.io.Reader reader)
Sets the Reader for scripts to read input .

Specified by:
setReader in interface ScriptContext
Parameters:
reader - The new Reader.

getWriter

public java.io.Writer getWriter()
Returns the Writer for scripts to use when displaying output.

Specified by:
getWriter in interface ScriptContext
Returns:
The Writer.

setWriter

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

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