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 int
ARGS_WRAP_DEFAULT
Argument wrapping mode that indicates arguments may be arbitrary Java objects that may need to be wrapped.static int
ARGS_WRAP_NONE
Argument wrapping mode that indicates arguments are wrapped already and should be passed along unchanged.static int
ARGS_WRAP_XMLRPC
Argument wrapping mode that indicates this is an XML-RPC call and arguments should be processed accordingly.
-
Method Summary
All Methods Instance Methods Abstract 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 when an execution context for a request evaluation is entered to let the Engine know it should update its prototype informationvoid
exitContext()
This method is called to let the scripting engine know that the current execution context has terminated.java.lang.Object
getGlobalProperty(java.lang.String propertyName)
Get a global propertyjava.lang.Object
getProperty(java.lang.Object thisObject, java.lang.String propertyName)
Get a property on an objectboolean
hasFunction(java.lang.Object thisObject, java.lang.String functionName, boolean resolve)
Return true if a function by that name is defined for that object.boolean
hasProperty(java.lang.Object thisObject, java.lang.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 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.java.lang.String
toString(java.lang.Object obj)
Return a string representation for the given object
-
-
-
Field Detail
-
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 Detail
-
init
void init(Application app, RequestEvaluator reval)
Init the scripting engine with an application and a request evaluator- Parameters:
app
- the applicationreval
- the request evaluator
-
shutdown
void shutdown()
Shut down the Scripting engine.
-
enterContext
void enterContext() throws java.io.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:
java.io.IOException
- an I/O exception occurredScriptingException
- a script related exception occurred
-
setGlobals
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.- 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
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.- Parameters:
thisObject
- the object to invoke the function on, or null for global functionsfunction
- the 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
void abort()
Let the evaluator know that the current evaluation has been aborted.
-
getGlobalProperty
java.lang.Object getGlobalProperty(java.lang.String propertyName)
Get a global property- Parameters:
propertyName
- the property name- Returns:
- the property value, or null
-
getProperty
java.lang.Object getProperty(java.lang.Object thisObject, java.lang.String propertyName)
Get a property on an object- Parameters:
thisObject
- the objectpropertyName
- the property name- Returns:
- the property value, or null
-
hasFunction
boolean hasFunction(java.lang.Object thisObject, java.lang.String functionName, boolean resolve)
Return true if a function by that name is defined for that object.- Parameters:
thisObject
- the objectfunctionName
- the function nameresolve
- if member path in function name should be resolved- Returns:
- true if the function is defined on the object
-
hasProperty
boolean hasProperty(java.lang.Object thisObject, java.lang.String propertyName)
Return true if a property by that name is defined for that object.- Parameters:
thisObject
- the objectpropertyName
- the property name- Returns:
- true if the function is defined on the object
-
isTypedObject
boolean isTypedObject(java.lang.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
java.lang.String toString(java.lang.Object obj)
Return a string representation for the given object- Parameters:
obj
- an object- Returns:
- a string representing the object
-
serialize
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.- Parameters:
obj
- the object to serializeout
- the stream to write to- Throws:
java.io.IOException
-
deserialize
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.- Parameters:
in
- the stream to read from- Returns:
- the deserialized object
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
injectCodeResource
void injectCodeResource(java.lang.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 toresource
- a code resource
-
-