org.picocontainer.defaults
Class InstantiatingComponentAdapter

java.lang.Object
  extended byorg.picocontainer.defaults.AbstractComponentAdapter
      extended byorg.picocontainer.defaults.InstantiatingComponentAdapter
All Implemented Interfaces:
ComponentAdapter, Serializable
Direct Known Subclasses:
ConstructorInjectionComponentAdapter, SetterInjectionComponentAdapter

public abstract class InstantiatingComponentAdapter
extends AbstractComponentAdapter

This ComponentAdapter will instantiate a new object for each call to ComponentAdapter.getComponentInstance(PicoContainer). That means that when used with a PicoContainer, getComponentInstance will return a new object each time.

Since:
1.0
Version:
$Revision: 1.36 $
Author:
Aslak Hellesøy, Paul Hammant, Jörg Schaible
See Also:
Serialized Form

Nested Class Summary
protected static class InstantiatingComponentAdapter.Guard
           
 
Field Summary
protected  boolean allowNonPublicClasses
          Flag indicating instanciation of non-public classes.
protected  Parameter[] parameters
          The parameters to use for initialization.
protected  InstantiatingComponentAdapter.Guard verifyingGuard
          The cycle guard for the verification.
 
Constructor Summary
protected InstantiatingComponentAdapter(Object componentKey, Class componentImplementation, Parameter[] parameters, boolean allowNonPublicClasses)
          Constructs a new ComponentAdapter for the given key and implementation.
 
Method Summary
 void accept(PicoVisitor visitor)
          Accepts a visitor for this ComponentAdapter.
protected  Parameter[] createDefaultParameters(Class[] parameters)
          Create default parameters for the given types.
protected abstract  Constructor getGreediestSatisfiableConstructor(PicoContainer container)
          Find and return the greediest satisfiable constructor.
protected  Object newInstance(Constructor constructor, Object[] parameters)
          Instantiate an object with given parameters and respect the accessible flag.
 void verify(PicoContainer container)
          Verify that all dependencies for this adapter can be satisifed.
 
Methods inherited from class org.picocontainer.defaults.AbstractComponentAdapter
checkTypeCompatibility, getComponentImplementation, getComponentKey, toString
 
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
 

Field Detail

verifyingGuard

protected transient InstantiatingComponentAdapter.Guard verifyingGuard
The cycle guard for the verification.


parameters

protected transient Parameter[] parameters
The parameters to use for initialization.


allowNonPublicClasses

protected boolean allowNonPublicClasses
Flag indicating instanciation of non-public classes.

Constructor Detail

InstantiatingComponentAdapter

protected InstantiatingComponentAdapter(Object componentKey,
                                        Class componentImplementation,
                                        Parameter[] parameters,
                                        boolean allowNonPublicClasses)
Constructs a new ComponentAdapter for the given key and implementation.

Parameters:
componentKey - the search key for this implementation
componentImplementation - the concrete implementation
parameters - the parameters to use for the initialization
allowNonPublicClasses - flag to allow instantiation of non-public classes.
Throws:
AssignabilityRegistrationException - if the key is a type and the implementation cannot be assigned to.
NotConcreteRegistrationException - if the implementation is not a concrete class.
Method Detail

createDefaultParameters

protected Parameter[] createDefaultParameters(Class[] parameters)
Create default parameters for the given types.

Parameters:
parameters - the parameter types
Returns:
the array with the default parameters.

verify

public void verify(PicoContainer container)
            throws PicoIntrospectionException
Description copied from interface: ComponentAdapter
Verify that all dependencies for this adapter can be satisifed. Normally, the adapter should verify this by checking that the associated PicoContainer contains all the needed dependnecies.

Parameters:
container - the PicoContainer, that is used to resolve any possible dependencies of the instance.
Throws:
PicoIntrospectionException - if one or more dependencies cannot be resolved.

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.

Specified by:
accept in interface ComponentAdapter
Overrides:
accept in class AbstractComponentAdapter

newInstance

protected Object newInstance(Constructor constructor,
                             Object[] parameters)
                      throws InstantiationException,
                             IllegalAccessException,
                             InvocationTargetException
Instantiate an object with given parameters and respect the accessible flag.

Parameters:
constructor - the constructor to use
parameters - the parameters for the constructor
Returns:
the new object.
Throws:
InstantiationException
IllegalAccessException
InvocationTargetException

getGreediestSatisfiableConstructor

protected abstract Constructor getGreediestSatisfiableConstructor(PicoContainer container)
                                                           throws PicoIntrospectionException,
                                                                  UnsatisfiableDependenciesException,
                                                                  AmbiguousComponentResolutionException,
                                                                  AssignabilityRegistrationException,
                                                                  NotConcreteRegistrationException
Find and return the greediest satisfiable constructor.

Parameters:
container - the PicoContainer to resolve dependencies.
Returns:
the found constructor.
Throws:
PicoIntrospectionException
UnsatisfiableDependenciesException
AmbiguousComponentResolutionException
AssignabilityRegistrationException
NotConcreteRegistrationException


Copyright © 2003-2004 Codehaus. All Rights Reserved.