net.israfil.micro.container
Class DefaultAutoWiringAdaptableContainer

java.lang.Object
  extended by net.israfil.micro.container.AbstractContainer
      extended by net.israfil.micro.container.DefaultAutoWiringAdaptableContainer
All Implemented Interfaces:
AutoWiringAdaptableContainer, Container

public class DefaultAutoWiringAdaptableContainer
extends AbstractContainer
implements AutoWiringAdaptableContainer

A default implementation of AutoWiringAdaptableContainer, a Container that uses an AutoWiringAdapter to ensure that components can be created appropriately with their dependencies satisfied automatically. This adapter is intended for constructor injection, but relies on the adapter to perform such. No reflection is used by this class itself.


Constructor Summary
DefaultAutoWiringAdaptableContainer()
          A default constructor that will throw errors regarding circular dependencies at registration time, throw missing dependency errors at wire-up (getComponent()) time, and has no parent.
DefaultAutoWiringAdaptableContainer(boolean failEarly)
          Construct this container such that it detects missing dependencies upon invocation of start().
DefaultAutoWiringAdaptableContainer(Container parent)
          This method constructs a DefaultAutoWiringAdaptableContainer that has a parent container for backup resolution.
DefaultAutoWiringAdaptableContainer(Container parent, boolean failEarly)
          Construct this container such that it detects missing dependencies upon invocation of start().
 
Method Summary
 java.lang.Object getComponent(java.lang.Object key)
          Returns the component named by the key if it is available, or null if no such component is available.
 void registerType(java.lang.Object key, AutoWiringAdapter componentAdapter)
          Register a component.
 void registerType(java.lang.Object key, java.lang.Class componentType)
          Register an independent component.
 void start()
          Begin the lifecycle of the container, after which components should be accessible.
 
Methods inherited from class net.israfil.micro.container.AbstractContainer
getParent, getStoredComponent, hasComponent, isRunning, isStored, store
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.israfil.micro.container.Container
hasComponent, isRunning
 

Constructor Detail

DefaultAutoWiringAdaptableContainer

public DefaultAutoWiringAdaptableContainer()
A default constructor that will throw errors regarding circular dependencies at registration time, throw missing dependency errors at wire-up (getComponent()) time, and has no parent.

Parameters:
failEarly - A boolean to indicate that this container should detect missing or circular dependencies at start() time.

DefaultAutoWiringAdaptableContainer

public DefaultAutoWiringAdaptableContainer(boolean failEarly)
Construct this container such that it detects missing dependencies upon invocation of start(). Otherwise, it will fail at wire time, rather than at registration time. Circular references will give errors at registration time.

Parameters:
failEarly - A boolean to indicate that this container should detect missing or circular dependencies at start() time.

DefaultAutoWiringAdaptableContainer

public DefaultAutoWiringAdaptableContainer(Container parent)
This method constructs a DefaultAutoWiringAdaptableContainer that has a parent container for backup resolution. The parent container can be of any type of Container.

Parameters:
parent - The parent container (optional)

DefaultAutoWiringAdaptableContainer

public DefaultAutoWiringAdaptableContainer(Container parent,
                                           boolean failEarly)
Construct this container such that it detects missing dependencies upon invocation of start(). Otherwise, it will fail at wire time, rather than at registration time. Circular references will give errors at registration time. This method also provides for a parent container. The parent container can be of any type of Container.

Parameters:
failEarly - A boolean to indicate that this container should detect missing or circular dependencies at start() time.
parent - The parent Container (optional)
Method Detail

start

public void start()
Description copied from interface: Container
Begin the lifecycle of the container, after which components should be accessible. Implementors should stop any component registration as of the start() call. Subsequent start() calls should be ignored.

Specified by:
start in interface AutoWiringAdaptableContainer
Specified by:
start in interface Container
Overrides:
start in class AbstractContainer

registerType

public void registerType(java.lang.Object key,
                         java.lang.Class componentType)
Description copied from interface: AutoWiringAdaptableContainer
Register an independent component. This is a convenience registry method for those components without dependencies, and which have a default constructor. Only classes which fit these criteria should be used in this method.

Specified by:
registerType in interface AutoWiringAdaptableContainer

registerType

public void registerType(java.lang.Object key,
                         AutoWiringAdapter componentAdapter)
Description copied from interface: AutoWiringAdaptableContainer
Register a component. The component's class must satisfy the test Injectable.class.isAssignableFrom(type); to ensure that the provided component implements the lifecycle mechanisms necessary to auto-wire.

Specified by:
registerType in interface AutoWiringAdaptableContainer

getComponent

public java.lang.Object getComponent(java.lang.Object key)
Description copied from interface: Container
Returns the component named by the key if it is available, or null if no such component is available. It throws a ContainerNotStarted runtime exception if this method is used before the container is started. This method must be implemented by implementors of Container in a thread-safe and reentrant way.

Specified by:
getComponent in interface Container


Copyright © 2008. All Rights Reserved.