org.red5.server.service
Class ConversionUtils

java.lang.Object
  extended by org.red5.server.service.ConversionUtils

public class ConversionUtils
extends Object

Misc utils for conversions

Author:
The Red5 Project (red5@osflash.org), Luke Hubbard, Codegent Ltd (luke@codegent.com), Paul Gregoire (mondain@gmail.com)

Constructor Summary
ConversionUtils()
           
 
Method Summary
static Object convert(Object source, Class<?> target)
          Convert source to given class
static List<?> convertArrayToList(Object[] source)
           
static Set<?> convertArrayToSet(Object[] source)
          Convert array to set, removing duplicates
static Map<?,?> convertBeanToMap(Object source)
          Convert bean to map
static Object convertMapToBean(Map<?,?> source, Class<?> target)
          Convert map to bean
static List<Object> convertMapToList(Map<?,?> map)
           
static Object convertNumberToWrapper(Number num, Class<?> wrapper)
          Convert number to primitive wrapper like Boolean or Float
static Class<?>[] convertParams(Object[] source)
          Convert parameters using methods of this utility class.
static Object[] convertParams(Object[] source, Class<?>[] target)
          Convert parameters using methods of this utility class
static Object convertStringToWrapper(String str, Class<?> wrapper)
          Convert string to primitive wrapper like Boolean or Float
static Object convertToArray(Object source, Class<?> target)
          Convert to array
static Object convertToWrappedPrimitive(Object source, Class<?> wrapper)
          Convert to wrapped primitive
static List<Method> findMethodsByNameAndNumParams(Object object, String method, int numParam)
          Find method by name and number of parameters
protected static Object newInstance(String className)
          Create new class instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConversionUtils

public ConversionUtils()
Method Detail

convert

public static Object convert(Object source,
                             Class<?> target)
                      throws org.apache.commons.beanutils.ConversionException
Convert source to given class

Parameters:
source - Source object
target - Target class
Returns:
Converted object
Throws:
org.apache.commons.beanutils.ConversionException - If object can't be converted

convertToArray

public static Object convertToArray(Object source,
                                    Class<?> target)
                             throws org.apache.commons.beanutils.ConversionException
Convert to array

Parameters:
source - Source object
target - Target class
Returns:
Converted object
Throws:
org.apache.commons.beanutils.ConversionException - If object can't be converted

convertMapToList

public static List<Object> convertMapToList(Map<?,?> map)

convertToWrappedPrimitive

public static Object convertToWrappedPrimitive(Object source,
                                               Class<?> wrapper)
Convert to wrapped primitive

Parameters:
source - Source object
wrapper - Primitive wrapper type
Returns:
Converted object

convertStringToWrapper

public static Object convertStringToWrapper(String str,
                                            Class<?> wrapper)
Convert string to primitive wrapper like Boolean or Float

Parameters:
str - String to convert
wrapper - Primitive wrapper type
Returns:
Converted object

convertNumberToWrapper

public static Object convertNumberToWrapper(Number num,
                                            Class<?> wrapper)
Convert number to primitive wrapper like Boolean or Float

Parameters:
num - Number to conver
wrapper - Primitive wrapper type
Returns:
Converted object

findMethodsByNameAndNumParams

public static List<Method> findMethodsByNameAndNumParams(Object object,
                                                         String method,
                                                         int numParam)
Find method by name and number of parameters

Parameters:
object - Object to find method on
method - Method name
numParam - Number of parameters
Returns:
List of methods that match by name and number of parameters

convertParams

public static Object[] convertParams(Object[] source,
                                     Class<?>[] target)
                              throws org.apache.commons.beanutils.ConversionException
Convert parameters using methods of this utility class

Parameters:
source - Array of source object
target - Array of target classes
Returns:
Array of converted objects
Throws:
org.apache.commons.beanutils.ConversionException - If object can't be converted

convertParams

public static Class<?>[] convertParams(Object[] source)
Convert parameters using methods of this utility class. Special handling is afforded to classes that implement IConnection.

Parameters:
source - Array of source object
Returns:
Array of converted objects

convertArrayToList

public static List<?> convertArrayToList(Object[] source)
                                  throws org.apache.commons.beanutils.ConversionException
Parameters:
source - source arra
Returns:
list
Throws:
org.apache.commons.beanutils.ConversionException - on failure

convertMapToBean

public static Object convertMapToBean(Map<?,?> source,
                                      Class<?> target)
                               throws org.apache.commons.beanutils.ConversionException
Convert map to bean

Parameters:
source - Source map
target - Target class
Returns:
Bean of that class
Throws:
org.apache.commons.beanutils.ConversionException - on failure

convertBeanToMap

public static Map<?,?> convertBeanToMap(Object source)
Convert bean to map

Parameters:
source - Source bean
Returns:
Converted map

convertArrayToSet

public static Set<?> convertArrayToSet(Object[] source)
Convert array to set, removing duplicates

Parameters:
source - Source array
Returns:
Set

newInstance

protected static Object newInstance(String className)
Create new class instance

Parameters:
className - Class name; may not be loaded by JVM yet
Returns:
Instance of given class


Copyright © 2006-2010 The Red5 Project