org.mentawai.util
Class InjectionUtils

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

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

checkPrimitives

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

tryToConvert

public static java.lang.Object tryToConvert(java.lang.Object source,
                                            java.lang.Class targetType,
                                            java.util.Locale loc)

tryToConvert

public static java.lang.Object tryToConvert(java.lang.Object source,
                                            java.lang.Class targetType,
                                            java.util.Locale loc,
                                            boolean tryNumber)

shouldConvertToNull

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

getPrimitiveFrom

public static java.lang.Class getPrimitiveFrom(java.lang.Object w)

getPrimitiveFrom

public static java.lang.Class getPrimitiveFrom(java.lang.Class klass)

getField

public static java.lang.reflect.Field getField(java.lang.Object target,
                                               java.lang.String name)

getField

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

findMethodToGet

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

findMethodToInject

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

findFieldToInject

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

getValueToInject

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

hasValueToInject

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

inject

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

hasDefaultConstructor

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

getObject

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

setObject

public static void setObject(java.lang.Object bean,
                             Output output,
                             java.lang.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 java.lang.String getProperty(java.lang.Object bean,
                                           java.lang.String nameProperty)
                                    throws java.lang.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
java.lang.Exception

beanToMap

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


Copyright © 2005 Mentawai Team. All Rights Reserved.