Package helma.scripting

# Interface ScriptingEngine

All Known Implementing Classes:
  `RhinoEngine`

public interface ScriptingEngine
This is the interface that must be implemented to make a scripting environment usable by the Helma application server. Implementations of this interface must have a public zero-argument constructor to be usable by the Helma framework.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`ARGS_WRAP_DEFAULT`
Argument wrapping mode that indicates arguments may be arbitrary Java objects that may need to be wrapped.
`static final int`
`ARGS_WRAP_NONE`
Argument wrapping mode that indicates arguments are wrapped already and should be passed along unchanged.
`static final int`
`ARGS_WRAP_XMLRPC`
Argument wrapping mode that indicates this is an XML-RPC call and arguments should be processed accordingly.

## 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 when an execution context for a request evaluation 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.
`Object`
`getGlobalProperty(String propertyName)`
Get a global property
`Object`
`getProperty(Object thisObject, String propertyName)`
Get a property on an object
`boolean`
`hasFunction(Object thisObject, String functionName, boolean resolve)`
Return true if a function by that name is defined for that object.
`boolean`
`hasProperty(Object thisObject, String propertyName)`
Return true if a property by that name is defined for that object.
`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.
`String`
`toString(Object obj)`
Return a string representation for the given object

## Field Details

### ARGS_WRAP_NONE

static final int ARGS_WRAP_NONE
Argument wrapping mode that indicates arguments are wrapped already and should be passed along unchanged.

See Also:
  - Constant Field Values

### ARGS_WRAP_DEFAULT

static final int ARGS_WRAP_DEFAULT
Argument wrapping mode that indicates arguments may be arbitrary Java objects that may need to be wrapped.

See Also:
  - Constant Field Values

### ARGS_WRAP_XMLRPC

static final int ARGS_WRAP_XMLRPC
Argument wrapping mode that indicates this is an XML-RPC call and arguments should be processed accordingly.

See Also:
  - Constant Field Values

## Method Details

### init

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

Parameters:
  `app` - the application
  `reval` - the request evaluator

### shutdown

void shutdown()
Shut down the Scripting engine.

### enterContext

void enterContext() throws IOException, ScriptingException
This method is called when an execution context for a request evaluation is entered to let the Engine know it should update its prototype information

Throws:
  `IOException` - an I/O exception occurred
  `ScriptingException` - a script related exception occurred

### setGlobals

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.

Parameters:
  `globals` - map of global variables
Throws:
  `ScriptingException` - a script related exception occurred

### exitContext

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

### invoke

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.

Parameters:
  `thisObject` - the object to invoke the function on, or null for global functions
  `function` - the 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

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

### getGlobalProperty

Object getGlobalProperty(String propertyName)
Get a global property

Parameters:
  `propertyName` - the property name
Returns:
  the property value, or null

### getProperty

Object getProperty(Object thisObject, String propertyName)
Get a property on an object

Parameters:
  `thisObject` - the object
  `propertyName` - the property name
Returns:
  the property value, or null

### hasFunction

boolean hasFunction(Object thisObject, String functionName, boolean resolve)
Return true if a function by that name is defined for that object.

Parameters:
  `thisObject` - the object
  `functionName` - the function name
  `resolve` - if member path in function name should be resolved
Returns:
  true if the function is defined on the object

### hasProperty

boolean hasProperty(Object thisObject, String propertyName)
Return true if a property by that name is defined for that object.

Parameters:
  `thisObject` - the object
  `propertyName` - the property name
Returns:
  true if the function is defined on the object

### isTypedObject

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

Parameters:
  `obj` - an object
Returns:
  true if the object is mapped to a type

### toString

String toString(Object obj)
Return a string representation for the given object

Parameters:
  `obj` - an object
Returns:
  a string representing the object

### serialize

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.

Parameters:
  `obj` - the object to serialize
  `out` - the stream to write to
Throws:
  `IOException`

### deserialize

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.

Parameters:
  `in` - the stream to read from
Returns:
  the deserialized object
Throws:
  `IOException`
  `ClassNotFoundException`

### injectCodeResource

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

Parameters:
  `typename` - the type this resource belongs to
  `resource` - a code resource