Class Classes

java.lang.Object
com.okta.commons.lang.Classes

public class Classes extends Object
Since:
0.5.0
  • Constructor Details

    • Classes

      public Classes()
  • Method Details

    • forName

      public static <T> Class<T> forName(String fqcn) throws UnknownClassException
      Attempts to load the specified class name from the current thread's context class loader, then the current ClassLoader (Classes.class.getClassLoader()), then the system/application ClassLoader (ClassLoader.getSystemClassLoader(), in that order. If any of them cannot locate the specified class, an UnknownClassException is thrown (our RuntimeException equivalent of the JRE's ClassNotFoundException.
      Type Parameters:
      T - type of class
      Parameters:
      fqcn - the fully qualified class name to load
      Returns:
      the located class
      Throws:
      UnknownClassException - if the class cannot be found.
    • getResourceAsStream

      public static InputStream getResourceAsStream(String name)
      Returns the specified resource by checking the current thread's context class loader, then the current ClassLoader (Classes.class.getClassLoader()), then the system/application ClassLoader (ClassLoader.getSystemClassLoader(), in that order, using getResourceAsStream(name).
      Parameters:
      name - the name of the resource to acquire from the classloader(s).
      Returns:
      the InputStream of the resource found, or null if the resource cannot be found from any of the three mentioned ClassLoaders.
    • isAvailable

      public static boolean isAvailable(String fullyQualifiedClassName)
    • newInstance

      public static <T> T newInstance(String fqcn)
    • newInstance

      public static <T> T newInstance(String fqcn, Object... args)
    • newInstance

      public static <T> T newInstance(Class<T> clazz)
    • newInstance

      public static <T> T newInstance(Class<T> clazz, Object... args)
    • getConstructor

      public static <T> Constructor<T> getConstructor(Class<T> clazz, Class... argTypes)
    • instantiate

      public static <T> T instantiate(Constructor<T> ctor, Object... args)
    • loadFromService

      public static <T> T loadFromService(Class<T> clazz)
    • loadFromService

      public static <T> T loadFromService(Class<T> clazz, String errorMessage)