org.picocontainer.gems.adapters
Class ThreadLocalComponentAdapter

java.lang.Object
  extended by org.picocontainer.defaults.DecoratingComponentAdapter
      extended by org.picocontainer.gems.adapters.ThreadLocalComponentAdapter
All Implemented Interfaces:
java.io.Serializable, org.picocontainer.ComponentAdapter, org.picocontainer.defaults.ComponentMonitorStrategy, org.picocontainer.defaults.LifecycleStrategy, org.picocontainer.LifecycleManager

public class ThreadLocalComponentAdapter
extends org.picocontainer.defaults.DecoratingComponentAdapter

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 ThreadLocalComponentAdapterFactory 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
private static class ThreadLocalComponentAdapter.ThreadLocalInvoker
           
 
Field Summary
private  java.lang.Class[] interfaces
           
private  com.thoughtworks.proxy.ProxyFactory proxyFactory
           
 
Constructor Summary
ThreadLocalComponentAdapter(org.picocontainer.ComponentAdapter delegate)
          Construct a ThreadLocalComponentAdapter using Proxy instances.
ThreadLocalComponentAdapter(org.picocontainer.ComponentAdapter delegate, com.thoughtworks.proxy.ProxyFactory proxyFactory)
          Construct a ThreadLocalComponentAdapter.
 
Method Summary
 java.lang.Object getComponentInstance(org.picocontainer.PicoContainer pico)
           
private  java.lang.Class[] getInterfaces()
           
 
Methods inherited from class org.picocontainer.defaults.DecoratingComponentAdapter
accept, changeMonitor, currentMonitor, dispose, dispose, getComponentImplementation, getComponentKey, getDelegate, hasLifecycle, hasLifecycle, start, start, stop, stop, toString, verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

interfaces

private transient java.lang.Class[] interfaces

proxyFactory

private com.thoughtworks.proxy.ProxyFactory proxyFactory
Constructor Detail

ThreadLocalComponentAdapter

public ThreadLocalComponentAdapter(org.picocontainer.ComponentAdapter delegate,
                                   com.thoughtworks.proxy.ProxyFactory proxyFactory)
                            throws org.picocontainer.PicoIntrospectionException
Construct a ThreadLocalComponentAdapter.

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

ThreadLocalComponentAdapter

public ThreadLocalComponentAdapter(org.picocontainer.ComponentAdapter delegate)
                            throws org.picocontainer.PicoIntrospectionException
Construct a ThreadLocalComponentAdapter using Proxy instances.

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

getComponentInstance

public java.lang.Object getComponentInstance(org.picocontainer.PicoContainer pico)
                                      throws org.picocontainer.PicoInitializationException,
                                             org.picocontainer.PicoIntrospectionException,
                                             org.picocontainer.defaults.AssignabilityRegistrationException,
                                             org.picocontainer.defaults.NotConcreteRegistrationException
Specified by:
getComponentInstance in interface org.picocontainer.ComponentAdapter
Overrides:
getComponentInstance in class org.picocontainer.defaults.DecoratingComponentAdapter
Throws:
org.picocontainer.PicoInitializationException
org.picocontainer.PicoIntrospectionException
org.picocontainer.defaults.AssignabilityRegistrationException
org.picocontainer.defaults.NotConcreteRegistrationException

getInterfaces

private final java.lang.Class[] getInterfaces()