javax.script
Interface ScriptEngine

All Known Implementing Classes:
AbstractScriptEngine

public interface ScriptEngine

See Javadoc of Java Scripting API


Field Summary
static String ARGV
          Reserved key associated with an object array which is used to pass set of positional parameters to the ScriptEngines.
static String ENGINE
          Reserved key associated with the name of the Java ScriptEngine
static String ENGINE_VERSION
          Reserved key associated with the version of the Java ScriptEngine
static String FILENAME
          Reserved key associated with name of the file which contains the source of the script.
static String LANGUAGE
          Reserved key associated with the name of the supported scripting language
static String LANGUAGE_VERSION
          Reserved key associated with the version of the supported scripting language
static String NAME
          Reserved key associated with the named value which identifies the short name of the supported language
 
Method Summary
 Bindings createBindings()
          Retrieves an uninitialized Bindings which can be used as the scope of the ScriptEngine.
 Object eval(Reader reader)
          Evaluates a script obtained using the specified reader as the script source.
 Object eval(Reader reader, Bindings bindings)
          Evaluates a script obtained using a reader as the script source and using the specified namespace as the ENGINE_SCOPE.
 Object eval(Reader reader, ScriptContext context)
          Evaluates a script obtained using the specified reader as the script source and using the bindings in the specifed ScriptContext.
 Object eval(String script)
          Evaluates a script contained in a String and returns the resultant object.
 Object eval(String script, Bindings bindings)
          Evaluates a piece of script using the specified namespace as the ENGINE_SCOPE.
 Object eval(String script, ScriptContext context)
          Evaluates a script using the bindings in the specifed ScriptContext.
 Object get(String key)
          Retrieves the value which is associated with the specified key in the state of the ScriptEngine.
 Bindings getBindings(int scope)
          Retrieves a reference to the associated bindings for the specified 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.
 ScriptEngineFactory getFactory()
          Returns a ScriptEngineFactory for the class to which this ScriptEngine belongs.
 void put(String key, Object value)
          Associates a key and a value in the ScriptEngine ENGINE_SCOPE bindings.
 void setBindings(Bindings bindings, int scope)
          Associates the specified bindings with the specified 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.
 

Field Detail

ARGV

static final String ARGV
Reserved key associated with an object array which is used to pass set of positional parameters to the ScriptEngines.

See Also:
Constant Field Values

FILENAME

static final String FILENAME
Reserved key associated with name of the file which contains the source of the script.

See Also:
Constant Field Values

ENGINE

static final String ENGINE
Reserved key associated with the name of the Java ScriptEngine

See Also:
Constant Field Values

ENGINE_VERSION

static final String ENGINE_VERSION
Reserved key associated with the version of the Java ScriptEngine

See Also:
Constant Field Values

LANGUAGE

static final String LANGUAGE
Reserved key associated with the name of the supported scripting language

See Also:
Constant Field Values

LANGUAGE_VERSION

static final String LANGUAGE_VERSION
Reserved key associated with the version of the supported scripting language

See Also:
Constant Field Values

NAME

static final String NAME
Reserved key associated with the named value which identifies the short name of the supported language

See Also:
Constant Field Values
Method Detail

createBindings

Bindings createBindings()
Retrieves an uninitialized Bindings which can be used as the scope of the ScriptEngine.

Returns:
a Bindings which can be used to replace the state of the ScriptEngine

eval

Object eval(Reader reader)
            throws ScriptException
Evaluates a script obtained using the specified reader as the script source. Returns null for scripts that don't return a value.

Parameters:
reader - the source of the script
Returns:
the value of the evaluated script
Throws:
ScriptException - if an error occurs
NullPointerException - if argument is null

eval

Object eval(Reader reader,
            Bindings bindings)
            throws ScriptException
Evaluates a script obtained using a reader as the script source and using the specified namespace as the ENGINE_SCOPE. Returns null for scripts that don't return a value.

Parameters:
reader - the script source used to obtained the script
bindings - the bindings to be used as ENGINE_SCOPE
Returns:
the value of the evaluated script
Throws:
ScriptException - if an error occurs
NullPointerException - if either argument is null

eval

Object eval(Reader reader,
            ScriptContext context)
            throws ScriptException
Evaluates a script obtained using the specified reader as the script source and using the bindings in the specifed ScriptContext. Returns null for scripts that don't return a value.

Parameters:
reader - the script source
context - the context contianing different bindings for script evaluation
Returns:
the value of the evaluated script
Throws:
ScriptException - if an error occurs
NullPointerException - if either argument is null

eval

Object eval(String script)
            throws ScriptException
Evaluates a script contained in a String and returns the resultant object. Returns null for scripts that don't return a value.

Parameters:
script - the String representation of the script
Returns:
the value of the evaluated script
Throws:
ScriptException - if an error occurs
NullPointerException - if argument is null

eval

Object eval(String script,
            Bindings bindings)
            throws ScriptException
Evaluates a piece of script using the specified namespace as the ENGINE_SCOPE. Returns null for scripts that don't return a value.

Parameters:
script - the String representation of the script
bindings - the bindings to be used as the ENGINE_SCOPE
Returns:
the value of the evaluated script
Throws:
ScriptException - if an error occurs
NullPointerException - if either argument is null

eval

Object eval(String script,
            ScriptContext context)
            throws ScriptException
Evaluates a script using the bindings in the specifed ScriptContext. Returns null for scripts that don't return a value.

Parameters:
script - the String representation of the script
context - tbe ScriptContext containing bindings for the script evaluation
Returns:
the value of the evaluated script
Throws:
ScriptException - if an error occurs
NullPointerException - if either argument is null

get

Object get(String key)
Retrieves the value which is associated with the specified key in the state of the ScriptEngine.

Parameters:
key - the key associated with value.
Returns:
an object value which is associated with the key
Throws:
IllegalArgumentException - if argument is empty
NullPointerException - if argument is null

getFactory

ScriptEngineFactory getFactory()
Returns a ScriptEngineFactory for the class to which this ScriptEngine belongs.

Returns:
The ScriptEngineFactory

getBindings

Bindings getBindings(int scope)
Retrieves a reference to the associated bindings for the specified scope. Possible scopes are: GLOBAL_SCOPE : if the ScriptEngine was created by ScriptingEngineManager then GLOBAL_SCOPE of it is returned (or null if there is no GLOBAL_SCOPE stored in the ScriptEngine). ENGINE_SCOPE : the set of key-value pairs stored in the ScriptEngine is returned.

Parameters:
scope - the specified scope
Returns:
associated bindings for the specified scope
Throws:
IllegalArgumentException - if the scope is invalid

put

void put(String key,
         Object value)
Associates a key and a value in the ScriptEngine ENGINE_SCOPE bindings.

Parameters:
key - the specified key associated with the value
value - value which is to be associated with the specified key
Throws:
IllegalArgumentException - if the key is empty
NullPointerException - if key is null

setBindings

void setBindings(Bindings bindings,
                 int scope)
Associates the specified bindings with the specified scope.

Parameters:
bindings - bindings to be associated with the specified scope
scope - scope which the bindings should be associated with
Throws:
IllegalArgumentException - if the scope is invalid
NullPointerException - if the bindings is null and the scope is ScriptContext.ENGINE_SCOPE

getContext

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

Returns:
The default ScriptContext of the ScriptEngine

setContext

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.

Parameters:
context - scriptContext that will replace the default ScriptContext in the ScriptEngine.
Throws:
NullPointerException - if the context is null


Copyright © 1999-2012 The Apache Software Foundation. All Rights Reserved.