org.apache.commons.inject.impl
Class AbstractInjector

java.lang.Object
  extended by org.apache.commons.inject.impl.AbstractInjector
All Implemented Interfaces:
IInjector
Direct Known Subclasses:
DefaultInjector

public abstract class AbstractInjector
extends Object
implements IInjector

Abstract implementation of an injector.


Constructor Summary
AbstractInjector()
           
 
Method Summary
protected abstract
<T> IBinding<T>
getBinding(IKey<T> pKey)
           
<T> T
getInstance(Class<T> pType)
          Returns an instance of pType, if a matching binding is present.
<T> T
getInstance(Class<T> pType, String pName)
          Returns an instance of the given type, with the given name, if a matching binding is present.
<T> T
getInstance(IKey<T> pKey)
          Returns an instance of the binding that has been registered for the given key.
 void injectMembers(Object pInstance)
          Injects members into the given instance, as if it where created by the injector itself.
protected abstract
<T> IBinding<T>
requireBinding(IKey<T> pKey)
           
<T> T
requireInstance(Class<T> pType)
          Returns an instance of pType, if a matching binding is present.
<T> T
requireInstance(Class<T> pType, String pName)
          Returns an instance of the given type, with the given name, if a matching binding is present.
<T> T
requireInstance(IKey<T> pKey)
          Returns an instance of the binding that has been registered for the given key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractInjector

public AbstractInjector()
Method Detail

getBinding

protected abstract <T> IBinding<T> getBinding(IKey<T> pKey)

requireBinding

protected abstract <T> IBinding<T> requireBinding(IKey<T> pKey)

getInstance

public <T> T getInstance(Class<T> pType)
Description copied from interface: IInjector
Returns an instance of pType, if a matching binding is present. This is a shortcut for
   getInstance(pType, "")
 
or
   getInstance(pType, Key.NO_NAME)
 

Specified by:
getInstance in interface IInjector
Parameters:
pType - The requested type.
Returns:
The created instance, or null.
See Also:
IInjector.getInstance(Class, String), IInjector.getInstance(IKey), IInjector.requireInstance(Class)

getInstance

public <T> T getInstance(Class<T> pType,
                         String pName)
Description copied from interface: IInjector
Returns an instance of the given type, with the given name, if a matching binding is present. This is a shortcut for
   Key key = new Key(pType, pName);
   getInstance(key)
 
or
   Key key = new Key(pType, pName, Key.NO_ANNOTATIONS);
   getInstance(key)
 

Specified by:
getInstance in interface IInjector
Parameters:
pType - The requested type.
pName - The requested objects name.
Returns:
The created instance, or null.
See Also:
IInjector.getInstance(IKey), IInjector.requireInstance(Class, String)

getInstance

public <T> T getInstance(IKey<T> pKey)
Description copied from interface: IInjector
Returns an instance of the binding that has been registered for the given key.

Specified by:
getInstance in interface IInjector
Parameters:
pKey - A binding key, for which a binding has been registered.
Returns:
The created instance, or null.
See Also:
IInjector.getInstance(Class), IInjector.getInstance(Class, String), IInjector.requireInstance(IKey)

requireInstance

public <T> T requireInstance(Class<T> pType)
                  throws NoSuchBindingException
Description copied from interface: IInjector
Returns an instance of pType, if a matching binding is present. This is a shortcut for
   requireInstance(pType, "")
 
or
   requireInstance(pType, Key.NO_NAME)
 

Specified by:
requireInstance in interface IInjector
Parameters:
pType - The requested type.
Returns:
The created instance.
Throws:
NoSuchBindingException - No matching binding has been registered with the injector.
See Also:
IInjector.getInstance(Class, String), IInjector.getInstance(IKey), IInjector.requireInstance(Class)

requireInstance

public <T> T requireInstance(Class<T> pType,
                             String pName)
                  throws NoSuchBindingException
Description copied from interface: IInjector
Returns an instance of the given type, with the given name, if a matching binding is present. This is a shortcut for
   Key key = new Key(pType, pName);
   requireInstance(key)
 
or
   Key key = new Key(pType, pName, Key.NO_ANNOTATIONS);
  requireInstance(key)
 

Specified by:
requireInstance in interface IInjector
Parameters:
pType - The requested type.
pName - The requested objects name.
Returns:
The created instance.
Throws:
NoSuchBindingException - No matching binding has been registered with the injector.
See Also:
IInjector.getInstance(Class, String), IInjector.requireInstance(Class), IInjector.requireInstance(IKey)

requireInstance

public <T> T requireInstance(IKey<T> pKey)
                  throws NoSuchBindingException
Description copied from interface: IInjector
Returns an instance of the binding that has been registered for the given key.

Specified by:
requireInstance in interface IInjector
Parameters:
pKey - A binding key, for which a binding has been registered.
Returns:
The created instance.
Throws:
NoSuchBindingException - No matching binding has been registered with the injector.
See Also:
IInjector.getInstance(IKey), IInjector.requireInstance(Class), IInjector.requireInstance(Class, String)

injectMembers

public void injectMembers(Object pInstance)
Description copied from interface: IInjector
Injects members into the given instance, as if it where created by the injector itself. In other words, fills fields and invokes methods annotated with @Inject, assuming that a binding is present for those fields, and method parameters.

Specified by:
injectMembers in interface IInjector


Copyright © 2014 The Apache Software Foundation. All Rights Reserved.