Class AbstractComponentRegistry<R extends AbstractComponentRegistry<R>>
- All Implemented Interfaces:
ComponentRegistry<R>
- Direct Known Subclasses:
DefaultComponentRegistry
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.
- Author:
- Nick Crum (ncrum)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddComponent
(String id, @NonNull Component<?> component) Adds a component to the registry.Component<?>
getComponent
(String id) Retrieves a component from the registry.Gets all components in the registry.boolean
hasComponent
(String id) Checks if a component exists in the registry.void
initialize
(List<FrameworkComponentSource> frameworkComponentSources, List<ComponentSource> componentSources) Primary method of initializing the registry with components.boolean
Whether the component key is case-insensitive.boolean
protected String
normalizeId
(String id) Normalizes the id to be used in the registry.Removes a component from the registry.protected R
self()
void
setComponentIdCaseInsensitive
(boolean componentIdCaseInsensitive) Whether the component key is case-insensitive.void
setFailOnValidationError
(boolean failOnValidationError) void
Validates each component within the registry using theComponentValidatorManager
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.metadata.dsl.registry.ComponentRegistry
add, add, get, get, getComponent, has, remove, reRegisterComponents
-
Constructor Details
-
AbstractComponentRegistry
-
-
Method Details
-
initialize
public void initialize(@Nullable List<FrameworkComponentSource> frameworkComponentSources, @Nullable List<ComponentSource> componentSources) Primary method of initializing the registry with components.First, the list of
FrameworkComponentSource
will be used to register any frameworkComponents
. Second, the list ofComponentSource
will be used to register new components and extend any framework components. Lastly, theComponentValidatorManager
will be used invalidateRegistry()
to validate every the components within the registry.- Parameters:
frameworkComponentSources
- the list of sources of framework componentscomponentSources
- the list of sources of components
-
validateRegistry
public void validateRegistry()Validates each component within the registry using theComponentValidatorManager
.If
isFailOnValidationError()
is set to true, then any validation errors will cause anIllegalStateException
to be thrown. If it is set to false, then no exception will be thrown, but debug logging may still occur within theComponentValidatorManager
. -
addComponent
Description copied from interface:ComponentRegistry
Adds a component to the registry.- Specified by:
addComponent
in interfaceComponentRegistry<R extends AbstractComponentRegistry<R>>
- Parameters:
id
- The id of the componentcomponent
- The component to add- Returns:
- The registry
-
removeComponent
Description copied from interface:ComponentRegistry
Removes a component from the registry.- Specified by:
removeComponent
in interfaceComponentRegistry<R extends AbstractComponentRegistry<R>>
- Parameters:
id
- The id of the component- Returns:
- The registry
-
hasComponent
Description copied from interface:ComponentRegistry
Checks if a component exists in the registry.- Specified by:
hasComponent
in interfaceComponentRegistry<R extends AbstractComponentRegistry<R>>
- Parameters:
id
- The id of the component- Returns:
- True if the component exists, false otherwise.
-
getComponent
Description copied from interface:ComponentRegistry
Retrieves a component from the registry.- Specified by:
getComponent
in interfaceComponentRegistry<R extends AbstractComponentRegistry<R>>
- Parameters:
id
- The id of the component- Returns:
- The component
-
self
-
normalizeId
Normalizes the id to be used in the registry. This is typically used to ensure that the id is case-insensitive.- Parameters:
id
- The id to normalize.- Returns:
- The normalized id.
- Since:
- 2.0.6
-
getValidatorManager
-
getComponents
Description copied from interface:ComponentRegistry
Gets all components in the registry.- Specified by:
getComponents
in interfaceComponentRegistry<R extends AbstractComponentRegistry<R>>
- Returns:
- A map of all components in the registry, keyed by their id.
-
isFailOnValidationError
public boolean isFailOnValidationError() -
isComponentIdCaseInsensitive
public boolean isComponentIdCaseInsensitive()Whether the component key is case-insensitive. This is used when storing, retrieving, and removing entries incomponents
. Default is true.This is accomplished by forcing keys to be lower-cased.
- Since:
- 2.0.6
-
setFailOnValidationError
public void setFailOnValidationError(boolean failOnValidationError) -
setComponentIdCaseInsensitive
public void setComponentIdCaseInsensitive(boolean componentIdCaseInsensitive) Whether the component key is case-insensitive. This is used when storing, retrieving, and removing entries incomponents
. Default is true.This is accomplished by forcing keys to be lower-cased.
- Since:
- 2.0.6
-