Package helma.scripting.rhino

# Class RhinoEngine

java.lang.Object
helma.scripting.rhino.RhinoEngine

All Implemented Interfaces:
  `ScriptingEngine`

public class RhinoEngine extends 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

Modifier and Type
Method
Description
`void`
`abort()`
Let the evaluator know that the current evaluation has been aborted.
`Object`
`deserialize(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.
`Object`
`getGlobalProperty(String propname)`
Get a property from the global object.
`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.
`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(String protoName, String skinName)`
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 evaluator
`void`
`injectCodeResource(String typename, Resource resource)`
Add a code resource to a given prototype by immediately compiling and evaluating it.
`Object`
`invoke(Object thisObject, Object function, Object[] args, int argsWrapMode, boolean resolve)`
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 engine
`void`
`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.
`Skin`
`toSkin(Object skinobj, String protoName)`
Try to get a skin from the parameter object.
`String`
`toString(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 Details

### app

public Application app

## Constructor Details

### RhinoEngine

public RhinoEngine()
Zero argument constructor.

## Method Details

### 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 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:
  `IOException` - an I/O exception occurred

### setGlobals

public void setGlobals(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 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 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(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.

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(Object obj, 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

### getGlobalProperty

public Object getGlobalProperty(String propname)
Get a property from the global object.

Specified by:
  `getGlobalProperty` in interface `ScriptingEngine`
Parameters:
  `propname` - the property name
Returns:
  the property value if the property is defined, or null

### getProperty

public 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.

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

### isTypedObject

public boolean isTypedObject(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 String toString(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

### serialize

public void serialize(Object obj, OutputStream out) throws 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:
  `IOException`

### deserialize

public Object deserialize(InputStream in) throws IOException, 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:
  `IOException`
  `ClassNotFoundException`

### injectCodeResource

public void injectCodeResource(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(Object skinobj, String protoName) throws IOException
Try to get a skin from the parameter object.

Throws:
  `IOException`

### getSkin

public Skin getSkin(String protoName, String skinName) throws 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:
  `IOException`