程序包 com.script
类 SimpleScriptContext
java.lang.Object
com.script.SimpleScriptContext
- 所有已实现的接口:
ScriptContext
Simple implementation of ScriptContext.
- 从以下版本开始:
- 1.6
-
字段概要
字段修饰符和类型字段说明protected 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.从接口继承的字段 com.script.ScriptContext
ENGINE_SCOPE, GLOBAL_SCOPE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明getAttribute(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.
-
字段详细资料
-
writer
This 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.- 另请参阅:
-
errorWriter
This 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.- 另请参阅:
-
reader
This 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.- 另请参阅:
-
engineScope
This is the engine scope bindings. By default, aSimpleBindingsis used. Accessor methods setBindings, getBindings are used to manage this field.- 另请参阅:
-
globalScope
This 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.
-
-
构造器详细资料
-
SimpleScriptContext
public SimpleScriptContext()Create aSimpleScriptContext.
-
-
方法详细资料
-
setBindings
Sets aBindingsof attributes for the given scope. If the value of scope isENGINE_SCOPEthe givenBindingsreplaces theengineScopefield. If the value of scope isGLOBAL_SCOPEthe givenBindingsreplaces theglobalScopefield.- 指定者:
setBindings在接口中ScriptContext- 参数:
bindings- TheBindingsof attributes to set.scope- The value of the scope in which the attributes are set.- 抛出:
IllegalArgumentException- if scope is invalid.NullPointerException- if the value of scope isENGINE_SCOPEand the specifiedBindingsis null.
-
getAttribute
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.)- 指定者:
getAttribute在接口中ScriptContext- 参数:
name- The name of the attribute to retrieve.- 返回:
- 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.
- 抛出:
NullPointerException- if the name is null.IllegalArgumentException- if the name is empty.
-
getAttribute
Gets the value of an attribute in a given scope.- 指定者:
getAttribute在接口中ScriptContext- 参数:
name- The name of the attribute to retrieve.scope- The scope in which to retrieve the attribute.- 返回:
- The value of the attribute. Returns
nullis the name does not exist in the given scope. - 抛出:
IllegalArgumentException- if the name is empty or if the value of scope is invalid.NullPointerException- if the name is null.
-
removeAttribute
Remove an attribute in a given scope.- 指定者:
removeAttribute在接口中ScriptContext- 参数:
name- The name of the attribute to removescope- The scope in which to remove the attribute- 返回:
- The removed value.
- 抛出:
IllegalArgumentException- if the name is empty or if the scope is invalid.NullPointerException- if the name is null.
-
setAttribute
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.- 指定者:
setAttribute在接口中ScriptContext- 参数:
name- The name of the attribute to setvalue- The value of the attributescope- The scope in which to set the attribute- 抛出:
IllegalArgumentException- if the name is empty or if the scope is invalid.NullPointerException- if the name is null.
-
getWriter
Returns theWriterfor scripts to use when displaying output.- 指定者:
getWriter在接口中ScriptContext- 返回:
- The
Writer.
-
getReader
Returns aReaderto be used by the script to read input.- 指定者:
getReader在接口中ScriptContext- 返回:
- The
Reader.
-
setReader
Sets theReaderfor scripts to read input .- 指定者:
setReader在接口中ScriptContext- 参数:
reader- The newReader.
-
setWriter
Sets theWriterfor scripts to use when displaying output.- 指定者:
setWriter在接口中ScriptContext- 参数:
writer- The newWriter.
-
getErrorWriter
Returns theWriterused to display error output.- 指定者:
getErrorWriter在接口中ScriptContext- 返回:
- The
Writer
-
setErrorWriter
Sets theWriterused to display error output.- 指定者:
setErrorWriter在接口中ScriptContext- 参数:
writer- TheWriter.
-
getAttributesScope
Get the lowest scope in which an attribute is defined.- 指定者:
getAttributesScope在接口中ScriptContext- 参数:
name- Name of the attribute .- 返回:
- The lowest scope. Returns -1 if no attribute with the given name is defined in any scope.
- 抛出:
NullPointerException- if name is null.IllegalArgumentException- if name is empty.
-
getBindings
Returns the value of theengineScopefield if specified scope isENGINE_SCOPE. Returns the value of theglobalScopefield if the specified scope isGLOBAL_SCOPE.- 指定者:
getBindings在接口中ScriptContext- 参数:
scope- The specified scope- 返回:
- The value of either the
engineScopeorglobalScopefield. - 抛出:
IllegalArgumentException- if the value of scope is invalid.
-
getScopes
Returns immutableListof all the valid values for scope in the ScriptContext.- 指定者:
getScopes在接口中ScriptContext- 返回:
- list of scope values
-