org.picocontainer.gems.behaviors
Class Assimilated<T>

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

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

ComponentAdapter that assimilates a component for a specific type.

Allows the instance of another ComponentAdapter to be converted into interface type, that the instance is not assignable from. In other words the instance of the delegated adapter does NOT necessarily implement the type interface.

For Example:

 public interface Foo {
     int size();
 }
        
 public class Bar {
     public int size() {
         return 1;
     }
 }
        
 new Assimilated(Foo.class, new InstanceAdapter(new Bar()));
 

Notice how Bar does not implement the interface Foo. But Bar does have an identical size() method.

Author:
Jörg Schaible, Michael Ward
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
Assimilated(Class<T> type, ComponentAdapter delegate)
          Construct an Assimilated.
Assimilated(Class<T> type, ComponentAdapter delegate, ProxyFactory proxyFactory)
          Construct an Assimilated.
 
Method Summary
 Class<T> getComponentImplementation()
          Return the type of the component.
 T getComponentInstance(PicoContainer container, Type into)
          Create and return a component instance.
 Object getComponentKey()
          Return the key of the component.
 String getDescriptor()
           
 
Methods inherited from class org.picocontainer.behaviors.AbstractBehavior
accept, changeMonitor, componentHasLifecycle, currentMonitor, dispose, dispose, findAdapterOfType, getComponentInstance, 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

Assimilated

public Assimilated(Class<T> type,
                   ComponentAdapter delegate,
                   ProxyFactory proxyFactory)
            throws PicoCompositionException
Construct an Assimilated. The type may not implement the type of the component instance. If the component instance does implement the interface, no proxy is used though.

Parameters:
type - The class type used as key.
delegate - The delegated ComponentAdapter.
proxyFactory - The ProxyFactory to use.
Throws:
PicoCompositionException - Thrown if the type is not compatible and cannot be proxied.

Assimilated

public Assimilated(Class<T> type,
                   ComponentAdapter delegate)
Construct an Assimilated. The type may not implement the type of the component instance. The implementation will use JDK Proxy instances. If the component instant does implement the interface, no proxy is used anyway.

Parameters:
type - The class type used as key.
delegate - The delegated ComponentAdapter.
Method Detail

getComponentInstance

public T getComponentInstance(PicoContainer container,
                              Type into)
                       throws PicoCompositionException
Create and return a component instance. If the component instance and the type to assimilate is not compatible, a proxy for the instance is generated, that implements the assimilated type.

Specified by:
getComponentInstance in interface ComponentAdapter<T>
Overrides:
getComponentInstance in class AbstractBehavior<T>
Throws:
PicoCompositionException
See Also:
AbstractBehavior#getComponentInstance(org.picocontainer.PicoContainer, java.lang.Class into)

getDescriptor

public String getDescriptor()

getComponentImplementation

public Class<T> getComponentImplementation()
Return the type of the component. If the component type is not compatible with the type to assimilate, the assimilated type is returned.

Specified by:
getComponentImplementation in interface ComponentAdapter<T>
Overrides:
getComponentImplementation in class AbstractBehavior<T>
See Also:
AbstractBehavior.getComponentImplementation()

getComponentKey

public Object getComponentKey()
Return the key of the component. If the key of the delegated component is a type, that is not compatible with the type to assimilate, then the assimilated type replaces the original type.

Specified by:
getComponentKey in interface ComponentAdapter<T>
Overrides:
getComponentKey in class AbstractBehavior<T>
See Also:
AbstractBehavior.getComponentKey()


Copyright © 2003-2010 Codehaus. All Rights Reserved.