public final class ChangeTemplateManager
extends java.lang.Object
ChangeTemplate implementations.
This class serves two primary purposes in different contexts:
getTemplates() method is called by
the GraalVM RegistrationFeature to discover all available templates. For each template,
the feature registers both the template class itself and all classes returned by
ReflectionMetadataProvider.getReflectiveClasses() for reflection in native images.loadTemplates() method is called during
Flamingock initialization to populate the internal registry with all available templates
for use during execution.
Templates are discovered through Java's ServiceLoader mechanism from two sources:
ChangeTemplate registered via SPIChangeTemplateFactory implementations registered via SPI
Thread Safety Note: This class is not thread-safe during initialization. The
loadTemplates() method modifies static state and is intended to be called only once
during application startup from a single thread. After initialization, the template registry
is effectively read-only and can be safely accessed concurrently.
| Modifier and Type | Method and Description |
|---|---|
static void |
addTemplate(java.lang.String templateName,
java.lang.Class<? extends io.flamingock.api.template.ChangeTemplate<?,?,?>> templateClass)
Adds a template to the internal registry for testing purposes.
|
static java.util.Optional<java.lang.Class<? extends io.flamingock.api.template.ChangeTemplate<?,?,?>>> |
getTemplate(java.lang.String templateName)
Retrieves a template class by name from the internal registry.
|
static java.util.Collection<io.flamingock.api.template.ChangeTemplate<?,?,?>> |
getTemplates()
Discovers and returns all available templates from the classpath.
|
static void |
loadTemplates()
Loads and registers all available templates from the classpath into the internal registry.
|
public static void loadTemplates()
This method is intended to be called once during Flamingock runtime initialization.
It discovers all templates via getTemplates() and registers them in the internal
registry, indexed by their simple class name.
This method is not thread-safe and should be called from a single thread during application startup before any template lookups are performed.
public static java.util.Collection<io.flamingock.api.template.ChangeTemplate<?,?,?>> getTemplates()
This method is used in two contexts:
loadTemplates() method during runtime initialization to populate
the internal template registryTemplates are discovered from two sources:
ChangeTemplate registered via SPIChangeTemplateFactory implementations registered via SPIThis method creates new instances of templates each time it's called and does not modify any internal state.
@TestOnly
public static void addTemplate(java.lang.String templateName,
java.lang.Class<? extends io.flamingock.api.template.ChangeTemplate<?,?,?>> templateClass)
This method is intended for use in test environments only to register mock or test templates. It directly modifies the internal template registry and is not thread-safe.
templateName - The name to register the template under (typically the simple class name)templateClass - The template class to registerpublic static java.util.Optional<java.lang.Class<? extends io.flamingock.api.template.ChangeTemplate<?,?,?>>> getTemplate(java.lang.String templateName)
This method is used during runtime to look up template classes by their simple name.
It returns an Optional that will be empty if no template with the specified
name has been registered.
This method is thread-safe after initialization (after loadTemplates() has been called).
templateName - The simple class name of the template to retrieve