Class SimpleScriptContext
java.lang.Object
javax.script.SimpleScriptContext
- All Implemented Interfaces:
- ScriptContext
Simple implementation of ScriptContext.
- Since:
- 1.6
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected BindingsThis is the engine scope bindings.protected WriterThis is the writer to be used to output errors from scripts.protected BindingsThis is the global scope bindings.protected ReaderThis is the reader to be used for input from scripts.protected WriterThis is the writer to be used to output from scripts.Fields declared in interface javax.script.ScriptContextENGINE_SCOPE, GLOBAL_SCOPE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptiongetAttribute(String name) Retrieves the value of the attribute with the given name in the scope occurring earliest in the search order.getAttribute(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.getBindings(int scope) Returns the value of theengineScopefield if specified scope isENGINE_SCOPE.Returns theWriterused to display error output.Returns aReaderto be used by the script to read input.Returns immutableListof all the valid values for scope in the ScriptContext.Returns theWriterfor scripts to use when displaying output.removeAttribute(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) Sets aBindingsof attributes for the given scope.voidsetErrorWriter(Writer writer) Sets theWriterused to display error output.voidSets theReaderfor scripts to read input .voidSets theWriterfor scripts to use when displaying output.
- 
Field Details- 
writerThis is the writer to be used to output from scripts. By default, aPrintWriterbased onSystem.outis used. Accessor methods getWriter, setWriter are used to manage this field.- See Also:
 
- 
errorWriterThis is the writer to be used to output errors from scripts. By default, aPrintWriterbased onSystem.erris used. Accessor methods getErrorWriter, setErrorWriter are used to manage this field.- See Also:
 
- 
readerThis is the reader to be used for input from scripts. By default, aInputStreamReaderbased onSystem.inis used and default charset is used by this reader. Accessor methods getReader, setReader are used to manage this field.- See Also:
 
- 
engineScopeThis is the engine scope bindings. By default, aSimpleBindingsis used. Accessor methods setBindings, getBindings are used to manage this field.- See Also:
 
- 
globalScopeThis is the global scope bindings. By default, a null value (which means no global scope) is used. Accessor methods setBindings, getBindings are used to manage this field.
 
- 
- 
Constructor Details- 
SimpleScriptContextpublic SimpleScriptContext()Create aSimpleScriptContext.
 
- 
- 
Method Details- 
setBindingsSets aBindingsof attributes for the given scope. If the value of scope isENGINE_SCOPEthe givenBindingsreplaces theengineScopefield. If the value of scope isGLOBAL_SCOPEthe givenBindingsreplaces theglobalScopefield.- Specified by:
- setBindingsin interface- ScriptContext
- Parameters:
- bindings- The- Bindingsof attributes to set.
- scope- The value of the scope in which the attributes are set.
- Throws:
- IllegalArgumentException- if scope is invalid.
- NullPointerException- if the value of scope is- ENGINE_SCOPEand the specified- Bindingsis null.
 
- 
getAttributeRetrieves 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.)- Specified by:
- getAttributein interface- ScriptContext
- 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.
 
- 
getAttributeGets the value of an attribute in a given scope.- Specified by:
- getAttributein interface- ScriptContext
- 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.
 
- 
removeAttributeRemove an attribute in a given scope.- Specified by:
- removeAttributein interface- ScriptContext
- 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.
 
- 
setAttributeSets 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.- Specified by:
- setAttributein interface- ScriptContext
- 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.
 
- 
getWriterReturns theWriterfor scripts to use when displaying output.- Specified by:
- getWriterin interface- ScriptContext
- Returns:
- The Writer.
 
- 
getReaderReturns aReaderto be used by the script to read input.- Specified by:
- getReaderin interface- ScriptContext
- Returns:
- The Reader.
 
- 
setReaderSets theReaderfor scripts to read input .- Specified by:
- setReaderin interface- ScriptContext
- Parameters:
- reader- The new- Reader.
 
- 
setWriterSets theWriterfor scripts to use when displaying output.- Specified by:
- setWriterin interface- ScriptContext
- Parameters:
- writer- The new- Writer.
 
- 
getErrorWriterReturns theWriterused to display error output.- Specified by:
- getErrorWriterin interface- ScriptContext
- Returns:
- The Writer
 
- 
setErrorWriterSets theWriterused to display error output.- Specified by:
- setErrorWriterin interface- ScriptContext
- Parameters:
- writer- The- Writer.
 
- 
getAttributesScopeGet the lowest scope in which an attribute is defined.- Specified by:
- getAttributesScopein interface- ScriptContext
- 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.
 
- 
getBindingsReturns the value of theengineScopefield if specified scope isENGINE_SCOPE. Returns the value of theglobalScopefield if the specified scope isGLOBAL_SCOPE.- Specified by:
- getBindingsin interface- ScriptContext
- Parameters:
- scope- The specified scope
- Returns:
- The value of either the  engineScopeorglobalScopefield.
- Throws:
- IllegalArgumentException- if the value of scope is invalid.
 
- 
getScopesReturns immutableListof all the valid values for scope in the ScriptContext.- Specified by:
- getScopesin interface- ScriptContext
- Returns:
- list of scope values
 
 
-