- 
- All Known Implementing Classes:
- SimpleScriptContext
 
 public interface ScriptContextThe 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 theScriptContextmethods. ScriptContexts also expose Readers and Writers that can be used by the ScriptEngines for input and output.- Since:
- 1.6
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intENGINE_SCOPEEngineScope attributes are visible during the lifetime of a singleScriptEngineand a set of attributes is maintained for each engine.static intGLOBAL_SCOPEGlobalScope attributes are visible to all engines created by same ScriptEngineFactory.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Modifier and Type Method Description ObjectgetAttribute(String name)Retrieves the value of the attribute with the given name in the scope occurring earliest in the search order.ObjectgetAttribute(String name, int scope)Gets the value of an attribute in a given scope.intgetAttributesScope(String name)Get the lowest scope in which an attribute is defined.BindingsgetBindings(int scope)Gets theBindingsassociated with the given scope in thisScriptContext.WritergetErrorWriter()Returns theWriterused to display error output.ReadergetReader()Returns aReaderto be used by the script to read input.List<Integer>getScopes()Returns immutableListof all the valid values for scope in the ScriptContext.WritergetWriter()Returns theWriterfor scripts to use when displaying output.ObjectremoveAttribute(String name, int scope)Remove an attribute in a given scope.voidsetAttribute(String name, Object value, int scope)Sets the value of an attribute in a given scope.voidsetBindings(Bindings bindings, int scope)Associates aBindingsinstance with a particular scope in thisScriptContext.voidsetErrorWriter(Writer writer)Sets theWriterused to display error output.voidsetReader(Reader reader)Sets theReaderfor scripts to read input .voidsetWriter(Writer writer)Sets theWriterfor scripts to use when displaying output.
 
- 
- 
- 
Field Detail- 
ENGINE_SCOPEstatic final int ENGINE_SCOPE EngineScope attributes are visible during the lifetime of a singleScriptEngineand a set of attributes is maintained for each engine.- See Also:
- Constant Field Values
 
 - 
GLOBAL_SCOPEstatic final int GLOBAL_SCOPE GlobalScope attributes are visible to all engines created by same ScriptEngineFactory.- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
setBindingsvoid setBindings(Bindings bindings, int scope) Associates aBindingsinstance with a particular scope in thisScriptContext. Calls to thegetAttributeandsetAttributemethods must map to thegetandputmethods of theBindingsfor the specified scope.- Parameters:
- bindings- The- Bindingsto associate with the given scope
- scope- The scope
- Throws:
- IllegalArgumentException- If no- Bindingsis defined for the specified scope value in ScriptContexts of this type.
- NullPointerException- if value of scope is- ENGINE_SCOPEand the specified- Bindingsis null.
 
 - 
getBindingsBindings getBindings(int scope) Gets theBindingsassociated with the given scope in thisScriptContext.- Parameters:
- scope- The scope
- Returns:
- The associated Bindings. Returnsnullif it has not been set.
- Throws:
- IllegalArgumentException- If no- Bindingsis defined for the specified scope value in- ScriptContextof this type.
 
 - 
setAttributevoid setAttribute(String name, Object value, int scope) Sets the value of an attribute in a given scope. If the scope isGLOBAL_SCOPEand no Bindings is set forGLOBAL_SCOPE, then setAttribute call is a no-op.- Parameters:
- name- The name of the attribute to set
- value- The value of the attribute
- scope- The scope in which to set the attribute
- Throws:
- IllegalArgumentException- if the name is empty or if the scope is invalid.
- NullPointerException- if the name is null.
 
 - 
getAttributeObject 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 nullis the name does not exist in the given scope.
- Throws:
- IllegalArgumentException- if the name is empty or if the value of scope is invalid.
- NullPointerException- if the name is null.
 
 - 
removeAttributeObject 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.
- Throws:
- IllegalArgumentException- if the name is empty or if the scope is invalid.
- NullPointerException- if the name is null.
 
 - 
getAttributeObject 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 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.
- Throws:
- NullPointerException- if the name is null.
- IllegalArgumentException- if the name is empty.
 
 - 
getAttributesScopeint 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.
- Throws:
- NullPointerException- if name is null.
- IllegalArgumentException- if name is empty.
 
 - 
getWriterWriter getWriter() Returns theWriterfor scripts to use when displaying output.- Returns:
- The Writer.
 
 - 
getErrorWriterWriter getErrorWriter() Returns theWriterused to display error output.- Returns:
- The Writer
 
 - 
setWritervoid setWriter(Writer writer) Sets theWriterfor scripts to use when displaying output.- Parameters:
- writer- The new- Writer.
 
 - 
setErrorWritervoid setErrorWriter(Writer writer) Sets theWriterused to display error output.- Parameters:
- writer- The- Writer.
 
 - 
getReaderReader getReader() Returns aReaderto be used by the script to read input.- Returns:
- The Reader.
 
 - 
setReadervoid setReader(Reader reader) Sets theReaderfor scripts to read input .- Parameters:
- reader- The new- Reader.
 
 
- 
 
-