javax.script
Class AbstractScriptEngine

java.lang.Object
  extended by javax.script.AbstractScriptEngine
All Implemented Interfaces:
ScriptEngine
Direct Known Subclasses:
InvocablePhpScriptEngine, PhpScriptEngine

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

GenericScriptEngine is an abstarct class which implements the ScriptEngine interface and it contains default implementations for several eval() methods.

Author:
Nandika Jayawardana , Sanka Samaranayake

Field Summary
 
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 namespace)
          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 nameSpace)
          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()
          Return the script context.
 void put(java.lang.String key, java.lang.Object value)
          Associates a key and a value in the ScriptEngine namespace.
 void setBindings(Bindings namespace, int scope)
          Associates a namespace with a specified level of scope.
 void setContext(ScriptContext ctx)
          Set a new context.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.script.ScriptEngine
createBindings, eval, eval, getFactory
 

Constructor Detail

AbstractScriptEngine

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


AbstractScriptEngine

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

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

setContext

public void setContext(ScriptContext ctx)
Set a new context.

Specified by:
setContext in interface ScriptEngine
Parameters:
ctx - The context

getContext

public ScriptContext getContext()
Return the script context.

Specified by:
getContext in interface ScriptEngine
Returns:
The script context.

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 nameSpace)
                      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

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 namespace,
                        int scope)
                 throws java.lang.UnsupportedOperationException
Associates a namespace with a specified level of scope.

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