Class ComponentRegistry

java.lang.Object
org.bluezoo.gumdrop.config.ComponentRegistry

public class ComponentRegistry extends Object
Simple dependency injection container for Gumdrop components. Manages component lifecycle and dependency wiring without external dependencies.

This registry provides:

  • Component registration by ID
  • Dependency resolution with circular detection
  • Singleton lifecycle management
  • Type-safe component retrieval
  • Automatic property injection via setters
  • Optional lifecycle methods (init/destroy)
Author:
Chris Burdess
  • Constructor Details

    • ComponentRegistry

      public ComponentRegistry()
  • Method Details

    • register

      public void register(String id, ComponentDefinition definition)
      Register a component definition.
      Parameters:
      id - the unique component identifier
      definition - the component definition
      Throws:
      IllegalArgumentException - if id is null or already registered
    • getComponent

      public <T> T getComponent(String id, Class<T> type)
      Get or create a component instance by ID.
      Parameters:
      id - the component identifier
      type - the expected component type
      Returns:
      the component instance
      Throws:
      IllegalArgumentException - if no component registered with this id
      IllegalStateException - if circular dependency detected
      ClassCastException - if component is not of expected type
    • getComponent

      public Object getComponent(String id)
      Get a component instance by ID without type checking.
      Parameters:
      id - the component identifier
      Returns:
      the component instance
      Throws:
      IllegalArgumentException - if no component registered with this id
      IllegalStateException - if circular dependency detected
    • hasComponent

      public boolean hasComponent(String id)
      Check if a component with the given ID is registered.
      Parameters:
      id - the component identifier
      Returns:
      true if registered, false otherwise
    • getComponentsOfType

      public <T> Collection<T> getComponentsOfType(Class<T> type)
      Get all components of a given type. This will instantiate all matching components.
      Parameters:
      type - the component type
      Returns:
      collection of all matching components
    • getComponentIds

      public Set<String> getComponentIds()
      Get all registered component IDs.
      Returns:
      set of all component IDs
    • shutdown

      public void shutdown()
      Shutdown all singleton components by calling their destroy methods.