java.lang.Object
javax.script.SimpleScriptContext
- 所有已实现的接口:
-
ScriptContext
ScriptContext的简单实现。
- 自1.6版本起:
- 1.6
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Bindings这是引擎范围的绑定。protected Writer这是用于从脚本输出错误的写入器。protected Bindings这是全局范围的绑定。protected Reader这是用于从脚本输入的读取器。protected Writer这是用于从脚本输出的写入器。Fields declared in interface javax.script.ScriptContext
ENGINE_SCOPE, GLOBAL_SCOPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAttribute(String name) 检索在搜索顺序中最早出现的范围中具有给定名称的属性的值。getAttribute(String name, int scope) 获取给定范围中属性的值。intgetAttributesScope(String name) 获取定义属性的最低范围。getBindings(int scope) 如果指定的范围是ENGINE_SCOPE,则返回engineScope字段的值。返回用于显示错误输出的Writer。返回供脚本读取输入使用的Reader。返回ScriptContext中所有有效范围的不可变List。返回供脚本显示输出使用的Writer。removeAttribute(String name, int scope) 在给定范围中移除属性。voidsetAttribute(String name, Object value, int scope) 在给定范围中设置属性的值。voidsetBindings(Bindings bindings, int scope) 为给定范围设置Bindings属性。voidsetErrorWriter(Writer writer) 设置用于显示错误输出的Writer。void设置脚本读取输入的Reader。void设置供脚本显示输出使用的Writer。
-
Field Details
-
writer
这是用于从脚本输出的写入器。默认情况下,基于System.out的PrintWriter被使用。访问器方法getWriter、setWriter用于管理此字段。- 参见:
-
errorWriter
这是用于从脚本输出错误的写入器。默认情况下,基于System.err的PrintWriter被使用。访问器方法getErrorWriter、setErrorWriter用于管理此字段。- 参见:
-
reader
这是用于从脚本输入的读取器。默认情况下,基于System.in的InputStreamReader被使用,并且此读取器使用默认字符集。访问器方法getReader、setReader用于管理此字段。- 参见:
-
engineScope
这是引擎范围的绑定。默认情况下,使用SimpleBindings。访问器方法setBindings、getBindings用于管理此字段。- 参见:
-
globalScope
这是全局范围的绑定。默认情况下,使用空值(表示没有全局范围)。访问器方法setBindings、getBindings用于管理此字段。
-
-
Constructor Details
-
SimpleScriptContext
public SimpleScriptContext()创建一个SimpleScriptContext。
-
-
Method Details
-
setBindings
为给定范围设置Bindings属性。如果范围的值是ENGINE_SCOPE,则给定的Bindings将替换engineScope字段。如果范围的值是GLOBAL_SCOPE,则给定的Bindings将替换globalScope字段。- 指定者:
-
setBindings在接口ScriptContext中 - 参数:
-
bindings- 要设置的Bindings属性。 -
scope- 设置属性的范围值。 - 抛出:
-
IllegalArgumentException- 如果范围无效。 -
NullPointerException- 如果范围的值是ENGINE_SCOPE且指定的Bindings为null。
-
getAttribute
检索搜索顺序中最早出现的范围中具有给定名称的属性的值。顺序由范围参数的数值确定(最低范围值优先)。- 指定者:
-
getAttribute在接口ScriptContext中 - 参数:
-
name- 要检索的属性的名称。 - 返回:
- 给定名称的属性在定义该名称的最低范围中的值。如果在任何范围中不存在具有该名称的属性,则返回null。
- 抛出:
-
NullPointerException- 如果名称为null。 -
IllegalArgumentException- 如果名称为空。
-
getAttribute
获取给定范围中属性的值。- 指定者:
-
getAttribute在接口ScriptContext中 - 参数:
-
name- 要检索的属性的名称。 -
scope- 要检索属性的范围。 - 返回:
-
属性的值。如果名称在给定范围中不存在,则返回
null。 - 抛出:
-
IllegalArgumentException- 如果名称为空或范围的值无效。 -
NullPointerException- 如果名称为null。
-
removeAttribute
在给定范围中移除属性。- 指定者:
-
removeAttribute在接口ScriptContext中 - 参数:
-
name- 要移除的属性的名称 -
scope- 要移除属性的范围 - 返回:
- 已移除的值。
- 抛出:
-
IllegalArgumentException- 如果名称为空或范围无效。 -
NullPointerException- 如果名称为null。
-
setAttribute
在给定范围中设置属性的值。如果范围是GLOBAL_SCOPE且未为GLOBAL_SCOPE设置Bindings,则setAttribute调用将不起作用。- 指定者:
-
setAttribute在接口ScriptContext中 - 参数:
-
name- 要设置的属性的名称 -
value- 属性的值 -
scope- 要设置属性的范围 - 抛出:
-
IllegalArgumentException- 如果名称为空或范围无效。 -
NullPointerException- 如果名称为null。
-
getWriter
返回供脚本显示输出时使用的Writer。- 指定者:
-
getWriter在接口ScriptContext中 - 返回:
-
Writer。
-
getReader
返回供脚本读取输入使用的Reader。- 指定者:
-
getReader在接口ScriptContext中 - 返回:
-
Reader。
-
setReader
设置供脚本读取输入的Reader。- 指定者:
-
setReader在接口ScriptContext中 - 参数:
-
reader- 新的Reader。
-
setWriter
设置供脚本显示输出时使用的Writer。- 指定者:
-
setWriter在接口ScriptContext - 参数:
-
writer- 新的Writer。
-
getErrorWriter
返回用于显示错误输出的Writer。- 指定者:
-
getErrorWriter在接口ScriptContext - 返回:
-
Writer
-
setErrorWriter
设置用于显示错误输出的Writer。- 指定者:
-
setErrorWriter在接口ScriptContext - 参数:
-
writer-Writer。
-
getAttributesScope
获取定义属性的最低作用域。- 指定者:
-
getAttributesScope在接口ScriptContext - 参数:
-
name- 属性的名称。 - 返回:
- 最低作用域。如果在任何作用域中未定义具有给定名称的属性,则返回-1。
- 抛出:
-
NullPointerException- 如果名称为null。 -
IllegalArgumentException- 如果名称为空。
-
getBindings
如果指定的作用域为ENGINE_SCOPE,则返回engineScope字段的值。如果指定的作用域为GLOBAL_SCOPE,则返回globalScope字段的值。- 指定者:
-
getBindings在接口ScriptContext - 参数:
-
scope- 指定的作用域 - 返回:
-
engineScope或globalScope字段的值。 - 抛出:
-
IllegalArgumentException- 如果作用域的值无效。
-
getScopes
返回 ScriptContext 中作用域的所有有效值的不可变List。- 指定者:
-
getScopes在接口ScriptContext - 返回:
- 作用域值的列表
-