Package org.exoplatform.container
Class AbstractContainer
java.lang.Object
org.exoplatform.container.AbstractContainer
- All Implemented Interfaces:
Serializable,Container,Disposable,Startable
- Direct Known Subclasses:
AbstractInterceptor,ExoContainer
This class is the root class of all the implementations of a
Container.
It implements by default all the methods by delegating the call the the successor.- Version:
- $Id$
- Author:
- Nicolas Filotto
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(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 givenInitParamsvoiddispose()Dispose this component.<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.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.Gives the correspondingManagementContextProvides theMBeanServerthis method is needed for backward compatibilityGives the ObjectName of the container build from the scoping dataRetrieve the successor of this container in the chain ofInterceptor.voidInitializes the container<T> voidregisterComponentAdapter(ComponentAdapter<T> componentAdapter) Register a component adapter.<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.voidstart()Start this component.voidstop()Stop this component.unregisterComponent(Object componentKey) Unregister a component by key.
-
Field Details
-
delegate
-
-
Constructor Details
-
AbstractContainer
protected AbstractContainer() -
AbstractContainer
-
-
Method Details
-
start
public void start()Start this component. Called initially at the begin of the lifecycle. It can be called again after a stop. -
stop
public void stop()Stop this component. Called near the end of the lifecycle. It can be called again after a further start. ImplementDisposableif you need a single call at the definite end of the lifecycle. -
dispose
public void dispose()Dispose this component. The component should deallocate all resources. The contract for this method defines a single call at the end of this component's life.- Specified by:
disposein interfaceDisposable
-
getComponentInstance
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.- Specified by:
getComponentInstancein interfaceContainer- 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
Find a component instance matching the specified type.- Specified by:
getComponentInstanceOfTypein interfaceContainer- 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
Retrieve the successor of this container in the chain ofInterceptor.- Specified by:
getSuccessorin interfaceContainer- Returns:
- a
Interceptorinstance, ornullif this container does not have a successor.
-
getComponentAdapter
public <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.- Specified by:
getComponentAdapterin interfaceContainer- 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
public <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.- Specified by:
getComponentAdapterOfTypein interfaceContainer- 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
Retrieve all the component adapters inside this container. The component adapters from the parent container are not returned.- Specified by:
getComponentAdaptersin interfaceContainer- Returns:
- a collection containing all the
ComponentAdapters inside this container. The collection will not be modifiable. - See Also:
-
getComponentAdaptersOfType
Retrieve all component adapters inside this container that are associated with the specified type. The component adapters from the parent container are not returned.- Specified by:
getComponentAdaptersOfTypein interfaceContainer- 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
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.- Specified by:
getComponentInstancesOfTypein interfaceContainer- Parameters:
componentType- the searched type.- Returns:
- a List of components.
- Throws:
ContainerException
-
accept
Accepts a visitor that should visit the child containers, component adapters and component instances. -
registerComponentImplementation
public <T> ComponentAdapter<T> registerComponentImplementation(Object componentKey, Class<T> componentImplementation) throws ContainerException Register a component.- Specified by:
registerComponentImplementationin interfaceContainer- 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
public <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.- Specified by:
registerComponentInstancein interfaceContainer- 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
Unregister a component by key.- Specified by:
unregisterComponentin interfaceContainer- Parameters:
componentKey- key of the component to unregister.- Returns:
- the ComponentAdapter that was associated with this component.
-
registerComponentAdapter
Description copied from interface:ContainerRegister a component adapter.- Specified by:
registerComponentAdapterin interfaceContainer- Parameters:
componentAdapter- ComponentAdapter to register.
-
getManagementContext
Gives the correspondingManagementContext- Specified by:
getManagementContextin interfaceContainer
-
getMBeanServer
Provides theMBeanServerthis method is needed for backward compatibility- Specified by:
getMBeanServerin interfaceContainer
-
getScopingObjectName
Gives the ObjectName of the container build from the scoping data- Specified by:
getScopingObjectNamein interfaceContainer
-
createComponent
Creates a component corresponding to the givenClasswith the givenInitParams- Specified by:
createComponentin interfaceContainer- 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
public void initialize()Initializes the container- Specified by:
initializein interfaceContainer
-