Package org.exoplatform.container.spi
Interface Container
-
- All Superinterfaces:
Disposable,Serializable,Startable
- All Known Subinterfaces:
Interceptor
- All Known Implementing Classes:
AbstractContainer,AbstractInterceptor,CachingContainer,ConcurrentContainer,ExoContainer,ManageableContainer,PortalContainer,RootContainer,StandaloneContainer
public interface Container extends Startable, Disposable, Serializable
This interface defines all the methods that we need to implement in order to allow eXo Kernel to delegate the whole life cycle of the components. An implementation needs to be able to:- Register a new component
- Manage the creation of the components
- Manage the initialization of the components
- Manage the startup of the components
- Manage the shutdown of the components
- Manage the destruction of the components
- Provide the components matching with some specific criteria
- Version:
- $Id$
- Author:
- Nicolas Filotto
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaccept(ContainerVisitor visitor)Accepts a visitor that should visit the child containers, component adapters and component instances.<T> TcreateComponent(Class<T> clazz, InitParams params)Creates a component corresponding to the givenClasswith the givenInitParams<T> ComponentAdapter<T>getComponentAdapter(Object componentKey, Class<T> bindType, boolean autoRegistration)Find a component adapter associated with the specified key.<T> ComponentAdapter<T>getComponentAdapterOfType(Class<T> componentType, boolean autoRegistration)Find a component adapter associated with the specified type.Collection<ComponentAdapter<?>>getComponentAdapters()Retrieve all the component adapters inside this container.<T> List<ComponentAdapter<T>>getComponentAdaptersOfType(Class<T> componentType)Retrieve all component adapters inside this container that are associated with the specified type.<T> TgetComponentInstance(Object componentKey, Class<T> bindType, boolean autoRegistration)Retrieve a component instance registered with a specific key.<T> TgetComponentInstanceOfType(Class<T> componentType, boolean autoRegistration)Find a component instance matching the specified type.<T> List<T>getComponentInstancesOfType(Class<T> componentType)Returns a List of components of a certain componentType.ManagementContextgetManagementContext()Gives the correspondingManagementContextMBeanServergetMBeanServer()Provides theMBeanServerthis method is needed for backward compatibilityObjectNamegetScopingObjectName()Gives the ObjectName of the container build from the scoping dataInterceptorgetSuccessor()Retrieve the successor of this container in the chain ofInterceptor.voidinitialize()Initializes the container<T> ComponentAdapter<T>registerComponentImplementation(Object componentKey, Class<T> componentImplementation)Register a component.<T> ComponentAdapter<T>registerComponentInstance(Object componentKey, T componentInstance)Register an arbitrary object as a component in the container.ComponentAdapter<?>unregisterComponent(Object componentKey)Unregister a component by key.-
Methods inherited from interface org.picocontainer.Disposable
dispose
-
-
-
-
Method Detail
-
getComponentInstance
<T> T getComponentInstance(Object componentKey, Class<T> bindType, boolean autoRegistration)
Retrieve a component instance registered with a specific key. If a component cannot be found in this container, the parent container (if one exists) will be searched.- Parameters:
componentKey- the key that the component was registered with.bindType- the expected type of the instance if one can be found.autoRegistration- indicates whether the auto registration should be performed or not- Returns:
- an instantiated component, or
nullif no component has been registered for the specified key.
-
getComponentInstanceOfType
<T> T getComponentInstanceOfType(Class<T> componentType, boolean autoRegistration)
Find a component instance matching the specified type.- Parameters:
componentType- the type of the component.autoRegistration- indicates whether the auto registration should be performed or not- Returns:
- the adapter matching the class.
-
getSuccessor
Interceptor getSuccessor()
Retrieve the successor of this container in the chain ofInterceptor.- Returns:
- a
Interceptorinstance, ornullif this container does not have a successor.
-
getComponentAdapter
<T> ComponentAdapter<T> getComponentAdapter(Object componentKey, Class<T> bindType, boolean autoRegistration)
Find a component adapter associated with the specified key. If a component adapter cannot be found in this container, the parent container (if one exists) will be searched.- Parameters:
componentKey- the key that the component was registered with.bindType- the expected raw type of the adapter if one can be found.autoRegistration- indicates whether the auto registration should be performed or not- Returns:
- the component adapter associated with this key, or
nullif no component has been registered for the specified key.
-
getComponentAdapterOfType
<T> ComponentAdapter<T> getComponentAdapterOfType(Class<T> componentType, boolean autoRegistration)
Find a component adapter associated with the specified type. If a component adapter cannot be found in this container, the parent container (if one exists) will be searched.- Parameters:
componentType- the type of the component.autoRegistration- indicates whether the auto registration should be performed or not- Returns:
- the component adapter associated with this class, or
nullif no component has been registered for the specified key.
-
getComponentAdapters
Collection<ComponentAdapter<?>> getComponentAdapters()
Retrieve all the component adapters inside this container. The component adapters from the parent container are not returned.- Returns:
- a collection containing all the
ComponentAdapters inside this container. The collection will not be modifiable. - See Also:
a variant of this method which returns the component adapters inside this container that are associated with the specified type.
-
getComponentAdaptersOfType
<T> List<ComponentAdapter<T>> getComponentAdaptersOfType(Class<T> componentType)
Retrieve all component adapters inside this container that are associated with the specified type. The component adapters from the parent container are not returned.- Parameters:
componentType- the type of the components.- Returns:
- a collection containing all the
ComponentAdapters inside this container that are associated with the specified type. Changes to this collection will not be reflected in the container itself.
-
getComponentInstancesOfType
<T> List<T> getComponentInstancesOfType(Class<T> componentType) throws ContainerException
Returns a List of components of a certain componentType. The list is ordered by instantiation order, starting with the components instantiated first at the beginning.- Parameters:
componentType- the searched type.- Returns:
- a List of components.
- Throws:
ContainerException
-
accept
void accept(ContainerVisitor visitor)
Accepts a visitor that should visit the child containers, component adapters and component instances.- Parameters:
visitor- the visitor
-
registerComponentImplementation
<T> ComponentAdapter<T> registerComponentImplementation(Object componentKey, Class<T> componentImplementation) throws ContainerException
Register a component.- Parameters:
componentKey- a key that identifies the component. Must be unique within the container. The type of the key object has no semantic significance unless explicitly specified in the documentation of the implementing container.componentImplementation- the component's implementation class. This must be a concrete class (ie, a class that can be instantiated).- Returns:
- the ComponentAdapter that has been associated with this component. In the majority of cases, this return
value can be safely ignored, as one of the
getXXX()methods of theContainerinterface can be used to retrieve a reference to the component later on. - Throws:
ContainerException- if registration of the component fails.
-
registerComponentInstance
<T> ComponentAdapter<T> registerComponentInstance(Object componentKey, T componentInstance) throws ContainerException
Register an arbitrary object as a component in the container. This is handy when other components in the same container have dependencies on this kind of object, but where letting the container manage and instantiate it is impossible.
Beware that too much use of this method is an antipattern.- Parameters:
componentKey- a key that identifies the component. Must be unique within the container. The type of the key object has no semantic significance unless explicitly specified in the implementing container.componentInstance- an arbitrary object.- Returns:
- the ComponentAdapter that has been associated with this component. In the majority of cases, this return
value can be safely ignored, as one of the
getXXX()methods of theContainerinterface can be used to retrieve a reference to the component later on. - Throws:
ContainerException- if registration fails.
-
unregisterComponent
ComponentAdapter<?> unregisterComponent(Object componentKey)
Unregister a component by key.- Parameters:
componentKey- key of the component to unregister.- Returns:
- the ComponentAdapter that was associated with this component.
-
getManagementContext
ManagementContext getManagementContext()
Gives the correspondingManagementContext
-
getMBeanServer
MBeanServer getMBeanServer()
Provides theMBeanServerthis method is needed for backward compatibility
-
getScopingObjectName
ObjectName getScopingObjectName()
Gives the ObjectName of the container build from the scoping data
-
createComponent
<T> T createComponent(Class<T> clazz, InitParams params) throws Exception
Creates a component corresponding to the givenClasswith the givenInitParams- Parameters:
clazz- the Class of the object to createparams- the parameters to use to create the component- Returns:
- an instance of the component
- Throws:
Exception- if any issue occurs while creating the component.
-
initialize
void initialize()
Initializes the container
-
-