org.picocontainer.defaults
Class AbstractComponentAdapter

java.lang.Object
  extended by org.picocontainer.defaults.MonitoringComponentAdapter
      extended by org.picocontainer.defaults.AbstractComponentAdapter
All Implemented Interfaces:
java.io.Serializable, ComponentAdapter, ComponentMonitorStrategy
Direct Known Subclasses:
InstanceComponentAdapter, InstantiatingComponentAdapter

public abstract class AbstractComponentAdapter
extends MonitoringComponentAdapter

Base class for a ComponentAdapter with general functionality. This implementation provides basic checks for a healthy implementation of a ComponentAdapter. It does not allow to use null for the component key or the implementation, ensures that the implementation is a concrete class and that the key is assignable from the implementation if the key represents a type.

Since:
1.0
Version:
$Revision: 2654 $
Author:
Paul Hammant, Aslak Hellesøy, Jon Tirsén
See Also:
Serialized Form

Field Summary
private  java.lang.Class componentImplementation
           
private  java.lang.Object componentKey
           
 
Constructor Summary
protected AbstractComponentAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation)
          Constructs a new ComponentAdapter for the given key and implementation.
protected AbstractComponentAdapter(java.lang.Object componentKey, java.lang.Class componentImplementation, ComponentMonitor monitor)
          Constructs a new ComponentAdapter for the given key and implementation.
 
Method Summary
 void accept(PicoVisitor visitor)
          Accepts a visitor for this ComponentAdapter.
protected  void checkTypeCompatibility()
           
 java.lang.Class getComponentImplementation()
          Retrieve the class of the component.
 java.lang.Object getComponentKey()
          Retrieve the key associated with the component.
 java.lang.String toString()
           
 
Methods inherited from class org.picocontainer.defaults.MonitoringComponentAdapter
changeMonitor, currentMonitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.picocontainer.ComponentAdapter
getComponentInstance, verify
 

Field Detail

componentKey

private java.lang.Object componentKey

componentImplementation

private java.lang.Class componentImplementation
Constructor Detail

AbstractComponentAdapter

protected AbstractComponentAdapter(java.lang.Object componentKey,
                                   java.lang.Class componentImplementation)
                            throws AssignabilityRegistrationException
Constructs a new ComponentAdapter for the given key and implementation.

Parameters:
componentKey - the search key for this implementation
componentImplementation - the concrete implementation
Throws:
AssignabilityRegistrationException - if the key is a type and the implementation cannot be assigned to.

AbstractComponentAdapter

protected AbstractComponentAdapter(java.lang.Object componentKey,
                                   java.lang.Class componentImplementation,
                                   ComponentMonitor monitor)
                            throws AssignabilityRegistrationException
Constructs a new ComponentAdapter for the given key and implementation.

Parameters:
componentKey - the search key for this implementation
componentImplementation - the concrete implementation
monitor - the component monitor used by this ComponentAdapter
Throws:
AssignabilityRegistrationException - if the key is a type and the implementation cannot be assigned to.
Method Detail

getComponentKey

public java.lang.Object getComponentKey()
Retrieve the key associated with the component.

Returns:
the component's key. Should either be a class type (normally an interface) or an identifier that is unique (within the scope of the current PicoContainer).
See Also:
ComponentAdapter.getComponentKey()

getComponentImplementation

public java.lang.Class getComponentImplementation()
Retrieve the class of the component.

Returns:
the component's implementation class. Should normally be a concrete class (ie, a class that can be instantiated).
See Also:
ComponentAdapter.getComponentImplementation()

checkTypeCompatibility

protected void checkTypeCompatibility()
                               throws AssignabilityRegistrationException
Throws:
AssignabilityRegistrationException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
Returns the ComponentAdapter's class name and the component's key.
See Also:
Object.toString()

accept

public void accept(PicoVisitor visitor)
Description copied from interface: ComponentAdapter
Accepts a visitor for this ComponentAdapter. The method is normally called by visiting a PicoContainer, that cascades the visitor also down to all its ComponentAdapter instances.

Parameters:
visitor - the visitor.