Class ClassUtil

java.lang.Object
org.jolokia.server.core.util.ClassUtil

public final class ClassUtil extends Object
Utility for class lookup.
Since:
19.04.11
Author:
roland
  • Method Details

    • classForName

      public static <T> Class<T> classForName(String pClassName, ClassLoader... pClassLoaders)
      Lookup a class. See classForName(String, boolean,ClassLoader[]) for details. The class gets initialized during lookup.
      Parameters:
      pClassName - name to lookup.
      Returns:
      the class found or null if no class could be found.
    • classForName

      public static <T> Class<T> classForName(String pClassName, boolean pInitialize, ClassLoader... pClassLoaders)
      Load a certain class. Several class loader are tried: Fires the current thread's context class loader, then its parents. If this doesn't work, the class loader which loaded this class is used (and its parents)
      Parameters:
      pClassName - class name to load
      pInitialize - whether the class must be initialized
      pClassLoaders - optional class loaders which are tried as well
      Returns:
      the class class found or null if no class could be loaded
    • getResourceAsStream

      public static InputStream getResourceAsStream(String pPath)
      Get the given path as an input stream or return null if not found
      Parameters:
      pPath - path to lookup
      Returns:
      input stream or null if not found.
    • checkForClass

      public static boolean checkForClass(String pClassName)
      Check for the existence of a given class
      Parameters:
      pClassName - class name to check
      Returns:
      true if the class could be loaded by the thread's conext class loader, false otherwise
    • newInstance

      public static <T> T newInstance(String pClassName, Object... pArguments)
      Instantiate an instance of the given class with its default constructor. The context class loader is used to lookup the class
      Type Parameters:
      T - type object type
      Parameters:
      pClassName - name of class to instantiate
      pArguments - optional constructor arguments. Works only for objects with the same class as declared in the constructor types (no subclasses)
      Returns:
      instantiated object
      Throws:
      IllegalArgumentException - if the class could not be found or instantiated
    • newInstance

      public static <T> T newInstance(Class<T> pClass, Object... pArguments)
      Instantiate an instance of the given class with its default constructor
      Type Parameters:
      T - type object type
      Parameters:
      pClass - class to instantiate
      pArguments - optional constructor arguments. Works only for objects with the same class as declared in the constructor types (no subclasses)
      Returns:
      instantiated object
      Throws:
      IllegalArgumentException - if the class could not be found or instantiated
    • newLogHandlerInstance

      public static LogHandler newLogHandlerInstance(String pLogHandlerClass, String pLogHandlerName, boolean pIsDebug)
    • applyMethod

      public static Object applyMethod(Object pObject, String pMethod, Object... pArgs)
      Apply a method to a given object with optional arguments. The method is looked up the whole class hierarchy.
      Parameters:
      pObject - object on which to apply the method
      pMethod - the method name
      pArgs - optional arguments
      Returns:
      return value (if any)
    • getResources

      public static Set<String> getResources(String pResource) throws IOException
      Get all resources from the classpath which are specified by the given path.
      Parameters:
      pResource - resource specification to use for lookup
      Returns:
      the list or URLs to loookup
      Throws:
      IOException