This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


javax.script
interface ScriptContext

All Known Implementing Classes:
SimpleScriptContext

Most common way to construct:

ScriptEngine meEngine = …;

ScriptContext context = meEngine.getContext();

Based on 79 examples


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.


Field Summary
static int ENGINE_SCOPE
          EngineScope attributes are visible during the lifetime of a single ScriptEngine and a set of attributes is maintained for each engine.
static int GLOBAL_SCOPE
          GlobalScope attributes are visible to all engines created by same ScriptEngineFactory.
 
Method Summary
 Object

          Retrieves the value of the attribute with the given name in the scope occurring earliest in the search order.
 Object
getAttribute(String name, int scope)

          Gets the value of an attribute in a given scope.
 int

          Get the lowest scope in which an attribute is defined.
 Bindings
getBindings(int scope)

          Gets the Bindings associated with the given scope in this ScriptContext.
 Writer

          Returns the Writer used to display error output.
 Reader

          Returns a Reader to be used by the script to read input.
 List

          Returns immutable List of all the valid values for scope in the ScriptContext.
 Writer

          Returns the Writer for scripts to use when displaying output.
 Object
removeAttribute(String name, int scope)

          Remove an attribute in a given scope.
 void
setAttribute(String name, Object value, int scope)

          Sets the value of an attribute in a given scope.
 void
setBindings(Bindings bindings, int scope)

          Associates a Bindings instance with a particular scope in this ScriptContext.
 void

          Sets the Writer used to display error output.
 void
setReader(Reader reader)

          Sets the Reader for scripts to read input .
 void
setWriter(Writer writer)

          Sets the Writer for scripts to use when displaying output.
 

Field Detail

ENGINE_SCOPE

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.

GLOBAL_SCOPE

public static final int GLOBAL_SCOPE
GlobalScope attributes are visible to all engines created by same ScriptEngineFactory.
Method Detail

getAttribute

public Object getAttribute(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.)

Parameters:
name - The name of the the attribute to retrieve.
Returns:
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.

getAttribute

public Object getAttribute(String name,
                           int scope)
Gets the value of an attribute in a given scope.

Parameters:
name - The name of the attribute to retrieve.
scope - The scope in which to retrieve the attribute.
Returns:
The value of the attribute. Returns null is the name does not exist in the given scope.

getAttributesScope

public int getAttributesScope(String name)
Get the lowest scope in which an attribute is defined.

Parameters:
name - Name of the attribute .
Returns:
The lowest scope. Returns -1 if no attribute with the given name is defined in any scope.

getBindings

public Bindings getBindings(int scope)
Gets the Bindings associated with the given scope in this ScriptContext.

Parameters:
scope
Returns:
The associated Bindings. Returns null if it has not been set.

getErrorWriter

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

Returns:
The Writer

getReader

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

Returns:
The Reader.

getScopes

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

Returns:
list of scope values

getWriter

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

Returns:
The Writer.

removeAttribute

public Object removeAttribute(String name,
                              int scope)
Remove an attribute in a given scope.

Parameters:
name - The name of the attribute to remove
scope - The scope in which to remove the attribute
Returns:
The removed value.

setAttribute

public void setAttribute(String name,
                         Object value,
                         int scope)
Sets the value of an attribute in a given scope.

Parameters:
name - The name of the attribute to set
value - The value of the attribute
scope - The scope in which to set the attribute

setBindings

public void setBindings(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.

Parameters:
bindings - The Bindings to associate with the given scope
scope - The scope

setErrorWriter

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

Parameters:
writer - The Writer.

setReader

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

Parameters:
reader - The new Reader.

setWriter

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

Parameters:
writer - The new Writer.


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.