org.rhq.bindings
Class ScriptEngineFactory

java.lang.Object
  extended by org.rhq.bindings.ScriptEngineFactory

public class ScriptEngineFactory
extends Object

This is RHQ specific imitation of ScriptEngineFactory. In RHQ, we provide a standard set of bound variables in the script context and also import classes from our standard packages to ease the development of the scripts.

This factory is able to instantiate a script engine and initialize it consistently so that all users of the script engine get the uniform environment to write the scripts in.

Author:
Lukas Krejci

Method Summary
static void bindIndirectionMethods(ScriptEngine scriptEngine, String bindingName)
          Goes through the methods of the object found in the scriptEngine's ENGINE_SCOPE and for each of them generates a top-level function that is called the same name and accepts the same parameters.
static ScriptEngineInitializer getInitializer(String language)
           
static ScriptEngine getScriptEngine(String language, PackageFinder packageFinder, StandardBindings bindings)
          Initializes the script engine for given language.
static ScriptEngine getSecuredScriptEngine(String language, PackageFinder packageFinder, StandardBindings bindings, PermissionCollection permissions)
          This method is similar to the getScriptEngine(String, PackageFinder, StandardBindings) method but additionally applies a security wrapper on the returned script engine so that the scripts execute with the provided java permissions.
static void injectStandardBindings(ScriptEngine engine, StandardBindings bindings, boolean deleteExistingBindings)
          Injects the values provided in the bindings into the engine scope of the provided script engine.
static void removeBindings(ScriptEngine engine, Set<String> keySet)
          Remove the specified bindings from the engine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getScriptEngine

public static ScriptEngine getScriptEngine(String language,
                                           PackageFinder packageFinder,
                                           StandardBindings bindings)
                                    throws ScriptException,
                                           IOException
Initializes the script engine for given language.

Parameters:
language - the language of the script to instantiate
packageFinder - the package finder to find the standard packages in user provided locations
bindings - the initial standard bindings or null if none required
Returns:
the initialized engine or null if the engine for given language isn't known.
Throws:
ScriptException - on error during initialization of the script environment
IOException - if the package finder fails to find the packages

getSecuredScriptEngine

public static ScriptEngine getSecuredScriptEngine(String language,
                                                  PackageFinder packageFinder,
                                                  StandardBindings bindings,
                                                  PermissionCollection permissions)
                                           throws ScriptException,
                                                  IOException
This method is similar to the getScriptEngine(String, PackageFinder, StandardBindings) method but additionally applies a security wrapper on the returned script engine so that the scripts execute with the provided java permissions.

Throws:
ScriptException
IOException
See Also:
getScriptEngine(String, PackageFinder, StandardBindings)

injectStandardBindings

public static void injectStandardBindings(ScriptEngine engine,
                                          StandardBindings bindings,
                                          boolean deleteExistingBindings)
Injects the values provided in the bindings into the engine scope of the provided script engine.

Parameters:
engine - the engine
bindings - the bindings
deleteExistingBindings - true if the existing bindings should be replaced by the provided ones, false if the provided bindings should be added to the existing ones (possibly overwriting bindings with the same name).

removeBindings

public static void removeBindings(ScriptEngine engine,
                                  Set<String> keySet)
Remove the specified bindings from the engine.

Parameters:
engine - the engine
keySet - the binding keys to be removed

bindIndirectionMethods

public static void bindIndirectionMethods(ScriptEngine scriptEngine,
                                          String bindingName)
Goes through the methods of the object found in the scriptEngine's ENGINE_SCOPE and for each of them generates a top-level function that is called the same name and accepts the same parameters.

Parameters:
scriptEngine - the script engine to generate the top-level functions in
bindingName - the name of the object in the script engine to generate the functions from
See Also:
ScriptEngineInitializer#generateIndirectionMethod(String, Method), NoTopLevelIndirection

getInitializer

public static ScriptEngineInitializer getInitializer(String language)


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