javax.script
Interface ScriptContext

All Known Subinterfaces:
HttpScriptContext
All Known Implementing Classes:
GenericHttpScriptContext, SimpleScriptContext

public interface ScriptContext

See Javadoc of Java Scripting API


Field Summary
static int ENGINE_SCOPE
          defines an integer for the scope, ENGINE_SCOPE
static int GLOBAL_SCOPE
          defines an integer for the scope, GLOBAL_SCOPE
 
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.
 

Field Detail

ENGINE_SCOPE

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

See Also:
Constant Field Values

GLOBAL_SCOPE

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

See Also:
Constant Field Values
Method Detail

getAttribute

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.

Parameters:
name - the name of the attribute
Returns:
the associated value with the specified name
Throws:
IllegalArgumentException - if the name is empty
NullPointerException - if the name is null

getAttribute

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.

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

getAttributesScope

int getAttributesScope(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
Throws:
NullPointerException - if name is null.
IllegalArgumentException - if name is empty.

getBindings

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

Parameters:
scope - the scope
Returns:
the Bindings associated with the specified scope
Throws:
IllegalArgumentException - If no Bindings is defined for the specified scope value in ScriptContext of this type.

getWriter

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

Returns:
an instance of java.io.Writer

getErrorWriter

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

Returns:
the error writer

setWriter

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

Parameters:
writer - the new writer.

setErrorWriter

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

Parameters:
writer - the new writer.

getReader

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

Returns:
the reader

setReader

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

Parameters:
reader - the new reader

removeAttribute

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.

Parameters:
name - the name of the attribute
scope - the scope from which to remove the attribute
Returns:
previous value associated with specified name
Throws:
NullPointerException - if the name is null
IllegalArgumentException - if the name is empty or if the scope is invalid

setAttribute

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

Parameters:
name - the name of the attribute
value - the value of the attribute
scope - the scope
Throws:
IllegalArgumentException - if the name is null or the scope is invalid
NullPointerException - if the name is null.

setBindings

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

Parameters:
bindings - the Bindings to be associated with the specified scope
scope - the scope
Throws:
IllegalArgumentException - if the scope is invalid
NullPointerException - if the bindings is null and the scope is ScriptEngine.ENGINE_SCOPE

getScopes

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

Returns:
the list


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