类 SimpleScriptContext
来源:互联网 发布:java开发rest api 编辑:程序博客网 时间:2024/06/14 22:09
javax.script
类 SimpleScriptContext
java.lang.Object javax.script.SimpleScriptContext
- 所有已实现的接口:
- ScriptContext
public class SimpleScriptContext
- extends Object
- implements ScriptContext
ScriptContext 的简单实现。
- 从以下版本开始:
- 1.6
protectedBindings
engineScope
此字段是引擎范围 bindings。protectedWriter
errorWriter
此字段是用于脚本输出错误的 writer。protectedBindings
globalScope
此字段是全局范围 bindings。protectedReader
reader
此字段是用于脚本输入的 reader。protectedWriter
writer
此字段是用于脚本输出的 writer。ENGINE_SCOPE, GLOBAL_SCOPE
SimpleScriptContext()
Object
getAttribute(String name)
获取范围中按搜索顺序最早出现的具有给定名称的属性的值。Object
getAttribute(String name, int scope)
获取给定范围中某一属性的值。int
getAttributesScope(String name)
获取用来定义属性的最小范围。Bindings
getBindings(int scope)
如果指定范围为 ENGINE_SCOPE
,则返回 engineScope
字段的值。Writer
getErrorWriter()
返回用来显示错误输出的 Writer
。Reader
getReader()
返回脚本用来读取输入的 Reader
。List<Integer>
getScopes()
返回 ScriptContext 中所有有效范围值的不可变List
。Writer
getWriter()
返回脚本的 Writer
,以便在显示输出时使用。Object
removeAttribute(String name, int scope)
移除给定范围中的某一属性。void
setAttribute(String name,Object value, int scope)
设置给定范围中某一属性的值。void
setBindings(Bindings bindings, int scope)
针对给定范围设置属性的Bindings
。void
setErrorWriter(Writer writer)
设置用来显示错误输出的Writer
。void
setReader(Reader reader)
设置脚本的Reader
,以读取输入。void
setWriter(Writer writer)
设置脚本的Writer
,以便在显示输出时使用。clone, equals, finalize, getClass, hashCode, notify, notifyAll,toString, wait, wait, wait
writer
protected Writer writer
- 此字段是用于脚本输出的 writer。默认情况下,使用基于
System.out
的PrintWriter
。可使用存取方法 getWriter 和 setWriter 来管理此字段。- 另请参见:
System.out
,PrintWriter
errorWriter
protected Writer errorWriter
- 此字段是用于脚本输出错误的 writer。默认情况下,使用基于
System.err
的PrintWriter
。可使用存取方法 getErrorWriter 和 setErrorWriter 来管理此字段。- 另请参见:
System.err
,PrintWriter
reader
protected Reader reader
- 此字段是用于脚本输入的 reader。默认情况下,此 reader 使用基于
System.in
的InputStreamReader
和默认字符集。可使用存取方法 getReader 和 setReader 来管理此字段。- 另请参见:
System.in
,InputStreamReader
engineScope
protected Bindings engineScope
- 此字段是引擎范围 bindings。默认情况下,使用
SimpleBindings
。可使用存取方法 setBindings 和 getBindings 来管理此字段。- 另请参见:
SimpleBindings
globalScope
protected Bindings globalScope
- 此字段是全局范围 bindings。默认情况下,使用 null 值(表示没有全局范围)。可使用存取方法 setBindings 和 getBindings 来管理此字段。
SimpleScriptContext
public SimpleScriptContext()
setBindings
public void setBindings(Bindings bindings, int scope)
- 针对给定范围设置属性的
Bindings
。如果范围值为ENGINE_SCOPE
,则使用给定Bindings
替代engineScope
字段。如果范围值为GLOBAL_SCOPE
,则使用给定Bindings
替换globalScope
字段。 - 指定者:
- 接口
ScriptContext
中的setBindings
- 参数:
bindings
- 要设置的属性的Bindings
。scope
- 范围值,将在该范围中设置属性。- 抛出:
IllegalArgumentException
- 如果 scope 无效。NullPointerException
- 如果 scope 的值为ENGINE_SCOPE
并且指定的Bindings
为 null。
getAttribute
public Object getAttribute(String name)
- 获取范围中按搜索顺序最早出现的具有给定名称的属性的值。搜索顺序由范围参数的数值确定(从最小的范围值开始)。
- 指定者:
- 接口
ScriptContext
中的getAttribute
- 参数:
name
- 要获取的属性的名称。- 返回:
- 具有给定名称的属性的值,该属性位于定义它的最小范围中。如果任何范围中都不存在具有该名称的属性,则返回 null。
- 抛出:
NullPointerException
- 如果 name 为 null。IllegalArgumentException
- 如果 name 为空。
getAttribute
public Object getAttribute(String name, int scope)
- 获取给定范围中某一属性的值。
- 指定者:
- 接口
ScriptContext
中的getAttribute
- 参数:
name
- 要获取的属性名称。scope
- 将在其中获取属性的范围。- 返回:
- 属性值。返回
null
表示 name 不存在于给定范围中。 - 抛出:
IllegalArgumentException
- 如果 name 为空,或者 scope 的值无效。NullPointerException
- 如果 name 为 null。
removeAttribute
public Object removeAttribute(String name, int scope)
- 移除给定范围中的某一属性。
- 指定者:
- 接口
ScriptContext
中的removeAttribute
- 参数:
name
- 要移除的属性的名称scope
- 移除属性的范围- 返回:
- 移除的值。
- 抛出:
IllegalArgumentException
- 如果 name 为空,或者 scope 无效。NullPointerException
- 如果 name 为 null。
setAttribute
public void setAttribute(String name, Object value, int scope)
- 设置给定范围中某一属性的值。
- 指定者:
- 接口
ScriptContext
中的setAttribute
- 参数:
name
- 要设置的属性的名称value
- 属性值scope
- 属性的设置范围- 抛出:
IllegalArgumentException
- 如果 name 为空,或者 scope 无效。NullPointerException
- 如果 name 为 null。
getWriter
public Writer getWriter()
- 返回脚本的
Writer
,以便在显示输出时使用。 - 指定者:
- 接口
ScriptContext
中的getWriter
- 返回:
Writer
。
getReader
public Reader getReader()
- 返回脚本用来读取输入的
Reader
。 - 指定者:
- 接口
ScriptContext
中的getReader
- 返回:
Reader
。
setReader
public void setReader(Reader reader)
- 设置脚本的
Reader
,以读取输入。 - 指定者:
- 接口
ScriptContext
中的setReader
- 参数:
reader
- 新的Reader
。
setWriter
public void setWriter(Writer writer)
- 设置脚本的
Writer
,以便在显示输出时使用。 - 指定者:
- 接口
ScriptContext
中的setWriter
- 参数:
writer
- 新的Writer
。
getErrorWriter
public Writer getErrorWriter()
- 返回用来显示错误输出的
Writer
。 - 指定者:
- 接口
ScriptContext
中的getErrorWriter
- 返回:
Writer
setErrorWriter
public void setErrorWriter(Writer writer)
- 设置用来显示错误输出的
Writer
。 - 指定者:
- 接口
ScriptContext
中的setErrorWriter
- 参数:
writer
-Writer
。
getAttributesScope
public int getAttributesScope(String name)
- 获取用来定义属性的最小范围。
- 指定者:
- 接口
ScriptContext
中的getAttributesScope
- 参数:
name
- 属性的名称。- 返回:
- 最小范围。如果在任何范围内都没有定义具有给定名称的属性,则返回 -1。
- 抛出:
NullPointerException
- 如果 name 为 null。IllegalArgumentException
- 如果 name 为空。
getBindings
public Bindings getBindings(int scope)
- 如果指定范围为
ENGINE_SCOPE
,则返回engineScope
字段的值。如果指定范围为GLOBAL_SCOPE
,则返回globalScope
字段的值。 - 指定者:
- 接口
ScriptContext
中的getBindings
- 参数:
scope
- 指定范围- 返回:
engineScope
或globalScope
字段的值。- 抛出:
IllegalArgumentException
- 如果 scope 的值无效。
getScopes
public List<Integer> getScopes()
- 返回 ScriptContext 中所有有效范围值的不可变
List
。 - 指定者:
- 接口
ScriptContext
中的getScopes
- 返回:
- 范围值列表