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>, ComponentLifecycle<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)
           
 String getDescriptor()
           
 
Methods inherited from class org.picocontainer.behaviors.AbstractBehavior
accept, changeMonitor, componentHasLifecycle, currentMonitor, dispose, dispose, findAdapterOfType, getComponentImplementation, getComponentInstance, getComponentKey, getDelegate, hasLifecycle, isLazy, isStarted, 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
Specified by:
getComponentInstance in interface ComponentAdapter<T>
Overrides:
getComponentInstance in class AbstractBehavior<T>
Throws:
PicoCompositionException

getDescriptor

public String getDescriptor()


Copyright © 2003-2010 Codehaus. All Rights Reserved.