javax.script
Interface ScriptContext

All Known Subinterfaces:
IPhpScriptContext
All Known Implementing Classes:
AbstractPhpScriptContext, PhpCompiledScriptContext, PhpHttpScriptContext, PhpJavaBridgeRunnerScriptContext, PhpScriptContext, PhpScriptContextDecorator, PhpSecureScriptContext, ScriptContextDecorator, SimpleScriptContext

public interface ScriptContext

The ScriptContext interface exposes the key-value pairs in various scopes.

Author:
Nandika Jayawardana , Sanka Samaranayake

Field Summary
static int ENGINE_SCOPE
          defines an integer for the level of scope, ENGINE_SCOPE
static int GLOBAL_SCOPE
          defines an integer for the level of scope, GLOBAL_SCOPE
 
Method Summary
 java.lang.Object getAttribute(java.lang.String name)
          Retrieves the value of the 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 of an attribute in the specified scope.
 int getAttributesScope(java.lang.String name)
          Retrieves the lowest value of the scope for which the attribute is defined.
 Bindings getBindings(int scope)
          Retrieves the Namespace instance associated with the gieve 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 given attribute form the specified scope.
 void setAttribute(java.lang.String key, java.lang.Object value, int scope)
          Associates a specified value with the specifed name in the specified scope.
 void setBindings(Bindings namespace, int scope)
          Associates the specified namespace with the specified 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.
 

Field Detail

ENGINE_SCOPE

static final int ENGINE_SCOPE
defines an integer for the level of scope, ENGINE_SCOPE

See Also:
Constant Field Values

GLOBAL_SCOPE

static final int GLOBAL_SCOPE
defines an integer for the level of scope, GLOBAL_SCOPE

See Also:
Constant Field Values
Method Detail

getAttribute

java.lang.Object getAttribute(java.lang.String name)
                              throws java.lang.IllegalArgumentException
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.

Parameters:
name - the name of the attribute
Returns:
the associated value with the specified name
Throws:
java.lang.IllegalArgumentException - if the name is null

getAttribute

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

Parameters:
name - the name of the attribute
scope - the value of the scope
Returns:
the associated value for the specified name
Throws:
java.lang.IllegalArgumentException - if the name is null or the scope is invalid

getAttributesScope

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

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

Bindings getBindings(int scope)
Retrieves the Namespace instance associated with the gieve scope. Returns null if no namespace is assoicited with specified level of scope.

Parameters:
scope - the level of the scope
Returns:
the Namespace associated with the specified levle of scope

removeAttribute

java.lang.Object removeAttribute(java.lang.String name,
                                 int scope)
                                 throws java.lang.IllegalArgumentException
Removes the given attribute form the specified scope. Returns the removed object or null if no value is associated with the specified key in specified level of scope.

Parameters:
name - the name of the attribute
scope - the level of scope which inherit the attribute
Returns:
previous value associated with specified name
Throws:
java.lang.IllegalArgumentException - if the name is null or if the scope is invalid

setAttribute

void setAttribute(java.lang.String key,
                  java.lang.Object value,
                  int scope)
                  throws java.lang.IllegalArgumentException
Associates a specified value with the specifed name in the specified scope.

Parameters:
key - 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 or the scope is invalid

setBindings

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

Parameters:
namespace - the namespace to be associated with the specified level of scope
scope - the specified level of scope
Throws:
java.lang.IllegalArgumentException - if the scope is invalid

getWriter

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

Returns:
The Writer.

getErrorWriter

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

Returns:
The Writer

setWriter

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

Parameters:
writer - The new Writer.

setErrorWriter

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

Parameters:
writer - The Writer.

getReader

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

Returns:
The Reader.

setReader

void setReader(java.io.Reader reader)
Sets the Reader for scripts to read input .

Parameters:
reader - The new Reader.

getScopes

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

Returns:
list of scope values