FileDocCategorySizeDatePackage
ScriptContext.javaAPI DocJava SE 6 API6389Tue Jun 10 00:26:26 BST 2008javax.script

ScriptContext

public interface ScriptContext
The interface whose implementing classes are used to connect Script Engines with objects, such as scoped Bindings, in hosting applications. Each scope is a set of named attributes whose values can be set and retrieved using the ScriptContext methods. ScriptContexts also expose Readers and Writers that can be used by the ScriptEngines for input and output.
author
Mike Grogan
version
1.0
since
1.6

Fields Summary
public static final int
ENGINE_SCOPE
EngineScope attributes are visible during the lifetime of a single ScriptEngine and a set of attributes is maintained for each engine.
public static final int
GLOBAL_SCOPE
GlobalScope attributes are visible to all engines created by same ScriptEngineFactory.
Constructors Summary
Methods Summary
public java.lang.ObjectgetAttribute(java.lang.String name, int scope)
Gets the value of an attribute in a given scope.

param
name The name of the attribute to retrieve.
param
scope The scope in which to retrieve the attribute.
return
The value of the attribute. Returns null is the name does not exist in the given scope.
throws
IllegalArgumentException if the name is empty or if the value of scope is invalid.
throws
NullPointerException if the name is null.

public java.lang.ObjectgetAttribute(java.lang.String name)
Retrieves the value of the attribute with the given name in the scope occurring earliest in the search order. The order is determined by the numeric value of the scope parameter (lowest scope values first.)

param
name The name of the the attribute to retrieve.
return
The value of the attribute in the lowest scope for which an attribute with the given name is defined. Returns null if no attribute with the name exists in any scope.
throws
NullPointerException if the name is null.
throws
IllegalArgumentException if the name is empty.

public intgetAttributesScope(java.lang.String name)
Get the lowest scope in which an attribute is defined.

param
name Name of the attribute .
return
The lowest scope. Returns -1 if no attribute with the given name is defined in any scope.
throws
NullPointerException if name is null.
throws
IllegalArgumentException if name is empty.

public javax.script.BindingsgetBindings(int scope)
Gets the Bindings associated with the given scope in this ScriptContext.

return
The associated Bindings. Returns null if it has not been set.
throws
IllegalArgumentException If no Bindings is defined for the specified scope value in ScriptContext of this type.

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

return
The Writer

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

return
The Reader.

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

return
list of scope values

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

return
The Writer.

public java.lang.ObjectremoveAttribute(java.lang.String name, int scope)
Remove an attribute in a given scope.

param
name The name of the attribute to remove
param
scope The scope in which to remove the attribute
return
The removed value.
throws
IllegalArgumentException if the name is empty or if the scope is invalid.
throws
NullPointerException if the name is null.

public voidsetAttribute(java.lang.String name, java.lang.Object value, int scope)
Sets the value of an attribute in a given scope.

param
name The name of the attribute to set
param
value The value of the attribute
param
scope The scope in which to set the attribute
throws
IllegalArgumentException if the name is empty or if the scope is invalid.
throws
NullPointerException if the name is null.

public voidsetBindings(javax.script.Bindings bindings, int scope)
Associates a Bindings instance with a particular scope in this ScriptContext. Calls to the getAttribute and setAttribute methods must map to the get and put methods of the Bindings for the specified scope.

param
bindings The Bindings to associate with the given scope
param
scope The scope
throws
IllegalArgumentException If no Bindings is defined for the specified scope value in ScriptContexts of this type.
throws
NullPointerException if value of scope is ENGINE_SCOPE and the specified Bindings is null.

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

param
writer The Writer.

public voidsetReader(java.io.Reader reader)
Sets the Reader for scripts to read input .

param
reader The new Reader.

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

param
writer The new Writer.