org.picocontainer.gems.adapters
Class AssimilatingComponentAdapter

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

public class AssimilatingComponentAdapter
extends org.picocontainer.defaults.DecoratingComponentAdapter

ComponentAdapter, that assimilates a component for a specific type.

Allows the instance of another ComponentAdapter to be converted into interfacte 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 AssimilatingComponentAdapter(Foo.class, new InstanceComponentAdapter(new Bar()));
 

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

Since:
1.2
Author:
Jörg Schaible, Michael Ward
See Also:
Serialized Form

Field Summary
private  boolean isCompatible
           
private  com.thoughtworks.proxy.ProxyFactory proxyFactory
           
private  java.lang.Class type
           
 
Constructor Summary
AssimilatingComponentAdapter(java.lang.Class type, org.picocontainer.ComponentAdapter delegate)
          Construct an AssimilatingComponentAdapter.
AssimilatingComponentAdapter(java.lang.Class type, org.picocontainer.ComponentAdapter delegate, com.thoughtworks.proxy.ProxyFactory proxyFactory)
          Construct an AssimilatingComponentAdapter.
 
Method Summary
 java.lang.Class getComponentImplementation()
          Return the type of the component.
 java.lang.Object getComponentInstance(org.picocontainer.PicoContainer container)
          Create and return a component instance.
 java.lang.Object getComponentKey()
          Return the key of the component.
 
Methods inherited from class org.picocontainer.defaults.DecoratingComponentAdapter
accept, changeMonitor, currentMonitor, dispose, dispose, 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

type

private java.lang.Class type

proxyFactory

private com.thoughtworks.proxy.ProxyFactory proxyFactory

isCompatible

private boolean isCompatible
Constructor Detail

AssimilatingComponentAdapter

public AssimilatingComponentAdapter(java.lang.Class type,
                                    org.picocontainer.ComponentAdapter delegate,
                                    com.thoughtworks.proxy.ProxyFactory proxyFactory)
                             throws org.picocontainer.PicoIntrospectionException
Construct an AssimilatingComponentAdapter. 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:
org.picocontainer.PicoIntrospectionException - Thrown if the type is not compatible and cannot be proxied.

AssimilatingComponentAdapter

public AssimilatingComponentAdapter(java.lang.Class type,
                                    org.picocontainer.ComponentAdapter delegate)
Construct an AssimilatingComponentAdapter. 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 java.lang.Object getComponentInstance(org.picocontainer.PicoContainer container)
                                      throws org.picocontainer.PicoInitializationException,
                                             org.picocontainer.PicoIntrospectionException
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 org.picocontainer.ComponentAdapter
Overrides:
getComponentInstance in class org.picocontainer.defaults.DecoratingComponentAdapter
Throws:
org.picocontainer.PicoInitializationException
org.picocontainer.PicoIntrospectionException
See Also:
DecoratingComponentAdapter.getComponentInstance(org.picocontainer.PicoContainer)

getComponentImplementation

public java.lang.Class 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 org.picocontainer.ComponentAdapter
Overrides:
getComponentImplementation in class org.picocontainer.defaults.DecoratingComponentAdapter
See Also:
DecoratingComponentAdapter.getComponentImplementation()

getComponentKey

public java.lang.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 org.picocontainer.ComponentAdapter
Overrides:
getComponentKey in class org.picocontainer.defaults.DecoratingComponentAdapter
See Also:
DecoratingComponentAdapter.getComponentKey()