bsh
Class BshScriptEngine

java.lang.Object
  extended by javax.script.AbstractScriptEngine
      extended by bsh.BshScriptEngine
All Implemented Interfaces:
javax.script.Compilable, javax.script.Invocable, javax.script.ScriptEngine

public class BshScriptEngine
extends javax.script.AbstractScriptEngine
implements javax.script.Compilable, javax.script.Invocable


Field Summary
 
Fields inherited from class javax.script.AbstractScriptEngine
context
 
Fields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
 
Constructor Summary
BshScriptEngine()
           
BshScriptEngine(BshScriptEngineFactory factory)
           
 
Method Summary
 javax.script.CompiledScript compile(java.io.Reader script)
          Compiles the script (source read from Reader) for later execution.
 javax.script.CompiledScript compile(java.lang.String script)
          Compiles the script (source represented as a String) for later execution.
 javax.script.Bindings createBindings()
           
 java.lang.Object eval(java.io.Reader reader, javax.script.ScriptContext scriptContext)
           
 java.lang.Object eval(java.lang.String script, javax.script.ScriptContext scriptContext)
           
 javax.script.ScriptEngineFactory getFactory()
           
<T> T
getInterface(java.lang.Class<T> clasz)
          Returns an implementation of an interface using procedures compiled in the interpreter.
<T> T
getInterface(java.lang.Object thiz, java.lang.Class<T> clasz)
          Returns an implementation of an interface using member functions of a scripting object compiled in the interpreter.
protected  Interpreter getInterpreter()
           
 java.lang.Object invokeFunction(java.lang.String name, java.lang.Object... args)
          Same as invoke(Object, String, Object...) with null as the first argument.
 java.lang.Object invokeMethod(java.lang.Object thiz, java.lang.String name, java.lang.Object... args)
          Calls a procedure compiled during a previous script execution, which is retained in the state of the {@code ScriptEngine{@code .
 
Methods inherited from class javax.script.AbstractScriptEngine
eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BshScriptEngine

public BshScriptEngine()

BshScriptEngine

public BshScriptEngine(BshScriptEngineFactory factory)
Method Detail

getInterpreter

protected Interpreter getInterpreter()

eval

public java.lang.Object eval(java.lang.String script,
                             javax.script.ScriptContext scriptContext)
                      throws javax.script.ScriptException
Specified by:
eval in interface javax.script.ScriptEngine
Throws:
javax.script.ScriptException

eval

public java.lang.Object eval(java.io.Reader reader,
                             javax.script.ScriptContext scriptContext)
                      throws javax.script.ScriptException
Specified by:
eval in interface javax.script.ScriptEngine
Throws:
javax.script.ScriptException

createBindings

public javax.script.Bindings createBindings()
Specified by:
createBindings in interface javax.script.ScriptEngine

getFactory

public javax.script.ScriptEngineFactory getFactory()
Specified by:
getFactory in interface javax.script.ScriptEngine

compile

public javax.script.CompiledScript compile(java.lang.String script)
                                    throws javax.script.ScriptException
Compiles the script (source represented as a String) for later execution.

Specified by:
compile in interface javax.script.Compilable
Parameters:
script - The source of the script, represented as a String.
Returns:
An subclass of CompiledScript to be executed later using one of the eval methods of CompiledScript.
Throws:
javax.script.ScriptException - if compilation fails.
java.lang.NullPointerException - if the argument is null.

compile

public javax.script.CompiledScript compile(java.io.Reader script)
                                    throws javax.script.ScriptException
Compiles the script (source read from Reader) for later execution. Functionality is identical to compile(String) other than the way in which the source is passed.

Specified by:
compile in interface javax.script.Compilable
Parameters:
script - The reader from which the script source is obtained.
Returns:
An implementation of CompiledScript to be executed later using one of its eval methods of CompiledScript.
Throws:
javax.script.ScriptException - if compilation fails.
java.lang.NullPointerException - if argument is null.

invokeMethod

public java.lang.Object invokeMethod(java.lang.Object thiz,
                                     java.lang.String name,
                                     java.lang.Object... args)
                              throws javax.script.ScriptException,
                                     java.lang.NoSuchMethodException
Calls a procedure compiled during a previous script execution, which is retained in the state of the {@code ScriptEngine{@code .

Specified by:
invokeMethod in interface javax.script.Invocable
Parameters:
name - The name of the procedure to be called.
thiz - If the procedure is a member of a class defined in the script and thiz is an instance of that class returned by a previous execution or invocation, the named method is called through that instance. If classes are not supported in the scripting language or if the procedure is not a member function of any class, the argument must be null.
args - Arguments to pass to the procedure. The rules for converting the arguments to scripting variables are implementation-specific.
Returns:
The value returned by the procedure. The rules for converting the scripting variable returned by the procedure to a Java Object are implementation-specific.
Throws:
javax.script.ScriptException - if an error occurrs during invocation of the method.
java.lang.NoSuchMethodException - if method with given name or matching argument types cannot be found.
java.lang.NullPointerException - if method name is null.

invokeFunction

public java.lang.Object invokeFunction(java.lang.String name,
                                       java.lang.Object... args)
                                throws javax.script.ScriptException,
                                       java.lang.NoSuchMethodException
Same as invoke(Object, String, Object...) with null as the first argument. Used to call top-level procedures defined in scripts.

Specified by:
invokeFunction in interface javax.script.Invocable
Parameters:
args - Arguments to pass to the procedure
Returns:
The value returned by the procedure
Throws:
javax.script.ScriptException - if an error occurrs during invocation of the method.
java.lang.NoSuchMethodException - if method with given name or matching argument types cannot be found.
java.lang.NullPointerException - if method name is null.

getInterface

public <T> T getInterface(java.lang.Class<T> clasz)
Returns an implementation of an interface using procedures compiled in the interpreter. The methods of the interface may be implemented using the invoke method.

Specified by:
getInterface in interface javax.script.Invocable
Parameters:
clasz - The Class object of the interface to return.
Returns:
An instance of requested interface - null if the requested interface is unavailable, i. e. if compiled methods in the ScriptEngine cannot be found matching the ones in the requested interface.
Throws:
java.lang.IllegalArgumentException - if the specified Class object does not exist or is not an interface.

getInterface

public <T> T getInterface(java.lang.Object thiz,
                          java.lang.Class<T> clasz)
Returns an implementation of an interface using member functions of a scripting object compiled in the interpreter. The methods of the interface may be implemented using invoke(Object, String, Object...) method.

Specified by:
getInterface in interface javax.script.Invocable
Parameters:
thiz - The scripting object whose member functions are used to implement the methods of the interface.
clasz - The Class object of the interface to return.
Returns:
An instance of requested interface - null if the requested interface is unavailable, i. e. if compiled methods in the ScriptEngine cannot be found matching the ones in the requested interface.
Throws:
java.lang.IllegalArgumentException - if the specified Class object does not exist or is not an interface, or if the specified Object is null or does not represent a scripting object.


? 2000-2005 pat@pat.net :-)