org.picocontainer.gems.adapters
Class ThreadLocalized<T>

java.lang.Object
  extended by org.picocontainer.behaviors.AbstractBehavior<T>
      extended by org.picocontainer.gems.adapters.ThreadLocalized<T>
All Implemented Interfaces:
Serializable, Behavior<T>, ComponentAdapter<T>, ComponentMonitorStrategy, LifecycleStrategy

public final class ThreadLocalized<T>
extends AbstractBehavior<T>

A ComponentAdapter that realizes a ThreadLocal component instance.

The adapter creates proxy instances, that will create the necessary instances on-the-fly invoking the methods of the instance. Use this adapter, if you are instantiating your components in a single thread, but should be different when accessed from different threads. See ThreadLocalizing for details.

Note: Because this implementation uses a Proxy, you can only access the methods exposed by the implemented interfaces of your component.

Author:
Jörg Schaible
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.picocontainer.ComponentAdapter
ComponentAdapter.NOTHING
 
Field Summary
 
Fields inherited from class org.picocontainer.behaviors.AbstractBehavior
delegate
 
Constructor Summary
ThreadLocalized(ComponentAdapter<T> delegate)
          Construct a ThreadLocalized using Proxy instances.
ThreadLocalized(ComponentAdapter<T> delegate, ProxyFactory proxyFactory)
          Construct a ThreadLocalized.
 
Method Summary
 T getComponentInstance(PicoContainer pico, Type into)
          Retrieve the component instance.
 String getDescriptor()
          Get a string key descriptor of the component adapter.
 
Methods inherited from class org.picocontainer.behaviors.AbstractBehavior
accept, changeMonitor, componentHasLifecycle, currentMonitor, dispose, dispose, findAdapterOfType, getComponentImplementation, getComponentInstance, getComponentKey, getDelegate, hasLifecycle, start, start, stop, stop, toString, verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ThreadLocalized

public ThreadLocalized(ComponentAdapter<T> delegate,
                       ProxyFactory proxyFactory)
                throws PicoCompositionException
Construct a ThreadLocalized.

Parameters:
delegate - The ComponentAdapter to delegate.
proxyFactory - The ProxyFactory to use.
Throws:
PicoCompositionException - Thrown if the component does not implement any interface.

ThreadLocalized

public ThreadLocalized(ComponentAdapter<T> delegate)
                throws PicoCompositionException
Construct a ThreadLocalized using Proxy instances.

Parameters:
delegate - The ComponentAdapter to delegate.
Throws:
PicoCompositionException - Thrown if the component does not implement any interface.
Method Detail

getComponentInstance

public T getComponentInstance(PicoContainer pico,
                              Type into)
                       throws PicoCompositionException
Description copied from interface: ComponentAdapter
Retrieve the component instance. This method will usually create a new instance each time it is called, but that is not required. For example, Cached will always return the same instance.

Specified by:
getComponentInstance in interface ComponentAdapter<T>
Overrides:
getComponentInstance in class AbstractBehavior<T>
Parameters:
pico - the PicoContainer, that is used to resolve any possible dependencies of the instance.
into - the class that is about to be injected into. Use ComponentAdapter.NOTHING.class if this is not important to you.
Returns:
the component instance.
Throws:
PicoCompositionException - if the component has dependencies which could not be resolved, or instantiation of the component lead to an ambiguous situation within the container.

getDescriptor

public String getDescriptor()
Description copied from interface: ComponentAdapter
Get a string key descriptor of the component adapter.

Returns:


Copyright © 2003-2010 Codehaus. All Rights Reserved.