Interface ScriptFactory
- All Known Implementing Classes:
DefaultScriptFactory, JSR223ScriptFactory
- Author:
- harald
-
Method Summary
Modifier and TypeMethodDescriptioncreateScript(String abbreviation, String code, boolean cached, boolean threadSafe, Function<String, ScriptConverter> converterProvider) Creates a script object.Gets the default language.static ScriptFactoryThe singleton.getLanguage(String abbreviation) Gets the scripting language.Gets all scripting languages.booleanisLanguageAvailable(String abbreviation) Check if a scripting language is available.voidsetDefaultLanguage(String abbreviation) Sets the default language.voidsetDefaultLanguage(ScriptingLanguage language) Sets the default language.
-
Method Details
-
getInstance
-
setDefaultLanguage
Sets the default language.Throws ScriptRuntimeException if no such language.
- Parameters:
abbreviation- the abbreviation for the default language
-
setDefaultLanguage
Sets the default language.- Parameters:
language- the language
-
getDefaultLanguage
ScriptingLanguage getDefaultLanguage()Gets the default language.- Returns:
- the default language, null if none
-
getLanguage
Gets the scripting language.Throws ScriptRuntimeException if no such language.
- Parameters:
abbreviation- one of the abbreviations for that language, null or empty string if default language- Returns:
- the language, never null
-
isLanguageAvailable
Check if a scripting language is available.- Parameters:
abbreviation- one of the abbreviations for that language, null or empty string if default language- Returns:
- true if the scripting language is available
-
getLanguages
-
createScript
Script createScript(String abbreviation, String code, boolean cached, boolean threadSafe, Function<String, ScriptConverter> converterProvider) Creates a script object.Scripts will be cached to optimize memory consumption and performance, if
cached=true. The same source code will refer to the same compiled evaluation unit. The implementation may still return a newScriptinstance if caching not supported by the language or the caching refers to class instances instead of objects. Caching should not be used for scripts that are executed only once.If there are chances that scripts are invoked from different threads at a time, all scripts must be executed in a thread-safe manner. Although some languages are threadsafe by design, others may need some extra synchronization. If in doubt, set
threadSafetotrueAn optional function provides a
ScriptConverterfor the given scripting language to translate the code before being compiled.Notice that the script will be compiled when first used. To compile it without execution, invoke
Script.validate().Throws
ScriptRuntimeExceptionif creating the script failed.- Parameters:
abbreviation- the scripting language abbreviation, null or empty for default languagecode- the scripting codecached- the same code should refer to the same compiled script objectthreadSafe- true if script may be used by more than one thread in parallelconverterProvider- the optional script converter provider- Returns:
- the script, never null
-