Package org.bluezoo.gumdrop.config
Class ComponentRegistry
java.lang.Object
org.bluezoo.gumdrop.config.ComponentRegistry
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetComponent(String id) Get a component instance by ID without type checking.<T> TgetComponent(String id, Class<T> type) Get or create a component instance by ID.Get all registered component IDs.<T> Collection<T>getComponentsOfType(Class<T> type) Get all components of a given type.booleanhasComponent(String id) Check if a component with the given ID is registered.voidregister(String id, ComponentDefinition definition) Register a component definition.voidshutdown()Shutdown all singleton components by calling their destroy methods.
-
Constructor Details
-
ComponentRegistry
public ComponentRegistry()
-
-
Method Details
-
register
Register a component definition.- Parameters:
id- the unique component identifierdefinition- the component definition- Throws:
IllegalArgumentException- if id is null or already registered
-
getComponent
Get or create a component instance by ID.- Parameters:
id- the component identifiertype- the expected component type- Returns:
- the component instance
- Throws:
IllegalArgumentException- if no component registered with this idIllegalStateException- if circular dependency detectedClassCastException- if component is not of expected type
-
getComponent
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 idIllegalStateException- if circular dependency detected
-
hasComponent
Check if a component with the given ID is registered.- Parameters:
id- the component identifier- Returns:
- true if registered, false otherwise
-
getComponentsOfType
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
Get all registered component IDs.- Returns:
- set of all component IDs
-
shutdown
public void shutdown()Shutdown all singleton components by calling their destroy methods.
-