org.mentawai.util
Class InjectionUtils

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

public class InjectionUtils
extends Object

Author:
Sergio Oliveira

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 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 source)
           
static Field getField(Class<? extends Object> target, String name)
           
static Field getField(Object target, String name)
           
static void getObject(Object target, Input input, Locale loc, boolean tryField, String prefix, boolean tryToConvert, boolean convertBoolean, boolean allowRecursion)
           
static Object getPrimitiveBlankValue(Class klass)
           
static Class getPrimitiveFrom(Class klass)
           
static Class getPrimitiveFrom(Object w)
           
static String getProperty(Object bean, String nameProperty)
          Extract the value of a property of a bean!
static Object getValueToInject(String name, Input input, String prefix)
           
static boolean hasDefaultConstructor(Class<? extends Object> klass)
           
static boolean hasValueToInject(String name, Input input, String prefix)
           
static boolean inject(Method m, Object target, Object value, Locale loc, boolean tryToConvert, boolean tryingToConvertBoolean)
           
static void prepareForInjection(Class<? extends Object> klass, Map<String,Object> setters, Map<String,Object> fields)
           
static void setObject(Object bean, Output output, String prefix, boolean overwrite)
          Extract all properties from bean and place them in output.
static Object shouldConvertToNull(Object value, Class<? extends Object> targetType)
           
static Object tryToConvert(Object source, Class targetType, Locale loc)
           
static Object tryToConvert(Object source, Class targetType, Locale loc, boolean tryNumber)
           
 
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 target,
                                      Class<? extends Object> source)

tryToConvert

public static Object tryToConvert(Object source,
                                  Class targetType,
                                  Locale loc)

tryToConvert

public static Object tryToConvert(Object source,
                                  Class targetType,
                                  Locale loc,
                                  boolean tryNumber)

shouldConvertToNull

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

getPrimitiveFrom

public static Class getPrimitiveFrom(Object w)

getPrimitiveBlankValue

public static Object getPrimitiveBlankValue(Class klass)

getPrimitiveFrom

public static Class getPrimitiveFrom(Class klass)

getField

public static Field getField(Object target,
                             String name)

getField

public static Field getField(Class<? extends Object> 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 source)

findFieldToInject

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

getValueToInject

public static Object getValueToInject(String name,
                                      Input input,
                                      String prefix)

hasValueToInject

public static boolean hasValueToInject(String name,
                                       Input input,
                                       String prefix)

inject

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

hasDefaultConstructor

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

getObject

public static void getObject(Object target,
                             Input input,
                             Locale loc,
                             boolean tryField,
                             String prefix,
                             boolean tryToConvert,
                             boolean convertBoolean,
                             boolean allowRecursion)
                      throws Exception
Throws:
Exception

setObject

public static void setObject(Object bean,
                             Output output,
                             String prefix,
                             boolean overwrite)
Extract all properties from bean and place them in output.

Parameters:
bean - The beam from where to extract the properties.
output - The output where to place the properties.
prefix - The prefix to use when placing the properties in the output.
overwrite - Overwrite ot not if value is already in the output.

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
Exception

beanToMap

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


Copyright © 2013. All Rights Reserved.