public class SimpleScriptContext extends Object implements ScriptContext
| Modifier and Type | Field and Description |
|---|---|
protected Bindings |
engineScope
这是引擎范围绑定。
|
protected Writer |
errorWriter
这是用于从脚本输出错误的作者。
|
protected Bindings |
globalScope
这是全局范围绑定。
|
protected Reader |
reader
这是用于从脚本输入的读者。
|
protected Writer |
writer
这是用于从脚本输出的作者。
|
ENGINE_SCOPE, GLOBAL_SCOPE| Constructor and Description |
|---|
SimpleScriptContext()
创建一个
SimpleScriptContext 。
|
| Modifier and Type | Method and Description |
|---|---|
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的所有有效值的不可变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用于显示输出时使用的脚本。
|
protected Writer writer
PrintWriter基于System.out使用。
Accessor方法getWriter,setWriter用于管理此字段。
System.out , PrintWriter
protected Writer errorWriter
PrintWriter基于System.err使用。
访问者方法getErrorWriter,setErrorWriter用于管理此字段。
System.err , PrintWriter
protected Reader reader
InputStreamReader基于System.in被使用,默认字符集是使用该阅读器。
访问者方法getReader,setReader用于管理此字段。
System.in , InputStreamReader
protected Bindings engineScope
SimpleBindings 。
访问方法setBindings,getBindings用于管理此字段。
SimpleBindings
protected Bindings globalScope
public void setBindings(Bindings bindings, int scope)
Bindings的属性。
如果范围的值为ENGINE_SCOPE则给定的Bindings替换engineScope字段。
如果范围值为GLOBAL_SCOPE ,给定的Bindings替换了globalScope字段。
setBindings在界面
ScriptContext
bindings - 要设置的
Bindings的Bindings。
scope - 属性设置范围的值。
IllegalArgumentException - 如果范围无效。
NullPointerException - 如果范围值为
ENGINE_SCOPE ,指定的
Bindings为空。
public Object getAttribute(String name)
getAttribute在界面
ScriptContext
name - 要检索的属性的名称。
NullPointerException - 如果名称为空。
IllegalArgumentException - 如果名称为空。
public Object getAttribute(String name, int scope)
getAttribute在界面
ScriptContext
name - 要检索的属性的名称。
scope - 检索属性的范围。
null是指定范围内不存在的名称。
IllegalArgumentException - 如果名称为空或范围的值无效。
NullPointerException - 如果名称为空。
public Object removeAttribute(String name, int scope)
removeAttribute在界面
ScriptContext
name - 要删除的属性的名称
scope - 删除属性的范围
IllegalArgumentException - 如果名称为空或范围无效。
NullPointerException - 如果名称为空。
public void setAttribute(String name, Object value, int scope)
setAttribute在界面
ScriptContext
name - 要设置的属性的名称
value - 属性的值
scope - 设置属性的范围
IllegalArgumentException - 如果名称为空或范围无效。
NullPointerException - 如果名称为空。
public Writer getWriter()
Writer脚本的显示输出时使用。
getWriter在界面
ScriptContext
Writer 。
public Reader getReader()
Reader以供脚本使用以读取输入。
getReader在界面
ScriptContext
Reader 。
public void setReader(Reader reader)
Reader脚本以读取输入。
setReader在界面
ScriptContext
reader - 全新
Reader 。
public void setWriter(Writer writer)
Writer用于显示输出时使用的脚本。
setWriter在界面
ScriptContext
writer - 全新
Writer 。
public Writer getErrorWriter()
Writer用于显示错误输出。
getErrorWriter在界面
ScriptContext
Writer
public void setErrorWriter(Writer writer)
Writer用于显示错误输出。
setErrorWriter在界面
ScriptContext
writer -
Writer 。
public int getAttributesScope(String name)
getAttributesScope在界面
ScriptContext
name -
name名称。
NullPointerException - 如果name为null。
IllegalArgumentException - 如果名称为空。
public Bindings getBindings(int scope)
ENGINE_SCOPE则返回engineScope字段的值。
如果指定的范围是GLOBAL_SCOPE则返回globalScope字段的值。
getBindings在界面
ScriptContext
scope - 指定的范围
engineScope或
globalScope字段。
IllegalArgumentException - 如果范围的值无效。
public List<Integer> getScopes()
List的List
List中范围的所有有效值。
getScopes在界面
ScriptContext
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.