TeaEngine 0.7.0 Java Script API

com.pdmfc.tea.engine
Class TeaScriptEngine

java.lang.Object
  extended by javax.script.AbstractScriptEngine
      extended by com.pdmfc.tea.engine.TeaScriptEngine
All Implemented Interfaces:
javax.script.Compilable, javax.script.Invocable, javax.script.ScriptEngine

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

Most of the functionality is implemented, except for 2 Invocable methods.


Field Summary
protected  com.pdmfc.tea.compiler.SCompiler _compiler
          A single com.pdmfc.tea.compiler.SCompiler is used to compile Tea code into an internal representation com.pdmfc.tea.runtime.SCode.
protected  TeaScriptEngineFactory _factory
          Reference the factory that instantiated this object.
 
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
TeaScriptEngine()
          Initialize _fatcory to null.
TeaScriptEngine(TeaScriptEngineFactory aFactory)
          Initialize _factory and super-class with AbstractScriptEngine(new TeaBindings()) so that the context now has an uninitialized TeaBindings.
 
Method Summary
 javax.script.CompiledScript compile(java.io.Reader reader)
           
 javax.script.CompiledScript compile(java.lang.String script)
           
 javax.script.CompiledScript compileBytes(byte[] script)
           
 javax.script.Bindings createBindings()
           
 void end()
          com.pdmfc.tea.runtime.STeaRuntime should have the end() method called before unloading, so that any Tea code callbacks may be called to free allocated resources.
 java.lang.Object eval(java.io.Reader reader, javax.script.ScriptContext scriptContext)
          Reads the file to memory, and converts it to byte[] for evaluation.
 java.lang.Object eval(java.lang.String script, javax.script.ScriptContext scriptContext)
          Converts the String to byte[] for evaluation.
 java.lang.Object evalBytes(byte[] script, javax.script.ScriptContext scriptContext)
          Compiles byte[] as a Tea script and executes it.
 com.pdmfc.tea.compiler.SCompiler getCompiler()
           
 javax.script.ScriptEngineFactory getFactory()
           
<T> T
getInterface(java.lang.Class<T> clasz)
          Unsupported yet.
<T> T
getInterface(java.lang.Object thisz, java.lang.Class<T> clasz)
          Unsupported yet.
 com.pdmfc.tea.runtime.STeaRuntime getMyRuntime()
          Get (and initialize if necessary) a com.pdmfc.tea.runtime.STeaRuntime from the current engine context.
static com.pdmfc.tea.runtime.STeaRuntime getRuntime(javax.script.ScriptContext sc)
          Get (and initialize if necessary) a com.pdmfc.tea.runtime.STeaRuntime from the given engine context.
 java.lang.Object invokeFunction(java.lang.String name, java.lang.Object... args)
           
 java.lang.Object invokeMethod(java.lang.Object thisz, java.lang.String name, java.lang.Object... args)
           
 
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
 

Field Detail

_compiler

protected com.pdmfc.tea.compiler.SCompiler _compiler
A single com.pdmfc.tea.compiler.SCompiler is used to compile Tea code into an internal representation com.pdmfc.tea.runtime.SCode.


_factory

protected TeaScriptEngineFactory _factory
Reference the factory that instantiated this object.

Constructor Detail

TeaScriptEngine

public TeaScriptEngine()
Initialize _fatcory to null. As we are not allowed to throw a ScriptException, real initialization is delayed until you try to evaluate some Tea code.

See Also:
TeaCompiledScript.eval(ScriptContext scriptContext)

TeaScriptEngine

public TeaScriptEngine(TeaScriptEngineFactory aFactory)
Initialize _factory and super-class with AbstractScriptEngine(new TeaBindings()) so that the context now has an uninitialized TeaBindings. As we are not allowed to throw a ScriptException, real initialization is delayed until you try to evaluate some Tea code.

See Also:
TeaCompiledScript.eval(ScriptContext scriptContext)
Method Detail

createBindings

public javax.script.Bindings createBindings()
Specified by:
createBindings in interface javax.script.ScriptEngine
Returns:
a new TeaBindings.

getCompiler

public com.pdmfc.tea.compiler.SCompiler getCompiler()
Returns:
a com.pdmfc.tea.compiler.SCompiler. There is only one per engine.

eval

public java.lang.Object eval(java.lang.String script,
                             javax.script.ScriptContext scriptContext)
                      throws javax.script.ScriptException
Converts the String to byte[] for evaluation.

Specified by:
eval in interface javax.script.ScriptEngine
Throws:
javax.script.ScriptException
See Also:
evalBytes(byte[] script, ScriptContext scriptContext).

eval

public java.lang.Object eval(java.io.Reader reader,
                             javax.script.ScriptContext scriptContext)
                      throws javax.script.ScriptException
Reads the file to memory, and converts it to byte[] for evaluation.

Specified by:
eval in interface javax.script.ScriptEngine
Throws:
javax.script.ScriptException
See Also:
evalBytes(byte[] script, ScriptContext scriptContext).

evalBytes

public java.lang.Object evalBytes(byte[] script,
                                  javax.script.ScriptContext scriptContext)
                           throws javax.script.ScriptException
Compiles byte[] as a Tea script and executes it.

Throws:
javax.script.ScriptException

getFactory

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

compile

public javax.script.CompiledScript compile(java.io.Reader reader)
                                    throws javax.script.ScriptException
Specified by:
compile in interface javax.script.Compilable
Throws:
javax.script.ScriptException

compile

public javax.script.CompiledScript compile(java.lang.String script)
                                    throws javax.script.ScriptException
Specified by:
compile in interface javax.script.Compilable
Throws:
javax.script.ScriptException

compileBytes

public javax.script.CompiledScript compileBytes(byte[] script)
                                         throws javax.script.ScriptException
Throws:
javax.script.ScriptException

invokeFunction

public java.lang.Object invokeFunction(java.lang.String name,
                                       java.lang.Object... args)
                                throws javax.script.ScriptException
Specified by:
invokeFunction in interface javax.script.Invocable
Throws:
javax.script.ScriptException

invokeMethod

public java.lang.Object invokeMethod(java.lang.Object thisz,
                                     java.lang.String name,
                                     java.lang.Object... args)
                              throws javax.script.ScriptException
Specified by:
invokeMethod in interface javax.script.Invocable
Throws:
javax.script.ScriptException

getInterface

public <T> T getInterface(java.lang.Class<T> clasz)
Unsupported yet.

Specified by:
getInterface in interface javax.script.Invocable
Throws:
java.lang.UnsupportedOperationException

getInterface

public <T> T getInterface(java.lang.Object thisz,
                          java.lang.Class<T> clasz)
Unsupported yet.

Specified by:
getInterface in interface javax.script.Invocable
Throws:
java.lang.UnsupportedOperationException

end

public void end()
         throws javax.script.ScriptException
com.pdmfc.tea.runtime.STeaRuntime should have the end() method called before unloading, so that any Tea code callbacks may be called to free allocated resources. As JSR-223 does not support this feature, this method is left as an extension for the programmer to call it explicitely. (If the Tea code does not defines any callbacks to release resources, no real harm is done by not calling this method.)

Throws:
javax.script.ScriptException

getMyRuntime

public com.pdmfc.tea.runtime.STeaRuntime getMyRuntime()
                                               throws javax.script.ScriptException
Get (and initialize if necessary) a com.pdmfc.tea.runtime.STeaRuntime from the current engine context.

Throws:
javax.script.ScriptException
See Also:
getRuntime(ScriptContext sc)

getRuntime

public static com.pdmfc.tea.runtime.STeaRuntime getRuntime(javax.script.ScriptContext sc)
                                                    throws javax.script.ScriptException
Get (and initialize if necessary) a com.pdmfc.tea.runtime.STeaRuntime from the given engine context.

Throws:
javax.script.ScriptException - as Tea initialization code might be called to initialize the runtime.
See Also:
TeaBindings.getMyRuntime()

TeaEngine 0.7.0 Java Script API

© 2007 PDM&FC, All Rights Reserved.