org.picocontainer.gems.adapters
Class AssimilatingComponentAdapter

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

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

Constructor Summary
AssimilatingComponentAdapter(Class type, org.picocontainer.ComponentAdapter delegate)
          Construct an AssimilatingComponentAdapter.
AssimilatingComponentAdapter(Class type, org.picocontainer.ComponentAdapter delegate, ProxyFactory proxyFactory)
          Construct an AssimilatingComponentAdapter.
 
Method Summary
 Class getComponentImplementation()
          Return the type of the component.
 Object getComponentInstance(org.picocontainer.PicoContainer container)
          Create and return a component instance.
 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
 

Constructor Detail

AssimilatingComponentAdapter

public AssimilatingComponentAdapter(Class type,
                                    org.picocontainer.ComponentAdapter delegate,
                                    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(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 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.

Throws:
org.picocontainer.PicoInitializationException
org.picocontainer.PicoIntrospectionException
See Also:
DecoratingComponentAdapter.getComponentInstance(org.picocontainer.PicoContainer)

getComponentImplementation

public 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.

See Also:
DecoratingComponentAdapter.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.

See Also:
DecoratingComponentAdapter.getComponentKey()


Copyright © 2003-2007 Codehaus. All Rights Reserved.