public abstract class AbstractComponentRegistry<R extends AbstractComponentRegistry<R>> extends Object implements ComponentRegistry<R>
ComponentRegistry
used for storing and retrieving
Components
.
This registry is typically configured as a bean during the auto-configuration of a Spring Boot
application. In most cases, the initialize(List, List)
method will be called shortly
after instantiation to initialize the registry using a set of ComponentSource
and
FrameworkComponentSource
beans. FrameworkComponentSource
beans will be processed
prior to the ComponentSource
beans, which allows ComponentSource
beans to
potentially extend or modify the framework components.
Once the registry has been initialized by the component sources, the initialization will make a
call to validateRegistry()
in order to validate each and every component within the
registry using ComponentValidatorManager
. If isFailOnValidationError()
is true,
this will cause an IllegalStateException
to be thrown.
Constructor and Description |
---|
AbstractComponentRegistry(ComponentValidatorManager validatorManager) |
Modifier and Type | Method and Description |
---|---|
R |
add(Component<?> component) |
R |
add(String id,
Component<?> component) |
R |
addComponent(String id,
Component<?> component) |
Component<?> |
get(String id) |
<T extends Component<T>> |
get(String key,
Class<T> clazz) |
Component<?> |
getComponent(String id) |
<T extends Component<T>> |
getComponent(String id,
Class<T> clazz) |
Map<String,Component<?>> |
getComponents() |
ComponentValidatorManager |
getValidatorManager() |
boolean |
has(String id) |
boolean |
hasComponent(String id) |
void |
initialize(List<FrameworkComponentSource> frameworkComponentSources,
List<ComponentSource> componentSources)
Primary method of initializing the registry with components.
|
boolean |
isFailOnValidationError() |
R |
remove(String id) |
R |
removeComponent(String id) |
protected R |
self() |
void |
setFailOnValidationError(boolean failOnValidationError) |
void |
validateRegistry()
Validates each component within the registry using the
ComponentValidatorManager . |
public AbstractComponentRegistry(ComponentValidatorManager validatorManager)
public void initialize(@Nullable List<FrameworkComponentSource> frameworkComponentSources, @Nullable List<ComponentSource> componentSources)
First, the list of FrameworkComponentSource
will be used to register any framework
Components
. Second, the list of ComponentSource
will be used to
register new components and extend any framework components. Lastly, the
ComponentValidatorManager
will be used in validateRegistry()
to validate
every the components within the registry.
frameworkComponentSources
- the list of sources of framework componentscomponentSources
- the list of sources of componentspublic void validateRegistry()
ComponentValidatorManager
.
If isFailOnValidationError()
is set to true, then any validation errors
will cause an IllegalStateException
to be thrown. If it is set to false,
then no exception will be thrown, but debug logging may still occur within the
ComponentValidatorManager
.
protected R self()
public R addComponent(String id, Component<?> component)
addComponent
in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
public R add(String id, Component<?> component)
add
in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
public R add(Component<?> component)
add
in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
public R removeComponent(String id)
removeComponent
in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
public R remove(String id)
remove
in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
public boolean hasComponent(String id)
hasComponent
in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
public boolean has(String id)
has
in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
public Component<?> getComponent(String id)
getComponent
in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
public <T extends Component<T>> T getComponent(String id, Class<T> clazz)
getComponent
in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
public Component<?> get(String id)
get
in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
public <T extends Component<T>> T get(String key, Class<T> clazz)
get
in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
public ComponentValidatorManager getValidatorManager()
public Map<String,Component<?>> getComponents()
getComponents
in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
public boolean isFailOnValidationError()
public void setFailOnValidationError(boolean failOnValidationError)
Copyright © 2021. All rights reserved.