程序包 com.script

类 AbstractScriptEngine

java.lang.Object
com.script.AbstractScriptEngine
所有已实现的接口:
ScriptEngine

public abstract class AbstractScriptEngine extends Object implements ScriptEngine
Provides a standard implementation for several of the variants of the eval method.

eval(Reader)

eval(String)

eval(String, Bindings)

eval(Reader, Bindings)

are implemented using the abstract methods

eval(Reader,ScriptContext) or eval(String, ScriptContext)

with a SimpleScriptContext.

A SimpleScriptContext is used as the default ScriptContext of the AbstractScriptEngine..

从以下版本开始:
1.6
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    protected ScriptContext
    The default ScriptContext of this AbstractScriptEngine.

    从接口继承的字段 com.script.ScriptEngine

    FILENAME
  • 构造器概要

    构造器
    构造器
    说明
    Creates a new instance of AbstractScriptEngine using a SimpleScriptContext as its default ScriptContext.
    Creates a new instance using the specified Bindings as the ENGINE_SCOPE Bindings in the protected context field.
  • 方法概要

    修饰符和类型
    方法
    说明
    eval(Reader reader)
    eval(Reader) calls the abstract eval(Reader, ScriptContext) passing the value of the context field.
    eval(Reader reader, Bindings bindings)
    eval(Reader, Bindings) calls the abstract eval(Reader, ScriptContext) method, passing it a ScriptContext whose Reader, Writers and Bindings for scopes other that ENGINE_SCOPE are identical to those members of the protected context field.
    eval(String script)
    Same as eval(Reader) except that the abstract eval(String, ScriptContext) is used.
    eval(String script, Bindings bindings)
    Same as eval(Reader, Bindings) except that the abstract eval(String, ScriptContext) is used.
    get(String key)
    Gets the value for the specified key in the ENGINE_SCOPE of the protected context field.
    getBindings(int scope)
    Returns the Bindings with the specified scope value in the protected context field.
    Returns the value of the protected context field.
    protected ScriptContext
    Returns a SimpleScriptContext.
    void
    put(String key, Object value)
    Sets the specified value with the specified key in the ENGINE_SCOPE Bindings of the protected context field.
    void
    setBindings(Bindings bindings, int scope)
    Sets the Bindings with the corresponding scope value in the context field.
    void
    Sets the value of the protected context field to the specified ScriptContext.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    从接口继承的方法 com.script.ScriptEngine

    createBindings, eval, eval
  • 字段详细资料

    • context

      protected ScriptContext context
      The default ScriptContext of this AbstractScriptEngine.
  • 构造器详细资料

    • AbstractScriptEngine

      public AbstractScriptEngine()
      Creates a new instance of AbstractScriptEngine using a SimpleScriptContext as its default ScriptContext.
    • AbstractScriptEngine

      public AbstractScriptEngine(Bindings n)
      Creates a new instance using the specified Bindings as the ENGINE_SCOPE Bindings in the protected context field.
      参数:
      n - The specified Bindings.
      抛出:
      NullPointerException - if n is null.
  • 方法详细资料

    • setContext

      public void setContext(ScriptContext ctxt)
      Sets the value of the protected context field to the specified ScriptContext.
      指定者:
      setContext 在接口中 ScriptEngine
      参数:
      ctxt - The specified ScriptContext.
      抛出:
      NullPointerException - if ctxt is null.
    • getContext

      public ScriptContext getContext()
      Returns the value of the protected context field.
      指定者:
      getContext 在接口中 ScriptEngine
      返回:
      The value of the protected context field.
    • getBindings

      public Bindings getBindings(int scope)
      Returns the Bindings with the specified scope value in the protected context field.
      指定者:
      getBindings 在接口中 ScriptEngine
      参数:
      scope - The specified scope
      返回:
      The corresponding Bindings.
      抛出:
      IllegalArgumentException - if the value of scope is invalid for the type the protected context field.
    • setBindings

      public void setBindings(Bindings bindings, int scope)
      Sets the Bindings with the corresponding scope value in the context field.
      指定者:
      setBindings 在接口中 ScriptEngine
      参数:
      bindings - The specified Bindings.
      scope - The specified scope.
      抛出:
      IllegalArgumentException - if the value of scope is invalid for the type the context field.
      NullPointerException - if the bindings is null and the scope is ScriptContext.ENGINE_SCOPE
    • put

      public void put(String key, Object value)
      Sets the specified value with the specified key in the ENGINE_SCOPE Bindings of the protected context field.
      指定者:
      put 在接口中 ScriptEngine
      参数:
      key - The specified key.
      value - The specified value.
      抛出:
      NullPointerException - if key is null.
      IllegalArgumentException - if key is empty.
    • get

      public Object get(String key)
      Gets the value for the specified key in the ENGINE_SCOPE of the protected context field.
      指定者:
      get 在接口中 ScriptEngine
      参数:
      key - The key whose value is to be returned
      返回:
      The value for the specified key.
      抛出:
      NullPointerException - if key is null.
      IllegalArgumentException - if key is empty.
    • eval

      public Object eval(Reader reader, Bindings bindings) throws ScriptException
      eval(Reader, Bindings) calls the abstract eval(Reader, ScriptContext) method, passing it a ScriptContext whose Reader, Writers and Bindings for scopes other that ENGINE_SCOPE are identical to those members of the protected context field. The specified Bindings is used instead of the ENGINE_SCOPE Bindings of the context field.
      指定者:
      eval 在接口中 ScriptEngine
      参数:
      reader - A Reader containing the source of the script.
      bindings - A Bindings to use for the ENGINE_SCOPE while the script executes.
      返回:
      The return value from eval(Reader, ScriptContext)
      抛出:
      ScriptException - if an error occurs in script.
      NullPointerException - if any of the parameters is null.
    • eval

      public Object eval(String script, Bindings bindings) throws ScriptException
      Same as eval(Reader, Bindings) except that the abstract eval(String, ScriptContext) is used.
      指定者:
      eval 在接口中 ScriptEngine
      参数:
      script - A String containing the source of the script.
      bindings - A Bindings to use as the ENGINE_SCOPE while the script executes.
      返回:
      The return value from eval(String, ScriptContext)
      抛出:
      ScriptException - if an error occurs in script.
      NullPointerException - if any of the parameters is null.
    • eval

      public Object eval(Reader reader) throws ScriptException
      eval(Reader) calls the abstract eval(Reader, ScriptContext) passing the value of the context field.
      指定者:
      eval 在接口中 ScriptEngine
      参数:
      reader - A Reader containing the source of the script.
      返回:
      The return value from eval(Reader, ScriptContext)
      抛出:
      ScriptException - if an error occurs in script.
      NullPointerException - if any of the parameters is null.
    • eval

      public Object eval(String script) throws ScriptException
      Same as eval(Reader) except that the abstract eval(String, ScriptContext) is used.
      指定者:
      eval 在接口中 ScriptEngine
      参数:
      script - A String containing the source of the script.
      返回:
      The return value from eval(String, ScriptContext)
      抛出:
      ScriptException - if an error occurs in script.
      NullPointerException - if any of the parameters is null.
    • getScriptContext

      protected ScriptContext getScriptContext(Bindings nn)
      Returns a SimpleScriptContext. The SimpleScriptContext:

      • Uses the specified Bindings for its ENGINE_SCOPE
      • Uses the Bindings returned by the abstract getGlobalScope method as its GLOBAL_SCOPE
      • Uses the Reader and Writer in the default ScriptContext of this ScriptEngine


      A SimpleScriptContext returned by this method is used to implement eval methods using the abstract eval(Reader,Bindings) and eval(String,Bindings) versions.
      参数:
      nn - Bindings to use for the ENGINE_SCOPE
      返回:
      The SimpleScriptContext