org.rhq.scripting
Interface ScriptEngineInitializer


public interface ScriptEngineInitializer

Is able to instantiate a script engine and import packages into the context of the engine.

Author:
Lukas Krejci

Method Summary
 String extractUserFriendlyErrorMessage(ScriptException e)
          At least the Rhino script engine for java script generates exceptions whose error messages contain just "too much" information to be easily decipherable by the end users.
 Set<String> generateIndirectionMethods(String boundObjectName, Set<Method> overloadedMethods)
          This function returns a definition string in the script engine's language that provides an indirection to calling the method on the bound object.
 void installScriptSourceProvider(ScriptEngine scriptEngine, ScriptSourceProvider scriptSourceProvider)
          Installs given script source provider into the script engine.
 ScriptEngine instantiate(Set<String> packages, PermissionCollection permissions)
          Instantiates a new script engine, makes the provided java packages "imported" into the context (i.e.
 

Method Detail

instantiate

ScriptEngine instantiate(Set<String> packages,
                         PermissionCollection permissions)
                         throws ScriptException
Instantiates a new script engine, makes the provided java packages "imported" into the context (i.e. classes from those packages can be instantiated without providing the full class name) and makes the script engine use the scriptSourceProvider to locate scripts.

Parameters:
packages - the list of java packages to be imported in the context
scriptSourceProvider - the provider of the sources of scripts - can be null to use no script source provider and depend on the default module loading mechanisms of the script language
permissions - the security permissions the script engine should execute the script with, can be null in which case the script engine is unsecured
Returns:
a newly instantiated script engine configured as above
Throws:
ScriptException

installScriptSourceProvider

void installScriptSourceProvider(ScriptEngine scriptEngine,
                                 ScriptSourceProvider scriptSourceProvider)
Installs given script source provider into the script engine.

Parameters:
scriptEngine -
scriptSourceProvider -
Throws:
IllegalArgumentException - if the script engine is not supported by this initializer

generateIndirectionMethods

Set<String> generateIndirectionMethods(String boundObjectName,
                                       Set<Method> overloadedMethods)
This function returns a definition string in the script engine's language that provides an indirection to calling the method on the bound object. for example for parameters: The method would generate this javascript:
function bar(arg) { return foo.bar(arg); }

This method gets passed all the overloaded versions of a method on the object (i.e. all the methods with the same name) and is free to return any number of functions that will map all the possible overloaded versions.

This is because different scripting languages have different support for function overloading and different ways of handling varying number of arguments of a function.

Parameters:
boundObjectName -
overloadedMethods -
Returns:
a set of strings with top-level function definitions in the scripting language

extractUserFriendlyErrorMessage

String extractUserFriendlyErrorMessage(ScriptException e)
At least the Rhino script engine for java script generates exceptions whose error messages contain just "too much" information to be easily decipherable by the end users.

This method extracts messages from the exception such that they are presentable to the end user.

The returned string should only contain the error message. The filename, line and column information should be stripped from it if at all possible.

Parameters:
e -
Returns:


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.