Class ReflectionUtils

java.lang.Object
org.apache.bookkeeper.common.util.ReflectionUtils

public class ReflectionUtils extends Object
General Class Reflection Utils.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Class<? extends T>
    forName(String className, Class<T> xface)
    Returns the Class object object associated with the class or interface with the given string name, which is a subclass of xface.
    static Class<?>
    getClass(org.apache.commons.configuration2.Configuration conf, String name, Class<?> defaultCls, ClassLoader classLoader)
    Get the value of the name property as a Class.
    static <T> Class<? extends T>
    getClass(org.apache.commons.configuration2.Configuration conf, String name, Class<? extends T> defaultValue, Class<T> xface, ClassLoader classLoader)
    Get the value of the name property as a Class implementing the interface specified by xface.
    static <T> T
    newInstance(Class<T> theCls)
    Create an object for the given class.
    static <T> T
    newInstance(String clsName, Class<T> xface)
    Create an object using the given class name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ReflectionUtils

      public ReflectionUtils()
  • Method Details

    • forName

      public static <T> Class<? extends T> forName(String className, Class<T> xface)
      Returns the Class object object associated with the class or interface with the given string name, which is a subclass of xface.
      Parameters:
      className - class name
      xface - class interface
      Returns:
      the class object associated with the class or interface with the given string name.
    • getClass

      public static Class<?> getClass(org.apache.commons.configuration2.Configuration conf, String name, Class<?> defaultCls, ClassLoader classLoader) throws org.apache.commons.configuration2.ex.ConfigurationException
      Get the value of the name property as a Class. If no such property is specified, then defaultCls is returned.
      Parameters:
      conf - Configuration Object.
      name - Class Property Name.
      defaultCls - Default Class to be returned.
      classLoader - Class Loader to load class.
      Returns:
      property value as a Class, or defaultCls.
      Throws:
      org.apache.commons.configuration2.ex.ConfigurationException
    • getClass

      public static <T> Class<? extends T> getClass(org.apache.commons.configuration2.Configuration conf, String name, Class<? extends T> defaultValue, Class<T> xface, ClassLoader classLoader) throws org.apache.commons.configuration2.ex.ConfigurationException
      Get the value of the name property as a Class implementing the interface specified by xface.

      If no such property is specified, then defaultValue is returned.

      An exception is thrown if the returned class does not implement the named interface.

      Parameters:
      conf - Configuration Object.
      name - Class Property Name.
      defaultValue - Default Class to be returned.
      xface - The interface implemented by the named class.
      classLoader - Class Loader to load class.
      Returns:
      property value as a Class, or defaultValue.
      Throws:
      org.apache.commons.configuration2.ex.ConfigurationException
    • newInstance

      public static <T> T newInstance(Class<T> theCls)
      Create an object for the given class.
      Parameters:
      theCls - class of which an object is created.
      Returns:
      a new object
    • newInstance

      public static <T> T newInstance(String clsName, Class<T> xface)
      Create an object using the given class name.
      Parameters:
      clsName - class name of which an object is created.
      xface - The interface implemented by the named class.
      Returns:
      a new object