eXo Kernel :: Container 2.5.0-GA

org.exoplatform.container
Class CachingContainer

java.lang.Object
  extended by org.exoplatform.container.AbstractContainer
      extended by org.exoplatform.container.AbstractInterceptor
          extended by org.exoplatform.container.CachingContainer
All Implemented Interfaces:
Serializable, Container, Interceptor, Disposable, Startable

public class CachingContainer
extends AbstractInterceptor

Version:
$Revision$
Author:
Julien Viet
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.exoplatform.container.AbstractInterceptor
holder, parent
 
Fields inherited from class org.exoplatform.container.AbstractContainer
delegate
 
Constructor Summary
CachingContainer()
           
 
Method Summary
<T> ComponentAdapter<T>
getComponentAdapterOfType(Class<T> componentType, boolean autoRegistration)
          Find a component adapter associated with the specified type.
<T> List<ComponentAdapter<T>>
getComponentAdaptersOfType(Class<T> componentType)
          Retrieve all component adapters inside this container that are associated with the specified type.
<T> T
getComponentInstance(Object componentKey, Class<T> bindType, boolean autoRegistration)
          Retrieve a component instance registered with a specific key.
<T> T
getComponentInstanceOfType(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.
 String getId()
          Gives an identifier to the Container, allowing to inject an Interceptor into the Interceptor chain.
<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 class org.exoplatform.container.AbstractInterceptor
setHolder, setParent, setSuccessor
 
Methods inherited from class org.exoplatform.container.AbstractContainer
accept, createComponent, dispose, getComponentAdapter, getComponentAdapters, getManagementContext, getMBeanServer, getScopingObjectName, getSuccessor, initialize, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.exoplatform.container.spi.Container
accept, createComponent, getComponentAdapter, getComponentAdapters, getManagementContext, getMBeanServer, getScopingObjectName, getSuccessor, initialize
 
Methods inherited from interface org.picocontainer.Startable
start, stop
 
Methods inherited from interface org.picocontainer.Disposable
dispose
 

Constructor Detail

CachingContainer

public CachingContainer()
Method Detail

getComponentAdapterOfType

public <T> ComponentAdapter<T> getComponentAdapterOfType(Class<T> componentType,
                                                         boolean autoRegistration)
Description copied from class: AbstractContainer
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:
getComponentAdapterOfType in interface Container
Overrides:
getComponentAdapterOfType in class AbstractContainer
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 null if no component has been registered for the specified key.

getComponentAdaptersOfType

public <T> List<ComponentAdapter<T>> getComponentAdaptersOfType(Class<T> componentType)
Description copied from class: AbstractContainer
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:
getComponentAdaptersOfType in interface Container
Overrides:
getComponentAdaptersOfType in class AbstractContainer
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

public <T> List<T> getComponentInstancesOfType(Class<T> componentType)
                                    throws ContainerException
Description copied from class: AbstractContainer
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:
getComponentInstancesOfType in interface Container
Overrides:
getComponentInstancesOfType in class AbstractContainer
Parameters:
componentType - the searched type.
Returns:
a List of components.
Throws:
ContainerException

getComponentInstance

public <T> T getComponentInstance(Object componentKey,
                                  Class<T> bindType,
                                  boolean autoRegistration)
                       throws ContainerException
Description copied from class: AbstractContainer
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:
getComponentInstance in interface Container
Overrides:
getComponentInstance in class AbstractContainer
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 null if no component has been registered for the specified key.
Throws:
ContainerException

getComponentInstanceOfType

public <T> T getComponentInstanceOfType(Class<T> componentType,
                                        boolean autoRegistration)
Description copied from class: AbstractContainer
Find a component instance matching the specified type.

Specified by:
getComponentInstanceOfType in interface Container
Overrides:
getComponentInstanceOfType in class AbstractContainer
Parameters:
componentType - the type of the component.
autoRegistration - indicates whether the auto registration should be performed or not
Returns:
the adapter matching the class.

unregisterComponent

public ComponentAdapter<?> unregisterComponent(Object componentKey)
Description copied from class: AbstractContainer
Unregister a component by key.

Specified by:
unregisterComponent in interface Container
Overrides:
unregisterComponent in class AbstractContainer
Parameters:
componentKey - key of the component to unregister.
Returns:
the ComponentAdapter that was associated with this component.

registerComponentInstance

public <T> ComponentAdapter<T> registerComponentInstance(Object componentKey,
                                                         T componentInstance)
                                              throws ContainerException
Description copied from class: AbstractContainer
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:
registerComponentInstance in interface Container
Overrides:
registerComponentInstance in class AbstractContainer
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 the Container interface can be used to retrieve a reference to the component later on.
Throws:
ContainerException - if registration fails.

registerComponentImplementation

public <T> ComponentAdapter<T> registerComponentImplementation(Object componentKey,
                                                               Class<T> componentImplementation)
                                                    throws ContainerException
Description copied from class: AbstractContainer
Register a component.

Specified by:
registerComponentImplementation in interface Container
Overrides:
registerComponentImplementation in class AbstractContainer
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 the Container interface can be used to retrieve a reference to the component later on.
Throws:
ContainerException

getId

public String getId()
Gives an identifier to the Container, allowing to inject an Interceptor into the Interceptor chain.

Specified by:
getId in interface Interceptor
Overrides:
getId in class AbstractInterceptor

eXo Kernel :: Container 2.5.0-GA

Copyright © 2014 eXo Platform SAS. All Rights Reserved.