Package org.unitils.inject.util
Class InjectionUtils
- java.lang.Object
-
- 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
Constructors Constructor Description InjectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ObjectinjectInto(Object objectToInject, Object target, String property)Explicit injection of the objectToInject into the specified property of the target.static voidinjectIntoAnnotated(Object objectToInject, Object target, Class<? extends Annotation> annotation)static voidinjectIntoAnnotatedFields(Object objectToInject, Object target, Class<? extends Annotation> annotation)static voidinjectIntoAnnotatedMethods(Object objectToInject, Object target, Class<? extends Annotation> annotation)static ObjectinjectIntoByType(Object objectToInject, Type objectToInjectType, Object target, PropertyAccess propertyAccess)Performs auto-injection by type of the objectToInject on the target object.static ObjectinjectIntoStatic(Object objectToInject, Class<?> targetClass, String property)Explicit injection of the objectToInject into the specified static property of the target class.static ObjectinjectIntoStaticByType(Object objectToInject, Type objectToInjectType, Class<?> targetClass, PropertyAccess propertyAccess)Performs auto-injection by type of the objectToInject into the target class.
-
-
-
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 injectedtarget- The target objectproperty- 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 injectedtargetClass- The target class, not nullproperty- 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 injectedobjectToInjectType- 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 objecttarget- The object into which the objectToInject is injectedpropertyAccess- 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 injectedobjectToInjectType- 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 classtargetClass- The class into which the objectToInject is injectedpropertyAccess- 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)
-
-