- java.lang.Object
-
- javax.script.SimpleScriptContext
-
- 实现的所有接口
-
ScriptContext
public class SimpleScriptContext extends Object implements ScriptContext
ScriptContext的简单实现。- 从以下版本开始:
- 1.6
-
-
字段汇总
字段 变量和类型 字段 描述 protected BindingsengineScope这是引擎范围绑定。protected WritererrorWriter这是用于从脚本输出错误的编写器。protected BindingsglobalScope这是全局范围绑定。protected Readerreader这是用于脚本输入的阅读器。protected Writerwriter这是用于从脚本输出的writer。-
Fields declared in interface javax.script.ScriptContext
ENGINE_SCOPE, GLOBAL_SCOPE
-
-
构造方法摘要
构造方法 构造器 描述 SimpleScriptContext()创建一个SimpleScriptContext。
-
方法摘要
所有方法 实例方法 具体的方法 变量和类型 方法 描述 ObjectgetAttribute(String name)检索在搜索顺序中最早发生的范围内具有给定名称的属性的值。ObjectgetAttribute(String name, int scope)获取给定范围内的属性的值。intgetAttributesScope(String name)获取定义属性的最低范围。BindingsgetBindings(int scope)如果指定的范围是ENGINE_SCOPE则返回engineScope字段的值。ObjectremoveAttribute(String name, int scope)删除给定范围中的属性。voidsetAttribute(String name, Object value, int scope)设置给定范围中属性的值。voidsetBindings(Bindings bindings, int scope)为给定范围设置Bindings属性。-
声明方法的类 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
声明方法的接口 javax.script.ScriptContext
getErrorWriter, getReader, getScopes, getWriter, setErrorWriter, setReader, setWriter
-
-
-
-
字段详细信息
-
writer
protected Writer writer
这是用于从脚本输出的writer。 默认情况下,PrintWriter基于System.out使用。 访问器方法getWriter,setWriter用于管理此字段。- 另请参见:
-
System.out,PrintWriter
-
errorWriter
protected Writer errorWriter
这是用于从脚本输出错误的编写器。 默认情况下,PrintWriter基于System.err使用。 访问器方法getErrorWriter,setErrorWriter用于管理此字段。- 另请参见:
-
System.err,PrintWriter
-
reader
protected Reader reader
这是用于脚本输入的阅读器。 默认情况下,InputStreamReader基于System.in的使用和默认字符集是使用该阅读器。 访问器方法getReader,setReader用于管理此字段。- 另请参见:
-
System.in,InputStreamReader
-
engineScope
protected Bindings engineScope
这是引擎范围绑定。 默认情况下,使用SimpleBindings。 访问器方法setBindings,getBindings用于管理此字段。- 另请参见:
-
SimpleBindings
-
globalScope
protected Bindings globalScope
这是全局范围绑定。 默认情况下,使用空值(表示没有全局范围)。 访问器方法setBindings,getBindings用于管理此字段。
-
-
方法详细信息
-
setBindings
public void setBindings(Bindings bindings, int scope)
为给定范围设置Bindings属性。 如果范围的值为ENGINE_SCOPE则给定的Bindings替换engineScope字段。 如果范围的值为GLOBAL_SCOPE则给定的Bindings替换globalScope字段。- Specified by:
-
setBindings,界面ScriptContext - 参数
-
bindings- 要设置的属性Bindings。 -
scope- 设置属性的范围的值。 - 异常
-
IllegalArgumentException- 如果范围无效。 -
NullPointerException- 如果scope的值为ENGINE_SCOPE且指定的Bindings为null。
-
getAttribute
public Object getAttribute(String name)
检索在搜索顺序中最早发生的范围内具有给定名称的属性的值。 顺序由范围参数的数值确定(首先是最低范围值。)- Specified by:
-
getAttribute接口ScriptContext - 参数
-
name- 要检索的属性的名称。 - 结果
- 定义具有给定名称的属性的最低范围中的属性的值。 如果任何范围中都不存在具有该名称的属性,则返回null。
- 异常
-
NullPointerException- 如果名称为null。 -
IllegalArgumentException- 如果名称为空。
-
getAttribute
public Object getAttribute(String name, int scope)
获取给定范围内的属性的值。- Specified by:
-
getAttribute接口ScriptContext - 参数
-
name- 要检索的属性的名称。 -
scope- 检索属性的范围。 - 结果
-
属性的值。
返回
null是给定范围中不存在的名称。 - 异常
-
IllegalArgumentException- 如果名称为空或范围的值无效。 -
NullPointerException- 如果名称为null。
-
removeAttribute
public Object removeAttribute(String name, int scope)
删除给定范围中的属性。- Specified by:
-
removeAttribute,界面ScriptContext - 参数
-
name- 要删除的属性的名称 -
scope- 删除属性的范围 - 结果
- 删除的值。
- 异常
-
IllegalArgumentException- 如果名称为空或范围无效。 -
NullPointerException- 如果名称为null。
-
setAttribute
public void setAttribute(String name, Object value, int scope)
设置给定范围中属性的值。 如果范围是GLOBAL_SCOPE并且没有为GLOBAL_SCOPE设置GLOBAL_SCOPE,则setAttribute调用是no-op。- Specified by:
-
setAttribute接口ScriptContext - 参数
-
name- 要设置的属性的名称 -
value- 属性的值 -
scope- 设置属性的范围 - 异常
-
IllegalArgumentException- 如果名称为空或范围无效。 -
NullPointerException- 如果名称为null。
-
getAttributesScope
public int getAttributesScope(String name)
获取定义属性的最低范围。- Specified by:
-
getAttributesScope在接口ScriptContext - 参数
-
name- 属性的名称。 - 结果
- 最低范围。 如果在任何范围内未定义具有给定名称的属性,则返回-1。
- 异常
-
NullPointerException- 如果name为null。 -
IllegalArgumentException- 如果名称为空。
-
getBindings
public Bindings getBindings(int scope)
如果指定的范围是ENGINE_SCOPE则返回engineScope字段的值。 如果指定的范围是GLOBAL_SCOPE则返回globalScope字段的值。- Specified by:
-
getBindings接口ScriptContext - 参数
-
scope- 指定的范围 - 结果
-
engineScope或globalScope字段的值。 - 异常
-
IllegalArgumentException- 如果范围的值无效。
-
-