Package org.apache.pulsar.common.util
Class Reflections
java.lang.Object
org.apache.pulsar.common.util.Reflections
Utils related to reflections.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanclassExists(String fqcn) Check if class exists.static booleanclassExistsInJar(File jar, String fqcn) Check if a class is in a jar.static booleanclassImplementsIface(String fqcn, Class xface) check if class implements interface.static booleanclassInJarImplementsIface(File jar, String fqcn, Class xface) check if a class implements an interface.static ObjectcreateInstance(String userClassName, File jar) static <T> TcreateInstance(String userClassName, Class<T> xface, ClassLoader classLoader) Create an instance ofuserClassNameusing providedclassLoader.static ObjectcreateInstance(String userClassName, ClassLoader classLoader) Create an instance ofuserClassNameusing providedclassLoader.static ObjectcreateInstance(String userClassName, ClassLoader classLoader, Object[] params, Class[] paramTypes) getAllFields(Class<?> type) static ClassloadClass(String className, ClassLoader classLoader) Load class to resolve array types.
-
Constructor Details
-
Reflections
public Reflections()
-
-
Method Details
-
createInstance
Create an instance ofuserClassNameusing 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 ofuserClassNameusing 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
-