javax.script
Class AbstractScriptEngine

java.lang.Object
  extended by javax.script.AbstractScriptEngine
All Implemented Interfaces:
ScriptEngine

public abstract class AbstractScriptEngine
extends java.lang.Object
implements ScriptEngine

See Javadoc of Java Scripting API


Field Summary
protected  ScriptContext context
           
 
Fields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
 
Constructor Summary
AbstractScriptEngine()
          Constructs a ScriptEngine using an uninitialized SimpleNamespace.
AbstractScriptEngine(Bindings bindings)
          Constructs a ScriptEngine using the specified namespace as its ENGINE_SCOPE.
 
Method Summary
 java.lang.Object eval(java.io.Reader reader)
          Evaluates a piece of script obtained using the specified reader as the script source.
 java.lang.Object eval(java.io.Reader reader, Bindings bindings)
          Evaluates a piece of scripts obtained using a reader as the script source and using the specified namespace as the SCRIPT_SCOPE.
 java.lang.Object eval(java.lang.String script)
          Evaluates a piece of script and returns the resultant object.
 java.lang.Object eval(java.lang.String script, Bindings nameSpace)
          Evaluates a piece of script using the specified namespace as its SCRIPT_SCOPE.
 java.lang.Object get(java.lang.String key)
          Retrieves the associated value with the specified key ScriptEngine namespace.
 Bindings getBindings(int scope)
          Retrieves a reference to the associated namespace for the specified level of scope.
 ScriptContext getContext()
          Returns the default ScriptContext of the ScriptEngine whose Bindings, Readers and Writers are used for script executions when no ScriptContext is specified.
protected  ScriptContext getScriptContext(Bindings bindings)
          Retrieves an instance of ScriptContext with namespaces associated with all the level of scopes and the specified namespace associated with SCRIPT_SCOPE.
 void put(java.lang.String key, java.lang.Object value)
          Associates a key and a value in the ScriptEngine namespace.
 void setBindings(Bindings bindings, int scope)
          Associates a namespace with a specified level of scope.
 void setContext(ScriptContext context)
          Sets the default ScriptContext of the ScriptEngine whose Bindings, Readers and Writers are used for script executions when no ScriptContext is specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.script.ScriptEngine
createBindings, eval, eval, getFactory
 

Field Detail

context

protected ScriptContext context
Constructor Detail

AbstractScriptEngine

public AbstractScriptEngine()
Constructs a ScriptEngine using an uninitialized SimpleNamespace.


AbstractScriptEngine

public AbstractScriptEngine(Bindings bindings)
Constructs a ScriptEngine using the specified namespace as its ENGINE_SCOPE.

Parameters:
bindings - the namespace to be used as the ENGINE_SCOPE
Method Detail

eval

public java.lang.Object eval(java.io.Reader reader)
                      throws ScriptException
Evaluates a piece of script obtained using the specified reader as the script source. Returns null for non-returning scripts.

Specified by:
eval in interface ScriptEngine
Parameters:
reader - the reader form which the script is obtained
Returns:
the value of the evaluated script
Throws:
ScriptException - if an error occurs

eval

public java.lang.Object eval(java.io.Reader reader,
                             Bindings bindings)
                      throws ScriptException
Evaluates a piece of scripts obtained using a reader as the script source and using the specified namespace as the SCRIPT_SCOPE. Returns null for non-returning scripts.

Specified by:
eval in interface ScriptEngine
Parameters:
reader - the reader from which the script is obtained
namespace - the namespace to be used as SCRIPT_SCOPE
Returns:
the value of the evaluated script
Throws:
ScriptException - if an error occurs

eval

public java.lang.Object eval(java.lang.String script)
                      throws ScriptException
Evaluates a piece of script and returns the resultant object. Returns null for non-returning scripts.

Specified by:
eval in interface ScriptEngine
Parameters:
script - the String representation of the script
Returns:
the value of the evaluated script
Throws:
ScriptException - if an error occurs

eval

public java.lang.Object eval(java.lang.String script,
                             Bindings nameSpace)
                      throws ScriptException
Evaluates a piece of script using the specified namespace as its SCRIPT_SCOPE. Returns null for non-returning scripts.

Specified by:
eval in interface ScriptEngine
Parameters:
script - the String representation of the script
namespace - the namespace to be used as the SCRIPT_SCOPE
Returns:
the value of the evaluated script
Throws:
ScriptException - if an error occurs

get

public java.lang.Object get(java.lang.String key)
Retrieves the associated value with the specified key ScriptEngine namespace. Returns null if no such value exists.

Specified by:
get in interface ScriptEngine
Parameters:
key - the associated key of the value
Returns:
the value associated with the specified key in ScriptEngine namespace

getBindings

public Bindings getBindings(int scope)
Retrieves a reference to the associated namespace for the specified level of scope.

Specified by:
getBindings in interface ScriptEngine
Parameters:
scope - the specified level of scope
Returns:
associated namespace for the specified level of scope
Throws:
java.lang.IllegalArgumentException - if the scope is invalid

getScriptContext

protected ScriptContext getScriptContext(Bindings bindings)
Retrieves an instance of ScriptContext with namespaces associated with all the level of scopes and the specified namespace associated with SCRIPT_SCOPE.

Parameters:
bindings - the namespace to be associated with SCRIPT_SCOPE
Returns:
an instance of ScriptContext with all namespaces of all scopes

put

public void put(java.lang.String key,
                java.lang.Object value)
Associates a key and a value in the ScriptEngine namespace.

Specified by:
put in interface ScriptEngine
Parameters:
key - String value which uniquely identifies the value
value - value which is to be associated with the specified key
Throws:
java.lang.IllegalArgumentException - if the key is null

setBindings

public void setBindings(Bindings bindings,
                        int scope)
                 throws java.lang.UnsupportedOperationException
Associates a namespace with a specified level of scope.

Specified by:
setBindings in interface ScriptEngine
Parameters:
bindings - the namespace to be associated with specified scope
scope - the level of scope of the specified namespace
Throws:
java.lang.IllegalArgumentException - if scope is invalid
java.lang.IllegalArgumentException - if the bindings is null and the scope is ScriptContext.ENGINE_SCOPE
java.lang.UnsupportedOperationException

getContext

public ScriptContext getContext()
Returns the default ScriptContext of the ScriptEngine whose Bindings, Readers and Writers are used for script executions when no ScriptContext is specified.

Specified by:
getContext in interface ScriptEngine
Returns:
The default ScriptContext of the ScriptEngine

setContext

public void setContext(ScriptContext context)
Sets the default ScriptContext of the ScriptEngine whose Bindings, Readers and Writers are used for script executions when no ScriptContext is specified.

Specified by:
setContext in interface ScriptEngine
Parameters:
scriptcontext - scriptContext that will replace the default ScriptContext in the ScriptEngine.


Copyright © 1999-2009 Apache Software Foundation. All Rights Reserved.