org.mentabean.util
Class InjectionUtils

java.lang.Object
  extended by org.mentabean.util.InjectionUtils

public class InjectionUtils
extends Object


Nested Class Summary
static interface InjectionUtils.Provider
           
 
Field Summary
static char PREFIX_SEPARATOR
          The character used to separate the prefix from the value name when you are using the getObject method with a prefix.
 
Constructor Summary
InjectionUtils()
           
 
Method Summary
static void beanToMap(Object bean, Map<String,String> map)
           
static boolean checkPrimitives(Class<? extends Object> target, Class<? extends Object> source)
           
static Field findFieldToInject(Class<? extends Object> target, String name, Class<? extends Object> source)
           
static Method findMethodToGet(Class<? extends Object> target, String name)
           
static Method findMethodToInject(Class<? extends Object> target, String name, Class<? extends Object> source)
           
static Class<?> findPropertyType(Class<?> target, String name)
           
static Object getDefaultValueForPrimitive(Class<?> klass)
           
static Field getField(Class<? extends Object> target, String name)
           
static Field getField(Object target, String name)
           
static void getObject(Object target, InjectionUtils.Provider provider, boolean tryField, String prefix, boolean tryToConvert, boolean convertBoolean, boolean allowRecursion)
           
static Class<? extends Object> getPrimitiveFrom(Class<? extends Object> klass)
           
static Class<? extends Object> getPrimitiveFrom(Object w)
           
static String getProperty(Object bean, String nameProperty)
          Extract the value of a property of a bean!
static boolean hasDefaultConstructor(Class<? extends Object> klass)
           
static boolean inject(Method m, Object target, Object value, boolean tryToConvert, boolean tryingToConvertBoolean)
           
static void prepareForInjection(Class<? extends Object> klass, Map<String,Object> setters, Map<String,Object> fields)
           
static Object shouldConvertToNull(Object value, Class<? extends Object> targetType)
           
static Object tryToConvert(Object source, Class<?> targetType, boolean tryNumber)
           
static Object tryToConvert(Object source, Class<? extends Object> targetType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREFIX_SEPARATOR

public static char PREFIX_SEPARATOR
The character used to separate the prefix from the value name when you are using the getObject method with a prefix. You can change the value of this prefix if you want to by changing this static variable. Ex: getObject(User.class, "user") will get all values that begin with "user.".

Constructor Detail

InjectionUtils

public InjectionUtils()
Method Detail

prepareForInjection

public static void prepareForInjection(Class<? extends Object> klass,
                                       Map<String,Object> setters,
                                       Map<String,Object> fields)

checkPrimitives

public static boolean checkPrimitives(Class<? extends Object> target,
                                      Class<? extends Object> source)

tryToConvert

public static Object tryToConvert(Object source,
                                  Class<? extends Object> targetType)

tryToConvert

public static Object tryToConvert(Object source,
                                  Class<?> targetType,
                                  boolean tryNumber)

shouldConvertToNull

public static Object shouldConvertToNull(Object value,
                                         Class<? extends Object> targetType)

getPrimitiveFrom

public static Class<? extends Object> getPrimitiveFrom(Object w)

getPrimitiveFrom

public static Class<? extends Object> getPrimitiveFrom(Class<? extends Object> klass)

getField

public static Field getField(Object target,
                             String name)

getField

public static Field getField(Class<? extends Object> target,
                             String name)

findPropertyType

public static Class<?> findPropertyType(Class<?> target,
                                        String name)

findMethodToGet

public static Method findMethodToGet(Class<? extends Object> target,
                                     String name)

findMethodToInject

public static Method findMethodToInject(Class<? extends Object> target,
                                        String name,
                                        Class<? extends Object> source)

findFieldToInject

public static Field findFieldToInject(Class<? extends Object> target,
                                      String name,
                                      Class<? extends Object> source)

inject

public static boolean inject(Method m,
                             Object target,
                             Object value,
                             boolean tryToConvert,
                             boolean tryingToConvertBoolean)
                      throws Exception
Throws:
Exception

hasDefaultConstructor

public static boolean hasDefaultConstructor(Class<? extends Object> klass)

getProperty

public static String getProperty(Object bean,
                                 String nameProperty)
                          throws Exception
Extract the value of a property of a bean!

Parameters:
bean - the target bean
nameProperty - the property name
Returns:
they value as String. The method toString is always called to every property!
Throws:
Exception

beanToMap

public static void beanToMap(Object bean,
                             Map<String,String> map)
                      throws IllegalArgumentException,
                             IllegalAccessException,
                             InvocationTargetException
Throws:
IllegalArgumentException
IllegalAccessException
InvocationTargetException

getDefaultValueForPrimitive

public static Object getDefaultValueForPrimitive(Class<?> klass)

getObject

public static void getObject(Object target,
                             InjectionUtils.Provider provider,
                             boolean tryField,
                             String prefix,
                             boolean tryToConvert,
                             boolean convertBoolean,
                             boolean allowRecursion)
                      throws Exception
Throws:
Exception


Copyright © 2013. All Rights Reserved.