类 SimpleScriptContext

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

public class SimpleScriptContext extends Object implements ScriptContext
ScriptContext 的简单实现。
自从:
1.6
  • 字段详细信息

    • writer

      protected Writer  writer
      这是用于从脚本输出的编写器。默认情况下,使用基于 System.outPrintWriter。访问器方法 getWriter、setWriter 用于管理此字段。
      参见:
    • errorWriter

      protected Writer  errorWriter
      这是用于从脚本输出错误的编写器。默认情况下,使用基于 System.errPrintWriter。访问器方法 getErrorWriter、setErrorWriter 用于管理该字段。
      参见:
    • reader

      protected Reader  reader
      这是用于脚本输入的阅读器。默认情况下,使用基于 System.inInputStreamReader 并且此阅读器使用默认字符集。访问器方法 getReader、setReader 用于管理此字段。
      参见:
    • engineScope

      protected Bindings  engineScope
      这是引擎作用域绑定。默认情况下,使用 SimpleBindings。访问器方法 setBindings、getBindings 用于管理此字段。
      参见:
    • globalScope

      protected Bindings  globalScope
      这是全局范围绑定。默认情况下,使用空值(这意味着没有全局范围)。访问器方法 setBindings、getBindings 用于管理此字段。
  • 构造方法详细信息

    • SimpleScriptContext

      public SimpleScriptContext()
      创建一个 SimpleScriptContext
  • 方法详情

    • setBindings

      public void setBindings(Bindings  bindings, int scope)
      为给定范围设置 Bindings 属性。如果 scope 的值为 ENGINE_SCOPE,则给定的 Bindings 将替换 engineScope 字段。如果范围的值为 GLOBAL_SCOPE,则给定的 Bindings 将替换 globalScope 字段。
      指定者:
      setBindings 在接口 ScriptContext
      参数:
      bindings - 要设置的属性的 Bindings
      scope - 设置属性的范围的值。
      抛出:
      IllegalArgumentException - 如果范围无效。
      NullPointerException - 如果范围的值为 ENGINE_SCOPE 且指定的 Bindings 为空。
    • getAttribute

      public Object  getAttribute(String  name)
      在搜索顺序中最早出现的范围内检索具有给定名称的属性的值。顺序由范围参数的数值确定(最低范围值在前)。
      指定者:
      getAttribute 在接口 ScriptContext
      参数:
      name - 要检索的属性的名称。
      返回:
      定义了具有给定名称的属性的最低作用域中的属性值。如果任何范围内不存在具有名称的属性,则返回 null。
      抛出:
      NullPointerException - 如果名称为空。
      IllegalArgumentException - 如果名称为空。
    • getAttribute

      public Object  getAttribute(String  name, int scope)
      获取给定范围内的属性值。
      指定者:
      getAttribute 在接口 ScriptContext
      参数:
      name - 要检索的属性的名称。
      scope - 检索属性的范围。
      返回:
      属性的值。返回 null 是给定范围内不存在的名称。
      抛出:
      IllegalArgumentException - 如果名称为空或范围的值无效。
      NullPointerException - 如果名称为空。
    • removeAttribute

      public Object  removeAttribute(String  name, int scope)
      删除给定范围内的属性。
      指定者:
      removeAttribute 在接口 ScriptContext
      参数:
      name - 要删除的属性的名称
      scope - 删除属性的范围
      返回:
      移除的值。
      抛出:
      IllegalArgumentException - 如果名称为空或范围无效。
      NullPointerException - 如果名称为空。
    • setAttribute

      public void setAttribute(String  name, Object  value, int scope)
      在给定范围内设置属性的值。如果范围是 GLOBAL_SCOPE 并且没有为 GLOBAL_SCOPE 设置绑定,则 setAttribute 调用是空操作。
      指定者:
      setAttribute 在接口 ScriptContext
      参数:
      name - 要设置的属性的名称
      value - 属性值
      scope - 设置属性的范围
      抛出:
      IllegalArgumentException - 如果名称为空或范围无效。
      NullPointerException - 如果名称为空。
    • getWriter

      public Writer  getWriter()
      返回显示输出时要使用的脚本的 Writer
      指定者:
      getWriter 在接口 ScriptContext
      返回:
      Writer
    • getReader

      public Reader  getReader()
      返回脚本用来读取输入的 Reader
      指定者:
      getReader 在接口 ScriptContext
      返回:
      Reader
    • setReader

      public void setReader(Reader  reader)
      为脚本设置 Reader 以读取输入。
      指定者:
      setReader 在接口 ScriptContext
      参数:
      reader - 新的 Reader
    • setWriter

      public void setWriter(Writer  writer)
      为显示输出时使用的脚本设置 Writer
      指定者:
      setWriter 在接口 ScriptContext
      参数:
      writer - 新的 Writer
    • getErrorWriter

      public Writer  getErrorWriter()
      返回用于显示错误输出的Writer
      指定者:
      getErrorWriter 在接口 ScriptContext
      返回:
      Writer
    • setErrorWriter

      public void setErrorWriter(Writer  writer)
      设置用于显示错误输出的Writer
      指定者:
      setErrorWriter 在接口 ScriptContext
      参数:
      writer - Writer
    • getAttributesScope

      public int getAttributesScope(String  name)
      获取定义属性的最低范围。
      指定者:
      getAttributesScope 在接口 ScriptContext
      参数:
      name - 属性名称。
      返回:
      最低范围。如果在任何范围内都没有定义具有给定名称的属性,则返回 -1。
      抛出:
      NullPointerException - 如果名称为空。
      IllegalArgumentException - 如果名称为空。
    • getBindings

      public Bindings  getBindings(int scope)
      如果指定范围为 ENGINE_SCOPE,则返回 engineScope 字段的值。如果指定范围为 GLOBAL_SCOPE,则返回 globalScope 字段的值。
      指定者:
      getBindings 在接口 ScriptContext
      参数:
      scope - 指定范围
      返回:
      engineScopeglobalScope 字段的值。
      抛出:
      IllegalArgumentException - 如果范围的值无效。
    • getScopes

      public List <Integer > getScopes()
      返回 ScriptContext 范围内所有有效值的不可变 List
      指定者:
      getScopes 在接口 ScriptContext
      返回:
      范围值列表