Class ConversionUtils

java.lang.Object
org.red5.io.utils.ConversionUtils

public class ConversionUtils extends Object
Misc utils for conversions
Author:
The Red5 Project, Luke Hubbard, Codegent Ltd (luke@codegent.com), Paul Gregoire (mondain@gmail.com)
  • Field Details

    • log

      private static final org.slf4j.Logger log
    • PRIMITIVES

      private static final Class<?>[] PRIMITIVES
    • WRAPPERS

      private static final Class<?>[] WRAPPERS
    • NUMERIC_TYPE

      private static final String NUMERIC_TYPE
      See Also:
    • PARAMETER_CHAINS

      private static final Class<?>[][] PARAMETER_CHAINS
      Parameter chains
    • primitiveMap

      private static Map<Class<?>,Class<?>> primitiveMap
      Mapping of primitives to wrappers
    • wrapperMap

      private static Map<Class<?>,Class<?>> wrapperMap
      Mapping of wrappers to primitives
    • parameterMap

      private static Map<Class<?>,Class<?>[]> 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

      private static String ignoredMethodNames
      Method names to skip when scanning for usable application methods.
  • Constructor Details

    • ConversionUtils

      public ConversionUtils()
  • Method Details

    • isBaseTypeOrArray

      public static boolean isBaseTypeOrArray(Object obj)
      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 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<String,? extends Object> 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
    • newInstance

      private static Object newInstance(Class<?> clazz)
      Create new class instance
      Parameters:
      clazz - Class; may not be loaded by JVM yet
      Returns:
      Instance of given class