Class ReflectionUtils
- java.lang.Object
-
- org.apache.bookkeeper.common.util.ReflectionUtils
-
public class ReflectionUtils extends java.lang.ObjectGeneral Class Reflection Utils.
-
-
Constructor Summary
Constructors Constructor Description ReflectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.lang.Class<? extends T>forName(java.lang.String className, java.lang.Class<T> xface)Returns theClassobject object associated with the class or interface with the given string name, which is a subclass ofxface.static java.lang.Class<?>getClass(org.apache.commons.configuration2.Configuration conf, java.lang.String name, java.lang.Class<?> defaultCls, java.lang.ClassLoader classLoader)Get the value of thenameproperty as aClass.static <T> java.lang.Class<? extends T>getClass(org.apache.commons.configuration2.Configuration conf, java.lang.String name, java.lang.Class<? extends T> defaultValue, java.lang.Class<T> xface, java.lang.ClassLoader classLoader)Get the value of thenameproperty as aClassimplementing the interface specified byxface.static <T> TnewInstance(java.lang.Class<T> theCls)Create an object for the given class.static <T> TnewInstance(java.lang.String clsName, java.lang.Class<T> xface)Create an object using the given class name.
-
-
-
Method Detail
-
forName
public static <T> java.lang.Class<? extends T> forName(java.lang.String className, java.lang.Class<T> xface)Returns theClassobject object associated with the class or interface with the given string name, which is a subclass ofxface.- Parameters:
className- class namexface- class interface- Returns:
- the class object associated with the class or interface with the given string name.
-
getClass
public static java.lang.Class<?> getClass(org.apache.commons.configuration2.Configuration conf, java.lang.String name, java.lang.Class<?> defaultCls, java.lang.ClassLoader classLoader) throws org.apache.commons.configuration2.ex.ConfigurationExceptionGet the value of thenameproperty as aClass. If no such property is specified, thendefaultClsis 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, ordefaultCls. - Throws:
org.apache.commons.configuration2.ex.ConfigurationException
-
getClass
public static <T> java.lang.Class<? extends T> getClass(org.apache.commons.configuration2.Configuration conf, java.lang.String name, java.lang.Class<? extends T> defaultValue, java.lang.Class<T> xface, java.lang.ClassLoader classLoader) throws org.apache.commons.configuration2.ex.ConfigurationExceptionGet the value of thenameproperty as aClassimplementing the interface specified byxface.If no such property is specified, then
defaultValueis 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, ordefaultValue. - Throws:
org.apache.commons.configuration2.ex.ConfigurationException
-
newInstance
public static <T> T newInstance(java.lang.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(java.lang.String clsName, java.lang.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
-
-