Package org.red5.io.utils
Class ConversionUtils
java.lang.Object
org.red5.io.utils.ConversionUtils
Misc utils for conversions
- Author:
- The Red5 Project, Luke Hubbard, Codegent Ltd (luke@codegent.com), Paul Gregoire (mondain@gmail.com)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static String
Method names to skip when scanning for usable application methods.private static final org.slf4j.Logger
private static final String
private static final Class<?>[][]
Parameter chainsMapping from wrapper class to appropriate parameter types (in order) Each entry is an array of Classes, the last of which is either null (for no chaining) or the next class to tryMapping of primitives to wrappersprivate static final Class<?>[]
Mapping of wrappers to primitivesprivate static final Class<?>[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
Convert source to given classstatic List<?>
convertArrayToList
(Object[] source) static Set<?>
convertArrayToSet
(Object[] source) Convert array to set, removing duplicatesstatic Map<?,
?> convertBeanToMap
(Object source) Convert bean to mapstatic Object
convertMapToBean
(Map<String, ? extends Object> source, Class<?> target) Convert map to beanconvertMapToList
(Map<?, ?> map) static Object
convertNumberToWrapper
(Number num, Class<?> wrapper) Convert number to primitive wrapper like Boolean or Floatstatic 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 classstatic Object
convertStringToWrapper
(String str, Class<?> wrapper) Convert string to primitive wrapper like Boolean or Floatstatic Object
convertToArray
(Object source, Class<?> target) Convert to arraystatic Object
convertToWrappedPrimitive
(Object source, Class<?> wrapper) Convert to wrapped primitivefindMethodsByNameAndNumParams
(Object object, String method, int numParam) Find method by name and number of parametersstatic boolean
isBaseTypeOrArray
(Object obj) Returns true for base types or arrays of base type.private static Object
newInstance
(Class<?> clazz) Create new class instanceprotected static Object
newInstance
(String className) Create new class instance
-
Field Details
-
log
private static final org.slf4j.Logger log -
PRIMITIVES
-
WRAPPERS
-
NUMERIC_TYPE
- See Also:
-
PARAMETER_CHAINS
Parameter chains -
primitiveMap
Mapping of primitives to wrappers -
wrapperMap
Mapping of wrappers to primitives -
parameterMap
Mapping from wrapper class to appropriate parameter types (in order) Each entry is an array of Classes, the last of which is either null (for no chaining) or the next class to try -
ignoredMethodNames
Method names to skip when scanning for usable application methods.
-
-
Constructor Details
-
ConversionUtils
public ConversionUtils()
-
-
Method Details
-
isBaseTypeOrArray
Returns true for base types or arrays of base type.- Parameters:
obj
- Object- Returns:
- true if base-type or array and false otherwise
-
convert
public static Object convert(Object source, Class<?> target) throws org.apache.commons.beanutils.ConversionException Convert source to given class- Parameters:
source
- Source objecttarget
- 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 objecttarget
- Target class- Returns:
- Converted object
- Throws:
org.apache.commons.beanutils.ConversionException
- If object can't be converted
-
convertMapToList
-
convertToWrappedPrimitive
Convert to wrapped primitive- Parameters:
source
- Source objectwrapper
- Primitive wrapper type- Returns:
- Converted object
-
convertStringToWrapper
Convert string to primitive wrapper like Boolean or Float- Parameters:
str
- String to convertwrapper
- Primitive wrapper type- Returns:
- Converted object
-
convertNumberToWrapper
Convert number to primitive wrapper like Boolean or Float- Parameters:
num
- Number to converwrapper
- 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 onmethod
- Method namenumParam
- 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 objecttarget
- Array of target classes- Returns:
- Array of converted objects
- Throws:
org.apache.commons.beanutils.ConversionException
- If object can't be converted
-
convertParams
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<String, ? extends Object> source, Class<?> target) throws org.apache.commons.beanutils.ConversionExceptionConvert map to bean- Parameters:
source
- Source maptarget
- Target class- Returns:
- Bean of that class
- Throws:
org.apache.commons.beanutils.ConversionException
- on failure
-
convertBeanToMap
Convert bean to map- Parameters:
source
- Source bean- Returns:
- Converted map
-
convertArrayToSet
Convert array to set, removing duplicates- Parameters:
source
- Source array- Returns:
- Set
-
newInstance
Create new class instance- Parameters:
className
- Class name; may not be loaded by JVM yet- Returns:
- Instance of given class
-
newInstance
Create new class instance- Parameters:
clazz
- Class; may not be loaded by JVM yet- Returns:
- Instance of given class
-