Class Reflections

java.lang.Object
org.apache.pulsar.common.util.Reflections

public class Reflections extends Object
Utils related to reflections.
  • Constructor Details

    • Reflections

      public Reflections()
  • Method Details

    • createInstance

      public static <T> T createInstance(String userClassName, Class<T> xface, ClassLoader classLoader)
      Create an instance of userClassName using provided classLoader. This instance should implement the provided interface xface.
      Parameters:
      userClassName - user class name
      xface - the interface that the reflected instance should implement
      classLoader - class loader to load the class.
      Returns:
      the instance
    • createInstance

      public static Object createInstance(String userClassName, ClassLoader classLoader)
      Create an instance of userClassName using provided classLoader.
      Parameters:
      userClassName - user class name
      classLoader - class loader to load the class.
      Returns:
      the instance
    • createInstance

      public static Object createInstance(String userClassName, ClassLoader classLoader, Object[] params, Class[] paramTypes)
    • createInstance

      public static Object createInstance(String userClassName, File jar)
    • classExistsInJar

      public static boolean classExistsInJar(File jar, String fqcn)
      Check if a class is in a jar.
      Parameters:
      jar - location of the jar
      fqcn - fully qualified class name to search for in jar
      Returns:
      true if class can be loaded from jar and false if otherwise
    • classExists

      public static boolean classExists(String fqcn)
      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

      public static boolean classInJarImplementsIface(File jar, String fqcn, Class xface)
      check if a class implements an interface.
      Parameters:
      fqcn - fully qualified class name to search for in jar
      xface - interface to check if implement
      Returns:
      true if class from jar implements interface xface and false if otherwise
    • classImplementsIface

      public static boolean classImplementsIface(String fqcn, Class xface)
      check if class implements interface.
      Parameters:
      fqcn - fully qualified class name
      xface - 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 name
      classLoader - class loader
      Returns:
      loaded class
      Throws:
      ClassNotFoundException
    • getAllFields

      public static List<Field> getAllFields(Class<?> type)