Package helma.scripting.rhino
Class RhinoEngine
java.lang.Object
helma.scripting.rhino.RhinoEngine
- All Implemented Interfaces:
ScriptingEngine
This is the implementation of ScriptingEnvironment for the Mozilla Rhino EcmaScript interpreter.
-
Field Summary
FieldsFields inherited from interface helma.scripting.ScriptingEngine
ARGS_WRAP_DEFAULT, ARGS_WRAP_NONE, ARGS_WRAP_XMLRPC
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
Let the evaluator know that the current evaluation has been aborted.Provide object deserialization for this engine's scripted objects.void
This method is called before an execution context is entered to let the engine know it should update its prototype information.void
This method is called to let the scripting engine know that the current execution context has terminated.Return the application we're running ingetCore()
Return the RhinoCore object for the application this engine belongs to.getGlobalProperty
(String propname) Get a property from the global object.getProperty
(Object obj, String propname) Check if an object has a defined property (public field if it is a java object) with that name.Return the Request object of the current evaluation context.Return the RequestEvaluator owningthis rhino engine.Return the Response object of the current evaluation context.static RhinoEngine
Return the RhinoEngine associated with the current thread, or null.Get a skin for the given prototype and skin name.boolean
hasFunction
(Object obj, 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
(Object obj, 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
(String typename, Resource resource) Add a code resource to a given prototype by immediately compiling and evaluating it.Invoke a function on some object, using the given arguments and global vars.boolean
isTypedObject
(Object obj) Determine if the given object is mapped to a type of the scripting enginevoid
serialize
(Object obj, OutputStream out) Provide object serialization for this engine's scripted objects.void
setGlobals
(Map globals) This method is called when an execution context for a request evaluation is entered.void
shutdown()
Shut down the scripting engine.Try to get a skin from the parameter object.Return a string representation for the given object
-
Field Details
-
app
-
-
Constructor Details
-
RhinoEngine
public RhinoEngine()Zero argument constructor.
-
-
Method Details
-
init
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
Return the RhinoEngine associated with the current thread, or null.- Returns:
- the RhinoEngine assocated with the current thread
-
enterContext
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:
IOException
- an I/O exception occurred
-
setGlobals
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 Object invoke(Object thisObject, Object function, 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
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
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
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
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
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
Return a string representation for the given object- Specified by:
toString
in interfaceScriptingEngine
- Parameters:
obj
- an object- Returns:
- a string representing the object
-
serialize
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:
IOException
-
deserialize
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:
IOException
ClassNotFoundException
-
injectCodeResource
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
Return the application we're running in -
getRequestEvaluator
Return the RequestEvaluator owningthis rhino engine. -
getResponse
Return the Response object of the current evaluation context. Proxy method to RequestEvaluator. -
getRequest
Return the Request object of the current evaluation context. Proxy method to RequestEvaluator. -
getCore
Return the RhinoCore object for the application this engine belongs to.- Returns:
- this engine's RhinoCore instance
-
toSkin
Try to get a skin from the parameter object.- Throws:
IOException
-
getSkin
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:
IOException
-