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.booleanhasComponent(String id) Checks if a component exists in the registry.voidinitialize(List<FrameworkComponentSource> frameworkComponentSources, List<ComponentSource> componentSources) Primary method of initializing the registry with components.booleanWhether the component key is case-insensitive.booleanprotected StringnormalizeId(String id) Normalizes the id to be used in the registry.Removes a component from the registry.protected Rself()voidsetComponentIdCaseInsensitive(boolean componentIdCaseInsensitive) Whether the component key is case-insensitive.voidsetFailOnValidationError(boolean failOnValidationError) voidValidates each component within the registry using theComponentValidatorManager.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
FrameworkComponentSourcewill be used to register any frameworkComponents. Second, the list ofComponentSourcewill be used to register new components and extend any framework components. Lastly, theComponentValidatorManagerwill 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 anIllegalStateExceptionto 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:ComponentRegistryAdds a component to the registry.- Specified by:
addComponentin interfaceComponentRegistry<R extends AbstractComponentRegistry<R>>- Parameters:
id- The id of the componentcomponent- The component to add- Returns:
- The registry
-
removeComponent
Description copied from interface:ComponentRegistryRemoves a component from the registry.- Specified by:
removeComponentin interfaceComponentRegistry<R extends AbstractComponentRegistry<R>>- Parameters:
id- The id of the component- Returns:
- The registry
-
hasComponent
Description copied from interface:ComponentRegistryChecks if a component exists in the registry.- Specified by:
hasComponentin 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:ComponentRegistryRetrieves a component from the registry.- Specified by:
getComponentin 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:ComponentRegistryGets all components in the registry.- Specified by:
getComponentsin 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
-