LibraryRegistry
com.jsmacrosce.jsmacros.core.library.LibraryRegistry
Registers library classes and supplies applicable instances as globals for script runs.
Instances are shared, created per language, per execution, or per execution and language,
according to the library superclass.
Constructors
new LibraryRegistry
Fields
libraries
Libraries instantiated once when registered and then shared, keyed by their Library annotation.
perExec
Per-execution library classes; each applicable class is instantiated for a script run using a BaseScriptContext.
perExecLanguage
perExecLanguage: Map<Class<? extends BaseLanguage<?, ?>>, Map<Library, Class<? extends PerExecLanguageLibrary<?, ?>>>>read-only#Per-execution, per-language library classes, keyed by their registered language class. Applicable classes are instantiated for each run with its context and the language class.
perLanguage
Methods
addLibrary
addLibrary(Class<? extends BaseLibrary> clazz): void#Registers a library class, instantiating shared and per-language kinds immediately and storing per-execution kinds for later construction. The superclass determines the kind. Registration requires a Library annotation; per-language construction uses a Core and the registered language class, while shared construction uses a Core. This method is synchronized.
Parameters:
clazz: the library class to register
getLibraries
getLibraries(BaseLanguage<?, ?> language, BaseScriptContext<?> context): Map<String, BaseLibrary>#Returns applicable shared and per-execution libraries. Per-execution instances are constructed by this call; shared instances are reused.
Parameters:
language: the language the script is being run incontext: the run context used to construct per-execution libraries
Returns: libraries keyed by their Library global names
getOnceLibraries
getOnceLibraries(BaseLanguage<?, ?> language): Map<String, BaseLibrary>#Returns shared libraries registered for all languages or this exact language, plus per-language instances registered for this language or one of its superclasses.
Parameters:
language: the language the libraries are being asked for
Returns: libraries keyed by their Library global names
getPerExecLibraries
getPerExecLibraries(BaseLanguage<?, ?> language, BaseScriptContext<?> context): Map<String, BaseLibrary>#Constructs and returns applicable per-execution libraries. Construction failures are wrapped in a RuntimeException.
Parameters:
language: the language the libraries are being asked forcontext: the run context used to construct libraries
Returns: libraries keyed by their Library global names