Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.picocontainer.injectors
Class AbstractInjector<T>

    java.lang.Object
      org.picocontainer.adapters.AbstractAdapter<T>
          org.picocontainer.injectors.AbstractInjector<T>

All Implemented Interfaces:
  Serializable, ComponentAdapter<T>, ComponentMonitorStrategy, Injector<T>, LifecycleStrategy

Direct Known Subclasses:
  CompositeInjector, IterativeInjector, SingleMemberInjector

    public abstract class AbstractInjector<T>

extends AbstractAdapter<T>
implements LifecycleStrategy, Injector<T>

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

Author:
  Aslak Hellesøy, Paul Hammant, Jörg Schaible, Mauro Talevi
See Also:
  Serialized Form

Nested Class Summary
`static class` | `AbstractInjector.AmbiguousComponentResolutionException` Exception that is thrown as part of the introspection.
`static class` | `AbstractInjector.CyclicDependencyException`
`static class` | `AbstractInjector.NotConcreteRegistrationException`
`static class` | `AbstractInjector.UnsatisfiableDependenciesException` Exception thrown when some of the component's dependencies are not satisfiable.

Nested classes/interfaces inherited from interface org.picocontainer.ComponentAdapter
`ComponentAdapter.NOTHING`

Field Summary
`protected LifecycleStrategy` | `lifecycleStrategy` The strategy used to control the lifecycle
`protected Parameter[]` | `parameters` The parameters to use for initialization.
`protected org.picocontainer.injectors.AbstractInjector.ThreadLocalCyclicDependencyGuard` | `verifyingGuard` The cycle guard for the verification.

Constructor Summary
`protected` | `AbstractInjector(Object componentKey, Class<?> componentImplementation, Parameter[] parameters, ComponentMonitor monitor, LifecycleStrategy lifecycleStrategy, boolean useNames)` Constructs a new ComponentAdapter for the given key and implementation.

Method Summary
`void` | `accept(PicoVisitor visitor)` Accepts a visitor for this ComponentAdapter.
`protected Type` | `box(Type parameterType)`
`protected T` | `caughtIllegalAccessException(ComponentMonitor componentMonitor, Constructor<T> constructor, IllegalAccessException e, PicoContainer container)` inform monitor about access exception.
`protected Object` | `caughtIllegalAccessException(ComponentMonitor componentMonitor, Member member, Object componentInstance, IllegalAccessException e)`
`protected T` | `caughtInstantiationException(ComponentMonitor componentMonitor, Constructor<T> constructor, InstantiationException e, PicoContainer container)` inform monitor about component instantiation failure
`protected T` | `caughtInvocationTargetException(ComponentMonitor componentMonitor, Member member, Object componentInstance, InvocationTargetException e)` inform monitor about exception while instantiating component
`protected Parameter[]` | `createDefaultParameters(Type[] parameters)` Create default parameters for the given types.
`Object` | `decorateComponentInstance(PicoContainer container, Type into, T instance)` A preexiting component instance can be injected into after instantiation
`void` | `dispose(Object component)` Invoke the "dispose" method on the component instance if this is disposable.
`T` | `getComponentInstance(PicoContainer container)` Retrieve the component instance.
`abstract T` | `getComponentInstance(PicoContainer container, Type into)` Retrieve the component instance.
`String` | `getDescriptor()` Get a string key descriptor of the component adapter.
`boolean` | `hasLifecycle(Class<?> type)` Test if a component instance has a lifecycle.
`protected T` | `newInstance(Constructor<T> constructor, Object[] parameters)` Instantiate an object with given parameters and respect the accessible flag.
`void` | `start(Object component)` Invoke the "start" method on the component instance if this is startable.
`void` | `stop(Object component)` Invoke the "stop" method on the component instance if this is stoppable.
`boolean` | `useNames()`
`void` | `verify(PicoContainer container)` Verify that all dependencies for this adapter can be satisfied.

Methods inherited from class org.picocontainer.adapters.AbstractAdapter
`changeMonitor, checkTypeCompatibility, currentMonitor, findAdapterOfType, getComponentImplementation, getComponentKey, getDelegate, 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
`findAdapterOfType, getComponentImplementation, getComponentKey, getDelegate`

Field Detail

### verifyingGuard

    protected transient org.picocontainer.injectors.AbstractInjector.ThreadLocalCyclicDependencyGuard verifyingGuard

  The cycle guard for the verification.

### parameters

    protected transient Parameter[] parameters

  The parameters to use for initialization.

### lifecycleStrategy

    protected LifecycleStrategy lifecycleStrategy

  The strategy used to control the lifecycle

Constructor Detail

### AbstractInjector

    protected AbstractInjector(Object componentKey,
                               Class<?> componentImplementation,
                               Parameter[] parameters,
                               ComponentMonitor monitor,
                               LifecycleStrategy lifecycleStrategy,
                               boolean useNames)

  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
    `monitor` - the component monitor used by this ComponentAdapter
    `lifecycleStrategy` - the lifecycle strategy used by this ComponentAdapter
  Throws:
    `AbstractInjector.NotConcreteRegistrationException` - if the implementation is not a concrete class
    `NullPointerException` - if one of the parameters is `null`

Method Detail

### useNames

    public boolean useNames()

### createDefaultParameters

    protected Parameter[] createDefaultParameters(Type[] 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 PicoCompositionException

  Description copied from interface: `ComponentAdapter`
  Verify that all dependencies for this adapter can be satisfied. Normally, the adapter should verify this by checking that the associated PicoContainer contains all the needed dependencies.

  Specified by:
    `verify` in interface `ComponentAdapter<T>`
  Parameters:
    `container` - the `PicoContainer`, that is used to resolve any possible dependencies of the instance.
  Throws:
    `PicoCompositionException` - if one or more dependencies cannot be resolved.

### getComponentInstance

    public T getComponentInstance(PicoContainer container)
                           throws PicoCompositionException

  Description copied from interface: `ComponentAdapter`
  Retrieve the component instance. This method will usually create a new instance each time it is called, but that is not required. For example, `Cached` will always return the same instance.

  Specified by:
    `getComponentInstance` in interface `ComponentAdapter<T>`
  Overrides:
    `getComponentInstance` in class `AbstractAdapter<T>`
  Parameters:
    `container` - the `PicoContainer`, that is used to resolve any possible dependencies of the instance.
  Returns:
    the component instance.
  Throws:
    `PicoCompositionException` - if the component has dependencies which could not be resolved, or instantiation of the component lead to an ambigous situation within the container.

### getComponentInstance

    public abstract T getComponentInstance(PicoContainer container,
                                           Type into)
                                    throws PicoCompositionException

  Description copied from interface: `ComponentAdapter`
  Retrieve the component instance. This method will usually create a new instance each time it is called, but that is not required. For example, `Cached` will always return the same instance.

  Specified by:
    `getComponentInstance` in interface `ComponentAdapter<T>`
  Parameters:
    `container` - the `PicoContainer`, that is used to resolve any possible dependencies of the instance.
    `into` - the class that is about to be injected into. Use ComponentAdapter.NOTHING.class if this is not important to you.
  Returns:
    the component instance.
  Throws:
    `PicoCompositionException` - if the component has dependencies which could not be resolved, or instantiation of the component lead to an ambiguous situation within the container.

### decorateComponentInstance

    public Object decorateComponentInstance(PicoContainer container,
                                            Type into,
                                            T instance)

  Description copied from interface: `Injector`
  A preexiting component instance can be injected into after instantiation

  Specified by:
    `decorateComponentInstance` in interface `Injector<T>`
  Parameters:
    `container` - the container that can provide injectable dependencies
    `instance` - the instance to
  Returns:

### 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<T>`
  Overrides:
    `accept` in class `AbstractAdapter<T>`
  Parameters:
    `visitor` - the visitor.

### start

    public void start(Object component)

  Description copied from interface: `LifecycleStrategy`
  Invoke the "start" method on the component instance if this is startable. It is up to the implementation of the strategy what "start" and "startable" means.

  Specified by:
    `start` in interface `LifecycleStrategy`
  Parameters:
    `component` - the instance of the component to start

### stop

    public void stop(Object component)

  Description copied from interface: `LifecycleStrategy`
  Invoke the "stop" method on the component instance if this is stoppable. It is up to the implementation of the strategy what "stop" and "stoppable" means.

  Specified by:
    `stop` in interface `LifecycleStrategy`
  Parameters:
    `component` - the instance of the component to stop

### dispose

    public void dispose(Object component)

  Description copied from interface: `LifecycleStrategy`
  Invoke the "dispose" method on the component instance if this is disposable. It is up to the implementation of the strategy what "dispose" and "disposable" means.

  Specified by:
    `dispose` in interface `LifecycleStrategy`
  Parameters:
    `component` - the instance of the component to dispose

### hasLifecycle

    public boolean hasLifecycle(Class<?> type)

  Description copied from interface: `LifecycleStrategy`
  Test if a component instance has a lifecycle.

  Specified by:
    `hasLifecycle` in interface `LifecycleStrategy`
  Parameters:
    `type` - the component's type
  Returns:
    `true` if the component has a lifecycle

### getDescriptor

    public String getDescriptor()

  Description copied from interface: `ComponentAdapter`
  Get a string key descriptor of the component adapter.

  Specified by:
    `getDescriptor` in interface `ComponentAdapter<T>`
  Returns:

### newInstance

    protected T newInstance(Constructor<T> 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`

### caughtInstantiationException

    protected T caughtInstantiationException(ComponentMonitor componentMonitor,
                                             Constructor<T> constructor,
                                             InstantiationException e,
                                             PicoContainer container)

  inform monitor about component instantiation failure

  Parameters:
    `componentMonitor` -
    `constructor` -
    `e` -
    `container` -
  Returns:

### caughtIllegalAccessException

    protected T caughtIllegalAccessException(ComponentMonitor componentMonitor,
                                             Constructor<T> constructor,
                                             IllegalAccessException e,
                                             PicoContainer container)

  inform monitor about access exception.

  Parameters:
    `componentMonitor` -
    `constructor` -
    `e` -
    `container` -
  Returns:

### caughtInvocationTargetException

    protected T caughtInvocationTargetException(ComponentMonitor componentMonitor,
                                                Member member,
                                                Object componentInstance,
                                                InvocationTargetException e)

  inform monitor about exception while instantiating component

  Parameters:
    `componentMonitor` -
    `member` -
    `componentInstance` -
    `e` -
  Returns:

### caughtIllegalAccessException

    protected Object caughtIllegalAccessException(ComponentMonitor componentMonitor,
                                                  Member member,
                                                  Object componentInstance,
                                                  IllegalAccessException e)

### box

    protected Type box(Type parameterType)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2009 Codehaus. All Rights Reserved.