Package helma.scripting.rhino
Class RhinoEngine
- java.lang.Object
-
- 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
Fields Modifier and Type Field Description Application
app
-
Fields inherited from interface helma.scripting.ScriptingEngine
ARGS_WRAP_DEFAULT, ARGS_WRAP_NONE, ARGS_WRAP_XMLRPC
-
-
Constructor Summary
Constructors Constructor Description RhinoEngine()
Zero argument constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 inRhinoCore
getCore()
Return the RhinoCore object for the application this engine belongs to.java.lang.Object
getGlobalProperty(java.lang.String propname)
Get a property from the global object.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 evaluatorvoid
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 enginevoid
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
-
-
-
Field Detail
-
app
public Application app
-
-
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 interfaceScriptingEngine
- Parameters:
app
- the applicationreval
- the request evaluator
-
shutdown
public void shutdown()
Shut down the scripting engine.- Specified by:
shutdown
in interfaceScriptingEngine
-
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 interfaceScriptingEngine
- 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 interfaceScriptingEngine
- 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 interfaceScriptingEngine
-
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 interfaceScriptingEngine
- Parameters:
thisObject
- the object to invoke the function on, or null for global functionsfunction
- the function or name of the function to be invokedargs
- array of argument objectsargsWrapMode
- indicated the way to process the arguments. Must be one ofARGS_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 interfaceScriptingEngine
-
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 interfaceScriptingEngine
- Parameters:
obj
- the objectfname
- the function nameresolve
- 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 interfaceScriptingEngine
- Parameters:
obj
- the objectpropname
- the property name- Returns:
- true if the function is defined on the object
-
getGlobalProperty
public java.lang.Object getGlobalProperty(java.lang.String propname)
Get a property from the global object.- Specified by:
getGlobalProperty
in interfaceScriptingEngine
- Parameters:
propname
- the property name- Returns:
- the property value if the property is defined, or null
-
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 interfaceScriptingEngine
- Parameters:
obj
- the objectpropname
- the property name- Returns:
- 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 interfaceScriptingEngine
- 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 interfaceScriptingEngine
- Parameters:
obj
- an object- Returns:
- a string representing the object
-
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 interfaceScriptingEngine
- Parameters:
obj
- the object to serializeout
- 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 interfaceScriptingEngine
- 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 interfaceScriptingEngine
- Parameters:
typename
- the type this resource belongs toresource
- 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
-
-