public class ScriptEngineFactory extends Object
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.
| Modifier and Type | Method and Description |
|---|---|
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 CodeCompletion |
getCodeCompletion(String language) |
static String |
getFileExtensionForLanguage(String language) |
static ScriptEngineInitializer |
getInitializer(String language) |
static String |
getLanguageByScriptFileExtension(String fileExtension) |
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, ScriptSourceProvider...) method
but additionally applies a security wrapper on the returned script engine so that the scripts execute
with the provided java permissions. |
static Set<String> |
getSupportedLanguages() |
static void |
injectStandardBindings(ScriptEngine engine,
StandardBindings bindings,
boolean deleteExistingBindings,
ScriptSourceProvider... scriptSourceProviders)
Injects the values provided in the bindings into the
engine scope
of the provided script engine. |
static void |
reloadScriptEngineProviders(ClassLoader classLoader)
Reloads the list of the known script engine providers using the given classloader
or the current thread's context classloader if it is null.
|
static void |
removeBindings(ScriptEngine engine,
Set<RhqManager> keySet)
Remove the specified bindings from the engine.
|
public static void reloadScriptEngineProviders(ClassLoader classLoader)
classLoader - the classloader used to find the script engine providers on the classpathIllegalStateException - if more than 1 script engine provider is found for a single languagepublic static Set<String> getSupportedLanguages()
public static String getLanguageByScriptFileExtension(String fileExtension)
public static ScriptEngine getScriptEngine(String language, PackageFinder packageFinder, StandardBindings bindings) throws ScriptException, IOException
language - the language of the script to instantiatepackageFinder - the package finder to find the standard packages in user provided locationsbindings - the initial standard bindings or null if none requiredScriptEngineProvider for given language isn't known.ScriptException - on error during initialization of the script environmentIOException - if the package finder fails to find the packagespublic static ScriptEngine getSecuredScriptEngine(String language, PackageFinder packageFinder, StandardBindings bindings, PermissionCollection permissions) throws ScriptException, IOException
#getScriptEngine(String, PackageFinder, StandardBindings, ScriptSourceProvider...) method
but additionally applies a security wrapper on the returned script engine so that the scripts execute
with the provided java permissions.ScriptExceptionIOException#getScriptEngine(String, PackageFinder, StandardBindings, ScriptSourceProvider...)public static void injectStandardBindings(ScriptEngine engine, StandardBindings bindings, boolean deleteExistingBindings, ScriptSourceProvider... scriptSourceProviders)
engine scope
of the provided script engine.engine - the enginebindings - the bindingsdeleteExistingBindings - 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).scriptSourceProviders - the list of script source providers to be used by the script engine to locate the scripts.
Note that the providers become associated with the script engine and its bindings and therefore should
not be used with any other script engine. If the providers implement the
StandardBindings.RhqFacadeChangeListener interface, they will be automatically hooked up with the
bindings so that the providers will get notified whenever the rhq facade changes.public static void removeBindings(ScriptEngine engine, Set<RhqManager> keySet)
engine - the enginekeySet - the binding keys to be removedpublic static void bindIndirectionMethods(ScriptEngine scriptEngine, String bindingName)
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.scriptEngine - the script engine to generate the top-level functions inbindingName - the name of the object in the script engine to generate the functions fromScriptEngineInitializer#generateIndirectionMethod(String, Method),
NoTopLevelIndirectionpublic static ScriptEngineInitializer getInitializer(String language)
public static CodeCompletion getCodeCompletion(String language)
Copyright © 2008-2014 Red Hat, Inc.. All Rights Reserved.