org.xwiki.component.manager
Interface ComponentManager


@ComponentRole
public interface ComponentManager

Provide way to access and modify components repository.

Version:
$Id$

Method Summary
<T> ComponentDescriptor<T>
getComponentDescriptor(java.lang.Class<T> role, java.lang.String roleHint)
           
<T> java.util.List<ComponentDescriptor<T>>
getComponentDescriptorList(java.lang.Class<T> role)
           
 ComponentEventManager getComponentEventManager()
           
 ComponentManager getParent()
           
<T> boolean
hasComponent(java.lang.Class<T> role)
           
<T> boolean
hasComponent(java.lang.Class<T> role, java.lang.String roleHint)
           
<T> T
lookup(java.lang.Class<T> role)
          Find a component instance that implements that passed interface class.
<T> T
lookup(java.lang.Class<T> role, java.lang.String roleHint)
          Find a component instance that implements that passed interface class.
<T> java.util.List<T>
lookupList(java.lang.Class<T> role)
           
<T> java.util.Map<java.lang.String,T>
lookupMap(java.lang.Class<T> role)
           
<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.
<T> void
release(T component)
          Remove a component from the list of available components.
 void setComponentEventManager(ComponentEventManager eventManager)
           
 void setParent(ComponentManager parentComponentManager)
           
 void unregisterComponent(java.lang.Class<?> role, java.lang.String roleHint)
          Remove a component from the component repository dynamically.
 

Method Detail

hasComponent

<T> boolean hasComponent(java.lang.Class<T> role)
Type Parameters:
T - the component role type
Parameters:
role - the class (aka role) that the component implements
Returns:
true if the component is registered or false otherwise

hasComponent

<T> boolean hasComponent(java.lang.Class<T> role,
                         java.lang.String roleHint)
Type Parameters:
T - the component role type
Parameters:
role - the class (aka role) that the component implements
roleHint - 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

lookup

<T> T lookup(java.lang.Class<T> role)
         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:
role - the class (aka role) that the component implements
Returns:
the component instance
Throws:
ComponentLookupException - in case the component cannot be found

lookup

<T> T lookup(java.lang.Class<T> role,
             java.lang.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:
role - the class (aka role) that the component implements
roleHint - 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 - in case the component cannot be found

release

<T> void release(T component)
             throws ComponentLifecycleException
Remove a component from the list of available components.

Type Parameters:
T - the component role type
Parameters:
component - the component to release passed as a component instance. The component definition matching the passed instance is removed
Throws:
ComponentLifecycleException - if the component's ending lifecycle raises an error

lookupMap

<T> java.util.Map<java.lang.String,T> lookupMap(java.lang.Class<T> role)
                                            throws ComponentLookupException
Throws:
ComponentLookupException

lookupList

<T> java.util.List<T> lookupList(java.lang.Class<T> role)
                             throws ComponentLookupException
Throws:
ComponentLookupException

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 the ComponentManager 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(java.lang.Class<?> role,
                         java.lang.String roleHint)
Remove a component from the component repository dynamically.

Parameters:
role - the role identifying the component
roleHint - the hint identifying the component
Since:
2.0M2

getComponentDescriptor

<T> ComponentDescriptor<T> getComponentDescriptor(java.lang.Class<T> role,
                                                  java.lang.String roleHint)
Type Parameters:
T - the component role type
Parameters:
role - the role identifying the component
roleHint - the hint identifying the component
Returns:
the descriptor for the component matching the passed parameter or null if this component doesn't exist
Since:
2.0M1

getComponentDescriptorList

<T> java.util.List<ComponentDescriptor<T>> getComponentDescriptorList(java.lang.Class<T> 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

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 - see getParent()


Copyright © 2004-2011 XWiki. All Rights Reserved.