Class AbstractComponentRegistry<R extends AbstractComponentRegistry<R>>

java.lang.Object
com.broadleafcommerce.metadata.dsl.registry.AbstractComponentRegistry<R>
All Implemented Interfaces:
ComponentRegistry<R>
Direct Known Subclasses:
DefaultComponentRegistry

public abstract class AbstractComponentRegistry<R extends AbstractComponentRegistry<R>> extends Object implements ComponentRegistry<R>
An abstract implementation of 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 Details

  • 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 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.

      Parameters:
      frameworkComponentSources - the list of sources of framework components
      componentSources - the list of sources of components
    • validateRegistry

      public void validateRegistry()
      Validates each component within the registry using the 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.

    • addComponent

      public R addComponent(String id, @NonNull @NonNull Component<?> component)
      Description copied from interface: ComponentRegistry
      Adds a component to the registry.
      Specified by:
      addComponent in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
      Parameters:
      id - The id of the component
      component - The component to add
      Returns:
      The registry
    • removeComponent

      public R removeComponent(String id)
      Description copied from interface: ComponentRegistry
      Removes a component from the registry.
      Specified by:
      removeComponent in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
      Parameters:
      id - The id of the component
      Returns:
      The registry
    • hasComponent

      public boolean hasComponent(String id)
      Description copied from interface: ComponentRegistry
      Checks if a component exists in the registry.
      Specified by:
      hasComponent in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
      Parameters:
      id - The id of the component
      Returns:
      True if the component exists, false otherwise.
    • getComponent

      public Component<?> getComponent(String id)
      Description copied from interface: ComponentRegistry
      Retrieves a component from the registry.
      Specified by:
      getComponent in interface ComponentRegistry<R extends AbstractComponentRegistry<R>>
      Parameters:
      id - The id of the component
      Returns:
      The component
    • self

      protected R self()
    • normalizeId

      protected String normalizeId(String id)
      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

      public ComponentValidatorManager getValidatorManager()
    • getComponents

      public Map<String,Component<?>> getComponents()
      Description copied from interface: ComponentRegistry
      Gets all components in the registry.
      Specified by:
      getComponents in interface ComponentRegistry<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 in components. 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 in components. Default is true.

      This is accomplished by forcing keys to be lower-cased.

      Since:
      2.0.6