Skip to content

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 ​

new LibraryRegistry(Core<?, ?> runner)#
Stores the core used to instantiate shared and per-language libraries during registration.

Parameters:

  • runner: core used for subsequent library instantiation

Fields ​

libraries ​

libraries: Map<Library, BaseLibrary>read-only#
Libraries instantiated once when registered and then shared, keyed by their Library annotation.

perExec ​

perExec: Map<Library, Class<? extends PerExecLibrary>>read-only#
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 ​

perLanguage: Map<Class<? extends BaseLanguage<?, ?>>, Map<Library, PerLanguageLibrary>>read-only#
Per-language instances, keyed by the language class used at registration. A language class also receives entries registered for its superclasses.

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 in
  • context: 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 for
  • context: the run context used to construct libraries
Returns: libraries keyed by their Library global names