类 SimpleScriptContext

javax.script
类 SimpleScriptContext

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

public class SimpleScriptContext
   
   
    
    extends 
    
    Object
   
   
   
   
    
    implements 
    
    ScriptContext
   
   
 

ScriptContext 的简单实现。

从以下版本开始:
1.6

字段摘要
protected BindingsengineScope 此字段是引擎范围 bindings。
protected WritererrorWriter 此字段是用于脚本输出错误的 writer。
protected BindingsglobalScope 此字段是全局范围 bindings。
protected Readerreader 此字段是用于脚本输入的 reader。
protected Writerwriter 此字段是用于脚本输出的 writer。
从接口 javax.script.ScriptContext 继承的字段
ENGINE_SCOPE, GLOBAL_SCOPE
构造方法摘要
SimpleScriptContext()
方法摘要
ObjectgetAttribute(String name) 获取范围中按搜索顺序最早出现的具有给定名称的属性的值。
ObjectgetAttribute(String name, int scope) 获取给定范围中某一属性的值。
intgetAttributesScope(String name) 获取用来定义属性的最小范围。
BindingsgetBindings(int scope) 如果指定范围为 ENGINE_SCOPE,则返回 engineScope 字段的值。
WritergetErrorWriter() 返回用来显示错误输出的 Writer
ReadergetReader() 返回脚本用来读取输入的 Reader
List<Integer>getScopes() 返回 ScriptContext 中所有有效范围值的不可变 List
WritergetWriter() 返回脚本的 Writer,以便在显示输出时使用。
ObjectremoveAttribute(String name, int scope) 移除给定范围中的某一属性。
voidsetAttribute(String name, Object value, int scope) 设置给定范围中某一属性的值。
voidsetBindings(Bindings bindings, int scope) 针对给定范围设置属性的 Bindings
voidsetErrorWriter(Writer writer) 设置用来显示错误输出的 Writer
voidsetReader(Reader reader) 设置脚本的 Reader,以读取输入。
voidsetWriter(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
返回:
范围值列表
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值