### javax.script

# Interface ScriptContext

Known Implementing Classes:
  PhpFacesScriptContext, PhpScriptContext, PhpSimpleHttpScriptContext, SimpleScriptContext

`public interface ScriptContext`

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

Authors:
  Nandika Jayawardana <nandika@opensource.lk>
  Sanka Samaranayake <sanka@opensource.lk>

## 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`

`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 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.

## Field Details

### ENGINE_SCOPE

    public static final int ENGINE_SCOPE

> defines an integer for the level of scope, ENGINE_SCOPE

> Field Value:
>   100

### GLOBAL_SCOPE

    public static final int GLOBAL_SCOPE

> defines an integer for the level of scope, GLOBAL_SCOPE

> Field Value:
>   200

## Method Details

### getAttribute

    public 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

    public 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

    public 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

    public 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

### getWriter

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

### removeAttribute

    public 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

    public 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

    public 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