helma.scripting.rhino
Class RhinoEngine

java.lang.Object
  extended by helma.scripting.rhino.RhinoEngine
All Implemented Interfaces:
ScriptingEngine

public class RhinoEngine
extends java.lang.Object
implements ScriptingEngine

This is the implementation of ScriptingEnvironment for the Mozilla Rhino EcmaScript interpreter.


Field Summary
 Application app
           
 
Fields inherited from interface helma.scripting.ScriptingEngine
ARGS_WRAP_DEFAULT, ARGS_WRAP_NONE, ARGS_WRAP_XMLRPC
 
Constructor Summary
RhinoEngine()
          Zero argument constructor.
 
Method Summary
 void abort()
          Let the evaluator know that the current evaluation has been aborted.
 java.lang.Object deserialize(java.io.InputStream in)
          Provide object deserialization for this engine's scripted objects.
 void enterContext()
          This method is called before an execution context is entered to let the engine know it should update its prototype information.
 void exitContext()
          This method is called to let the scripting engine know that the current execution context has terminated.
 Application getApplication()
          Return the application we're running in
 RhinoCore getCore()
          Return the RhinoCore object for the application this engine belongs to.
 DocApplication getDoc()
          Get an introspector to this engine.
 java.lang.Object getProperty(java.lang.Object obj, java.lang.String propname)
          Check if an object has a defined property (public field if it is a java object) with that name.
 RequestTrans getRequest()
          Return the Request object of the current evaluation context.
 RequestEvaluator getRequestEvaluator()
          Return the RequestEvaluator owningthis rhino engine.
 ResponseTrans getResponse()
          Return the Response object of the current evaluation context.
static RhinoEngine getRhinoEngine()
          Return the RhinoEngine associated with the current thread, or null.
 Skin getSkin(java.lang.String protoName, java.lang.String skinName)
          Get a skin for the given prototype and skin name.
 boolean hasFunction(java.lang.Object obj, java.lang.String fname, boolean resolve)
          Check if an object has a function property (public method if it is a java object) with that name.
 boolean hasProperty(java.lang.Object obj, java.lang.String propname)
          Check if an object has a value property defined with that name.
 void init(Application app, RequestEvaluator reval)
          Init the scripting engine with an application and a request evaluator
 void injectCodeResource(java.lang.String typename, Resource resource)
          Add a code resource to a given prototype by immediately compiling and evaluating it.
 java.lang.Object invoke(java.lang.Object thisObject, java.lang.Object function, java.lang.Object[] args, int argsWrapMode, boolean resolve)
          Invoke a function on some object, using the given arguments and global vars.
 boolean isTypedObject(java.lang.Object obj)
          Determine if the given object is mapped to a type of the scripting engine
 void serialize(java.lang.Object obj, java.io.OutputStream out)
          Provide object serialization for this engine's scripted objects.
 void setGlobals(java.util.Map globals)
          This method is called when an execution context for a request evaluation is entered.
 void shutdown()
          Shut down the scripting engine.
 Skin toSkin(java.lang.Object skinobj, java.lang.String protoName)
          Try to get a skin from the parameter object.
 java.lang.String toString(java.lang.Object obj)
          Return a string representation for the given object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

app

public Application app
Constructor Detail

RhinoEngine

public RhinoEngine()
Zero argument constructor.

Method Detail

init

public void init(Application app,
                 RequestEvaluator reval)
Init the scripting engine with an application and a request evaluator

Specified by:
init in interface ScriptingEngine
Parameters:
app - the application
reval - the request evaluator

shutdown

public void shutdown()
Shut down the scripting engine.

Specified by:
shutdown in interface ScriptingEngine

getRhinoEngine

public static RhinoEngine getRhinoEngine()
Return the RhinoEngine associated with the current thread, or null.

Returns:
the RhinoEngine assocated with the current thread

enterContext

public void enterContext()
                  throws java.io.IOException
This method is called before an execution context is entered to let the engine know it should update its prototype information.

Specified by:
enterContext in interface ScriptingEngine
Throws:
java.io.IOException - an I/O exception occurred

setGlobals

public void setGlobals(java.util.Map globals)
                throws ScriptingException
This method is called when an execution context for a request evaluation is entered. The globals parameter contains the global values to be applied during this execution context.

Specified by:
setGlobals in interface ScriptingEngine
Parameters:
globals - map of global variables
Throws:
ScriptingException - a script related exception occurred

exitContext

public void exitContext()
This method is called to let the scripting engine know that the current execution context has terminated.

Specified by:
exitContext in interface ScriptingEngine

invoke

public java.lang.Object invoke(java.lang.Object thisObject,
                               java.lang.Object function,
                               java.lang.Object[] args,
                               int argsWrapMode,
                               boolean resolve)
                        throws ScriptingException
Invoke a function on some object, using the given arguments and global vars. XML-RPC calls require special input and output parameter conversion.

Specified by:
invoke in interface ScriptingEngine
Parameters:
thisObject - the object to invoke the function on, or null for global functions
function - the function or name of the function to be invoked
args - array of argument objects
argsWrapMode - indicated the way to process the arguments. Must be one of ARGS_WRAP_NONE, ARGS_WRAP_DEFAULT, ARGS_WRAP_XMLRPC
resolve - indicates whether functionName may contain an object path or just the plain function name
Returns:
the return value of the function
Throws:
ScriptingException - to indicate something went wrong with the invocation

abort

public void abort()
Let the evaluator know that the current evaluation has been aborted.

Specified by:
abort in interface ScriptingEngine

hasFunction

public boolean hasFunction(java.lang.Object obj,
                           java.lang.String fname,
                           boolean resolve)
Check if an object has a function property (public method if it is a java object) with that name.

Specified by:
hasFunction in interface ScriptingEngine
Parameters:
obj - the object
fname - the function name
resolve - if member path in function name should be resolved
Returns:
true if the function is defined on the object

hasProperty

public boolean hasProperty(java.lang.Object obj,
                           java.lang.String propname)
Check if an object has a value property defined with that name.

Specified by:
hasProperty in interface ScriptingEngine
Parameters:
obj - the object
propname - the property name
Returns:
true if the function is defined on the object

getProperty

public java.lang.Object getProperty(java.lang.Object obj,
                                    java.lang.String propname)
Check if an object has a defined property (public field if it is a java object) with that name.

Specified by:
getProperty in interface ScriptingEngine
Parameters:
obj - the object
propname - the property name
Returns:
true the property value, or null

isTypedObject

public boolean isTypedObject(java.lang.Object obj)
Determine if the given object is mapped to a type of the scripting engine

Specified by:
isTypedObject in interface ScriptingEngine
Parameters:
obj - an object
Returns:
true if the object is mapped to a type

toString

public java.lang.String toString(java.lang.Object obj)
Return a string representation for the given object

Specified by:
toString in interface ScriptingEngine
Parameters:
obj - an object
Returns:
a string representing the object

getDoc

public DocApplication getDoc()
Get an introspector to this engine.

Specified by:
getDoc in interface ScriptingEngine

serialize

public void serialize(java.lang.Object obj,
                      java.io.OutputStream out)
               throws java.io.IOException
Provide object serialization for this engine's scripted objects. If no special provisions are required, this method should just wrap the stream with an ObjectOutputStream and write the object.

Specified by:
serialize in interface ScriptingEngine
Parameters:
obj - the object to serialize
out - the stream to write to
Throws:
java.io.IOException

deserialize

public java.lang.Object deserialize(java.io.InputStream in)
                             throws java.io.IOException,
                                    java.lang.ClassNotFoundException
Provide object deserialization for this engine's scripted objects. If no special provisions are required, this method should just wrap the stream with an ObjectIntputStream and read the object.

Specified by:
deserialize in interface ScriptingEngine
Parameters:
in - the stream to read from
Returns:
the deserialized object
Throws:
java.io.IOException
java.lang.ClassNotFoundException

injectCodeResource

public void injectCodeResource(java.lang.String typename,
                               Resource resource)
Add a code resource to a given prototype by immediately compiling and evaluating it.

Specified by:
injectCodeResource in interface ScriptingEngine
Parameters:
typename - the type this resource belongs to
resource - a code resource

getApplication

public Application getApplication()
Return the application we're running in


getRequestEvaluator

public RequestEvaluator getRequestEvaluator()
Return the RequestEvaluator owningthis rhino engine.


getResponse

public ResponseTrans getResponse()
Return the Response object of the current evaluation context. Proxy method to RequestEvaluator.


getRequest

public RequestTrans getRequest()
Return the Request object of the current evaluation context. Proxy method to RequestEvaluator.


getCore

public RhinoCore getCore()
Return the RhinoCore object for the application this engine belongs to.

Returns:
this engine's RhinoCore instance

toSkin

public Skin toSkin(java.lang.Object skinobj,
                   java.lang.String protoName)
            throws java.io.IOException
Try to get a skin from the parameter object.

Throws:
java.io.IOException

getSkin

public Skin getSkin(java.lang.String protoName,
                    java.lang.String skinName)
             throws java.io.IOException
Get a skin for the given prototype and skin name. This method considers the skinpath set in the current response object and does per-response skin caching.

Throws:
java.io.IOException


Copyright © 1998-1998-${year} Helma.org. All Rights Reserved.