JavaTM 2 Platform
Standard Ed. 6

javax.script
类 SimpleScriptContext

java.lang.Object
  继承者 javax.script.SimpleScriptContext
所有已实现的接口:
ScriptContext

public class SimpleScriptContext
extends Object
implements ScriptContext

ScriptContext 的简单实现。

从以下版本开始:
1.6

字段摘要
protected  Bindings engineScope
          此字段是引擎范围 bindings。
protected  Writer errorWriter
          此字段是用于脚本输出错误的 writer。
protected  Bindings globalScope
          此字段是全局范围 bindings。
protected  Reader reader
          此字段是用于脚本输入的 reader。
protected  Writer writer
          此字段是用于脚本输出的 writer。
 
从接口 javax.script.ScriptContext 继承的字段
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,以便在显示输出时使用。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

writer

protected Writer writer
此字段是用于脚本输出的 writer。默认情况下,使用基于 System.outPrintWriter。可使用存取方法 getWriter 和 setWriter 来管理此字段。

另请参见:
System.out, PrintWriter

errorWriter

protected Writer errorWriter
此字段是用于脚本输出错误的 writer。默认情况下,使用基于 System.errPrintWriter。可使用存取方法 getErrorWriter 和 setErrorWriter 来管理此字段。

另请参见:
System.err, PrintWriter

reader

protected Reader reader
此字段是用于脚本输入的 reader。默认情况下,此 reader 使用基于 System.inInputStreamReader 和默认字符集。可使用存取方法 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 - 指定范围
返回:
engineScopeglobalScope 字段的值。
抛出:
IllegalArgumentException - 如果 scope 的值无效。

getScopes

public List<Integer> getScopes()
返回 ScriptContext 中所有有效范围值的不可变 List

指定者:
接口 ScriptContext 中的 getScopes
返回:
范围值列表

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only