javax.script
Class SimpleScriptContext

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

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()
           
 
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 getWriter()
          Retrieves an instance of java.io.Writer which can be used by scripts to display their 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleScriptContext

public SimpleScriptContext()
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 - if the name is null

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 - if the name is null or the scope is invalid

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

getWriter

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

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:
IllegalArguementException - if the name is null scope is invalid
java.lang.IllegalArgumentException - if the name is null or the 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 - if the scope is invalid