Package org.xwiki.component.manager
Interface ComponentManager
-
- All Known Subinterfaces:
NamespacedComponentManager
@Role public interface ComponentManager
Provide way to access and modify components repository.- Version:
- $Id: 9fdb68edd7eb6e6a6c37561df64ad05e310f1e6e $
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description <T> ComponentDescriptor<T>
getComponentDescriptor(Type role, String hint)
<T> List<ComponentDescriptor<T>>
getComponentDescriptorList(Class<T> role)
Deprecated.since 4.0M1 usegetComponentDescriptorList(Type)
instead<T> List<ComponentDescriptor<T>>
getComponentDescriptorList(Type role)
ComponentEventManager
getComponentEventManager()
<T> T
getInstance(Type roleType)
Find a component instance that implements that passed type.<T> T
getInstance(Type roleType, String roleHint)
Find a component instance that implements that passed interface class.<T> List<T>
getInstanceList(Type role)
Find all the components implementing the provided role.<T> Map<String,T>
getInstanceMap(Type role)
Find all the components implementing the provided role and organize then in aMap
with role hint as key.ComponentManager
getParent()
boolean
hasComponent(Type role)
boolean
hasComponent(Type role, String hint)
<T> void
registerComponent(ComponentDescriptor<T> componentDescriptor)
Add a component in the component repository dynamically.<T> void
registerComponent(ComponentDescriptor<T> componentDescriptor, T componentInstance)
Add a component in the component repository dynamically.void
release(Object componentInstance)
Release the provided singleton instance but don't unregister the component descriptor.void
setComponentEventManager(ComponentEventManager eventManager)
void
setParent(ComponentManager parentComponentManager)
void
unregisterComponent(Type role, String hint)
Remove a component from the component repository dynamically.void
unregisterComponent(ComponentDescriptor<?> componentDescriptor)
Remove a component from the component repository dynamically.
-
-
-
Method Detail
-
hasComponent
boolean hasComponent(Type role)
- Parameters:
role
- the class (aka role) that the component implements- Returns:
- true if the component is registered or false otherwise
- Since:
- 4.0M1
-
hasComponent
boolean hasComponent(Type role, String hint)
- Parameters:
role
- the class (aka role) that the component implementshint
- the hint that differentiates a component implementation from another one (each component is registered with a hint; the "default" hint being the default)- Returns:
- true if the component is registered for the passed hint or false otherwise
- Since:
- 4.0M1
-
getInstance
<T> T getInstance(Type roleType) throws ComponentLookupException
Find a component instance that implements that passed type. If the component has a singleton lifecycle then this method always return the same instance.- Type Parameters:
T
- the component role type- Parameters:
roleType
- the class (aka role) that the component implements- Returns:
- the component instance
- Throws:
ComponentLookupException
- if any error happen during component search (the component does not exist, the instance fail to initialize)- Since:
- 4.0RC1
-
getInstance
<T> T getInstance(Type roleType, String roleHint) throws ComponentLookupException
Find a component instance that implements that passed interface class. If the component has a singleton lifecycle then this method always return the same instance.- Type Parameters:
T
- the component role type- Parameters:
roleType
- the class (aka role) that the component implementsroleHint
- the hint that differentiates a component implementation from another one (each component is registered with a hint; the "default" hint being the default)- Returns:
- the component instance
- Throws:
ComponentLookupException
- if any error happen during component search (the component does not exist, the instance fail to initialize)- Since:
- 4.0RC1
-
release
void release(Object componentInstance) throws ComponentLifecycleException
Release the provided singleton instance but don't unregister the component descriptor. This means that next time the component is looked up a new instance will be created.- Parameters:
componentInstance
- the component to release passed as a component instance.- Throws:
ComponentLifecycleException
- if the component's ending lifecycle raises an error- Since:
- 4.0M1
-
getInstanceList
<T> List<T> getInstanceList(Type role) throws ComponentLookupException
Find all the components implementing the provided role.- Type Parameters:
T
- the type of the components role- Parameters:
role
- the type of the components role- Returns:
- the components
- Throws:
ComponentLookupException
- if any error happen during component search- Since:
- 4.0RC1
-
getInstanceMap
<T> Map<String,T> getInstanceMap(Type role) throws ComponentLookupException
Find all the components implementing the provided role and organize then in aMap
with role hint as key.- Type Parameters:
T
- the type of the components role- Parameters:
role
- the type of the components role- Returns:
- the components
- Throws:
ComponentLookupException
- if any error happen during component search- Since:
- 4.0M1
-
registerComponent
<T> void registerComponent(ComponentDescriptor<T> componentDescriptor) throws ComponentRepositoryException
Add a component in the component repository dynamically.If a component with the same role and role hint already exists it will be replaced by this provided one when lookup.
- Type Parameters:
T
- the component role type- Parameters:
componentDescriptor
- the descriptor of the component to register.- Throws:
ComponentRepositoryException
- error when registering component descriptor.- Since:
- 1.7M1
-
registerComponent
<T> void registerComponent(ComponentDescriptor<T> componentDescriptor, T componentInstance) throws ComponentRepositoryException
Add a component in the component repository dynamically. This method also makes possible to set the instance returned by theComponentManager
instead of letting it created it from descriptor.If a component with the same role and role hint already exists it will be replaced by this provided one when lookup.
- Type Parameters:
T
- the component role type- Parameters:
componentDescriptor
- the descriptor of the component to register.componentInstance
- the initial component instance- Throws:
ComponentRepositoryException
- error when registering component descriptor.- Since:
- 2.0M2
-
unregisterComponent
void unregisterComponent(Type role, String hint)
Remove a component from the component repository dynamically.- Parameters:
role
- the role identifying the componenthint
- the hint identifying the component- Since:
- 4.0M1
-
unregisterComponent
void unregisterComponent(ComponentDescriptor<?> componentDescriptor)
Remove a component from the component repository dynamically.- Parameters:
componentDescriptor
- the component descriptor- Since:
- 4.0M1
-
getComponentDescriptor
<T> ComponentDescriptor<T> getComponentDescriptor(Type role, String hint)
- Type Parameters:
T
- the component role type- Parameters:
role
- the role identifying the componenthint
- the hint identifying the component- Returns:
- the descriptor for the component matching the passed parameter or null if this component doesn't exist
- Since:
- 4.0M1
-
getComponentDescriptorList
<T> List<ComponentDescriptor<T>> getComponentDescriptorList(Type role)
- Type Parameters:
T
- the role class for which to return all component implementations- Parameters:
role
- the role class for which to return all component implementations- Returns:
- all component implementations for the passed role
- Since:
- 4.0M1
-
getComponentEventManager
ComponentEventManager getComponentEventManager()
- Returns:
- the manager to use to send events when a component descriptor is registered
- Since:
- 2.1RC1
-
setComponentEventManager
void setComponentEventManager(ComponentEventManager eventManager)
- Parameters:
eventManager
- the manager to use to send events when a component descriptor is registered
-
getParent
ComponentManager getParent()
- Returns:
- the parent Component Manager of this Component Manager. When doing lookups if the component cannot be found in the current Component Manager it'll also be looked for in the parent Component Manager
-
setParent
void setParent(ComponentManager parentComponentManager)
- Parameters:
parentComponentManager
- seegetParent()
-
getComponentDescriptorList
@Deprecated <T> List<ComponentDescriptor<T>> getComponentDescriptorList(Class<T> role)
Deprecated.since 4.0M1 usegetComponentDescriptorList(Type)
instead- Type Parameters:
T
- the role class for which to return all component implementations- Parameters:
role
- the role class for which to return all component implementations- Returns:
- all component implementations for the passed role
-
-