Package org.apache.pulsar.common.util
Class Reflections
java.lang.Object
org.apache.pulsar.common.util.Reflections
Utils related to reflections.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
classExists
(String fqcn) Check if class exists.static boolean
classExistsInJar
(File jar, String fqcn) Check if a class is in a jar.static boolean
classImplementsIface
(String fqcn, Class xface) check if class implements interface.static boolean
classInJarImplementsIface
(File jar, String fqcn, Class xface) check if a class implements an interface.static Object
createInstance
(String userClassName, File jar) static <T> T
createInstance
(String userClassName, Class<T> xface, ClassLoader classLoader) Create an instance ofuserClassName
using providedclassLoader
.static Object
createInstance
(String userClassName, ClassLoader classLoader) Create an instance ofuserClassName
using providedclassLoader
.static Object
createInstance
(String userClassName, ClassLoader classLoader, Object[] params, Class[] paramTypes) getAllFields
(Class<?> type) static Class
loadClass
(String className, ClassLoader classLoader) Load class to resolve array types.
-
Constructor Details
-
Reflections
public Reflections()
-
-
Method Details
-
createInstance
Create an instance ofuserClassName
using providedclassLoader
. This instance should implement the provided interfacexface
.- Parameters:
userClassName
- user class namexface
- the interface that the reflected instance should implementclassLoader
- class loader to load the class.- Returns:
- the instance
-
createInstance
Create an instance ofuserClassName
using providedclassLoader
.- Parameters:
userClassName
- user class nameclassLoader
- class loader to load the class.- Returns:
- the instance
-
createInstance
public static Object createInstance(String userClassName, ClassLoader classLoader, Object[] params, Class[] paramTypes) -
createInstance
-
classExistsInJar
Check if a class is in a jar.- Parameters:
jar
- location of the jarfqcn
- fully qualified class name to search for in jar- Returns:
- true if class can be loaded from jar and false if otherwise
-
classExists
Check if class exists.- Parameters:
fqcn
- fully qualified class name to search for- Returns:
- true if class can be loaded from jar and false if otherwise
-
classInJarImplementsIface
check if a class implements an interface.- Parameters:
fqcn
- fully qualified class name to search for in jarxface
- interface to check if implement- Returns:
- true if class from jar implements interface xface and false if otherwise
-
classImplementsIface
check if class implements interface.- Parameters:
fqcn
- fully qualified class namexface
- the interface the fqcn should implement- Returns:
- true if class implements interface xface and false if otherwise
-
loadClass
public static Class loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException Load class to resolve array types.- Parameters:
className
- class nameclassLoader
- class loader- Returns:
- loaded class
- Throws:
ClassNotFoundException
-
getAllFields
-