org.unitils.inject.util
Class InjectionUtils

java.lang.Object
  extended by org.unitils.inject.util.InjectionUtils

public class InjectionUtils
extends Object

Class containing static methods that implement explicit injection using OGNL expressions, and auto-injection by type.

Author:
Filip Neven, Tim Ducheyne

Constructor Summary
InjectionUtils()
           
 
Method Summary
static Object injectInto(Object objectToInject, Object target, String property)
          Explicit injection of the objectToInject into the specified property of the target.
static void injectIntoAnnotated(Object objectToInject, Object target, Class<? extends Annotation> annotation)
           
static void injectIntoAnnotatedFields(Object objectToInject, Object target, Class<? extends Annotation> annotation)
           
static void injectIntoAnnotatedMethods(Object objectToInject, Object target, Class<? extends Annotation> annotation)
           
static Object injectIntoByType(Object objectToInject, Type objectToInjectType, Object target, PropertyAccess propertyAccess)
          Performs auto-injection by type of the objectToInject on the target object.
static Object injectIntoStatic(Object objectToInject, Class<?> targetClass, String property)
          Explicit injection of the objectToInject into the specified static property of the target class.
static Object injectIntoStaticByType(Object objectToInject, Type objectToInjectType, Class<?> targetClass, PropertyAccess propertyAccess)
          Performs auto-injection by type of the objectToInject into the target class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InjectionUtils

public InjectionUtils()
Method Detail

injectInto

public static Object injectInto(Object objectToInject,
                                Object target,
                                String property)
Explicit injection of the objectToInject into the specified property of the target. The property should be a correct OGNL expression.

Parameters:
objectToInject - The object that is injected
target - The target object
property - The OGNL expression that defines where the object will be injected, not null
Returns:
The object that was replaced by the injection

injectIntoStatic

public static Object injectIntoStatic(Object objectToInject,
                                      Class<?> targetClass,
                                      String property)
Explicit injection of the objectToInject into the specified static property of the target class. The property should be a correct OGNL expression.

Parameters:
objectToInject - The object that is injected
targetClass - The target class, not null
property - The OGNL expression that defines where the object will be injected, not null
Returns:
The object that was replaced by the injection

injectIntoByType

public static Object injectIntoByType(Object objectToInject,
                                      Type objectToInjectType,
                                      Object target,
                                      PropertyAccess propertyAccess)
Performs auto-injection by type of the objectToInject on the target object.

Parameters:
objectToInject - The object that is injected
objectToInjectType - The type of the object. This should be the type of the object or one of his super-types or implemented interfaces. This type is used for property type matching on the target object
target - The object into which the objectToInject is injected
propertyAccess - Defines if field or setter injection is used
Returns:
The object that was replaced by the injection

injectIntoStaticByType

public static Object injectIntoStaticByType(Object objectToInject,
                                            Type objectToInjectType,
                                            Class<?> targetClass,
                                            PropertyAccess propertyAccess)
Performs auto-injection by type of the objectToInject into the target class.

Parameters:
objectToInject - The object that is injected
objectToInjectType - The type of the object. This should be the type of the object or one of his super-types or implemented interfaces. This type is used for property type matching on the target class
targetClass - The class into which the objectToInject is injected
propertyAccess - Defines if field or setter injection is used
Returns:
The object that was replaced by the injection

injectIntoAnnotated

public static void injectIntoAnnotated(Object objectToInject,
                                       Object target,
                                       Class<? extends Annotation> annotation)

injectIntoAnnotatedMethods

public static void injectIntoAnnotatedMethods(Object objectToInject,
                                              Object target,
                                              Class<? extends Annotation> annotation)

injectIntoAnnotatedFields

public static void injectIntoAnnotatedFields(Object objectToInject,
                                             Object target,
                                             Class<? extends Annotation> annotation)


Copyright © 2011. All Rights Reserved.