com.opensymphony.xwork2.inject
Class ContainerImpl

java.lang.Object
  extended by com.opensymphony.xwork2.inject.ContainerImpl
All Implemented Interfaces:
Container, Serializable

 class ContainerImpl
extends Object
implements Container

Default Container implementation.

Author:
crazybob@google.com (Bob Lee)
See Also:
ContainerBuilder

Nested Class Summary
(package private) static class ContainerImpl.ConstructorInjector<T>
           
(package private) static interface ContainerImpl.ContextualCallable<T>
           
(package private) static class ContainerImpl.FieldInjector
           
(package private) static interface ContainerImpl.Injector
          Injects a field or method in a given object.
(package private) static interface ContainerImpl.InjectorFactory<M extends Member & AnnotatedElement>
           
(package private) static class ContainerImpl.MethodInjector
           
(package private) static class ContainerImpl.MissingDependencyException
           
(package private) static class ContainerImpl.ParameterInjector<T>
           
 
Field Summary
(package private)  Map<Class<?>,ContainerImpl.ConstructorInjector> constructors
           
(package private)  Map<Key<?>,InternalFactory<?>> factories
           
(package private)  Map<Class<?>,Set<String>> factoryNamesByType
           
(package private)  Map<Class<?>,List<ContainerImpl.Injector>> injectors
          Field and method injectors.
(package private)  ThreadLocal<Object[]> localContext
           
(package private)  ThreadLocal<Object> localScopeStrategy
           
 
Fields inherited from interface com.opensymphony.xwork2.inject.Container
DEFAULT_NAME
 
Constructor Summary
ContainerImpl(Map<Key<?>,InternalFactory<?>> factories)
           
 
Method Summary
(package private)  void addInjectors(Class clazz, List<ContainerImpl.Injector> injectors)
          Recursively adds injectors for fields and methods from the given class to the given list.
(package private)  void addInjectorsForFields(Field[] fields, boolean statics, List<ContainerImpl.Injector> injectors)
           
(package private)
<M extends Member & AnnotatedElement>
void
addInjectorsForMembers(List<M> members, boolean statics, List<ContainerImpl.Injector> injectors, ContainerImpl.InjectorFactory<M> injectorFactory)
           
(package private)  void addInjectorsForMethods(Method[] methods, boolean statics, List<ContainerImpl.Injector> injectors)
           
(package private)
<T> T
callInContext(ContainerImpl.ContextualCallable<T> callable)
          Looks up thread local context.
(package private)
<T> ContainerImpl.ParameterInjector<T>
createParameterInjector(Key<T> key, Member member)
           
(package private)  Inject findInject(Annotation[] annotations)
          Finds the Inject annotation in an array of annotations.
(package private)
<T> ContainerImpl.ConstructorInjector<T>
getConstructor(Class<T> implementation)
          Gets a constructor function for a given implementation class.
(package private)
<T> InternalFactory<? extends T>
getFactory(Key<T> key)
           
<T> T
getInstance(Class<T> type)
          Convenience method.
(package private)
<T> T
getInstance(Class<T> type, InternalContext context)
           
<T> T
getInstance(Class<T> type, String name)
          Gets an instance of the given dependency which was declared in ContainerBuilder.
(package private)
<T> T
getInstance(Class<T> type, String name, InternalContext context)
           
 Set<String> getInstanceNames(Class<?> type)
          Gets a set of all registered names for the given type
private static Object[] getParameters(Member member, InternalContext context, ContainerImpl.ParameterInjector[] parameterInjectors)
           
(package private)
<M extends AccessibleObject & Member>
ContainerImpl.ParameterInjector<?>[]
getParametersInjectors(M member, Annotation[][] annotations, Class[] parameterTypes, String defaultName)
          Gets parameter injectors.
<T> T
inject(Class<T> implementation)
          Creates and injects a new instance of type implementation.
(package private)
<T> T
inject(Class<T> implementation, InternalContext context)
           
 void inject(Object o)
          Injects dependencies into the fields and methods of an existing object.
(package private)  void inject(Object o, InternalContext context)
           
(package private)  void injectStatics(List<Class<?>> staticInjections)
           
private  boolean isStatic(Member member)
           
 void removeScopeStrategy()
          Removes the scope strategy for the current thread.
 void setScopeStrategy(Scope.Strategy scopeStrategy)
          Sets the scope strategy for the current thread.
private  ContainerImpl.ParameterInjector<?>[] toArray(List<ContainerImpl.ParameterInjector<?>> parameterInjections)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factories

final Map<Key<?>,InternalFactory<?>> factories

factoryNamesByType

final Map<Class<?>,Set<String>> factoryNamesByType

injectors

final Map<Class<?>,List<ContainerImpl.Injector>> injectors
Field and method injectors.


constructors

Map<Class<?>,ContainerImpl.ConstructorInjector> constructors

localContext

ThreadLocal<Object[]> localContext

localScopeStrategy

final ThreadLocal<Object> localScopeStrategy
Constructor Detail

ContainerImpl

ContainerImpl(Map<Key<?>,InternalFactory<?>> factories)
Method Detail

getFactory

<T> InternalFactory<? extends T> getFactory(Key<T> key)

addInjectors

void addInjectors(Class clazz,
                  List<ContainerImpl.Injector> injectors)
Recursively adds injectors for fields and methods from the given class to the given list. Injects parent classes before sub classes.


injectStatics

void injectStatics(List<Class<?>> staticInjections)

addInjectorsForMethods

void addInjectorsForMethods(Method[] methods,
                            boolean statics,
                            List<ContainerImpl.Injector> injectors)

addInjectorsForFields

void addInjectorsForFields(Field[] fields,
                           boolean statics,
                           List<ContainerImpl.Injector> injectors)

addInjectorsForMembers

<M extends Member & AnnotatedElement> void addInjectorsForMembers(List<M> members,
                                                                 boolean statics,
                                                                 List<ContainerImpl.Injector> injectors,
                                                                 ContainerImpl.InjectorFactory<M> injectorFactory)

isStatic

private boolean isStatic(Member member)

getParametersInjectors

<M extends AccessibleObject & Member> ContainerImpl.ParameterInjector<?>[] getParametersInjectors(M member,
                                                                                                 Annotation[][] annotations,
                                                                                                 Class[] parameterTypes,
                                                                                                 String defaultName)
                                                      throws ContainerImpl.MissingDependencyException
Gets parameter injectors.

Parameters:
member - to which the parameters belong
annotations - on the parameters
parameterTypes - parameter types
Returns:
injections
Throws:
ContainerImpl.MissingDependencyException

createParameterInjector

<T> ContainerImpl.ParameterInjector<T> createParameterInjector(Key<T> key,
                                                               Member member)
                                                     throws ContainerImpl.MissingDependencyException
Throws:
ContainerImpl.MissingDependencyException

toArray

private ContainerImpl.ParameterInjector<?>[] toArray(List<ContainerImpl.ParameterInjector<?>> parameterInjections)

findInject

Inject findInject(Annotation[] annotations)
Finds the Inject annotation in an array of annotations.


getParameters

private static Object[] getParameters(Member member,
                                      InternalContext context,
                                      ContainerImpl.ParameterInjector[] parameterInjectors)

inject

void inject(Object o,
            InternalContext context)

inject

<T> T inject(Class<T> implementation,
             InternalContext context)

getInstance

<T> T getInstance(Class<T> type,
                  String name,
                  InternalContext context)

getInstance

<T> T getInstance(Class<T> type,
                  InternalContext context)

inject

public void inject(Object o)
Description copied from interface: Container
Injects dependencies into the fields and methods of an existing object.

Specified by:
inject in interface Container

inject

public <T> T inject(Class<T> implementation)
Description copied from interface: Container
Creates and injects a new instance of type implementation.

Specified by:
inject in interface Container

getInstance

public <T> T getInstance(Class<T> type,
                         String name)
Description copied from interface: Container
Gets an instance of the given dependency which was declared in ContainerBuilder.

Specified by:
getInstance in interface Container

getInstance

public <T> T getInstance(Class<T> type)
Description copied from interface: Container
Convenience method. Equivalent to getInstance(type, DEFAULT_NAME).

Specified by:
getInstance in interface Container

getInstanceNames

public Set<String> getInstanceNames(Class<?> type)
Description copied from interface: Container
Gets a set of all registered names for the given type

Specified by:
getInstanceNames in interface Container
Parameters:
type - The instance type
Returns:
A set of registered names

callInContext

<T> T callInContext(ContainerImpl.ContextualCallable<T> callable)
Looks up thread local context. Creates (and removes) a new context if necessary.


getConstructor

<T> ContainerImpl.ConstructorInjector<T> getConstructor(Class<T> implementation)
Gets a constructor function for a given implementation class.


setScopeStrategy

public void setScopeStrategy(Scope.Strategy scopeStrategy)
Description copied from interface: Container
Sets the scope strategy for the current thread.

Specified by:
setScopeStrategy in interface Container

removeScopeStrategy

public void removeScopeStrategy()
Description copied from interface: Container
Removes the scope strategy for the current thread.

Specified by:
removeScopeStrategy in interface Container


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.