Class ClassLoaderUtil

java.lang.Object
org.apache.commons.jxpath.util.ClassLoaderUtil

public final class ClassLoaderUtil extends Object
Port of class loading methods from org.apache.commons.lang3.ClassUtils from the Apache Commons Lang Component. Some adjustments made to remove dependency on org.apache.commons.lang3.StringUtils. Also modified to fall back on the current class loader when an attempt to load a class with the context class loader results in a java.lang.ClassNotFoundException. See org.apache.commons.lang3.ClassUtils
Since:
1.4.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static Map<String,String>
    Maps a primitive class name to its corresponding abbreviation used in array class names.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    New need to constructs new instances.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    addAbbreviation(String primitive, String abbreviation)
    Adds primitive type abbreviation to map of abbreviations.
    private static <T> Class<T>
    getClass(ClassLoader classLoader, String className, boolean initialize)
    Gets the class represented by className using the classLoader.
    static <T> Class<T>
    getClass(String className, boolean initialize)
    Gets the class represented by className using the current thread's context class loader.
    private static String
    Converts a class name to a JLS style class name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • abbreviationMap

      private static Map<String,String> abbreviationMap
      Maps a primitive class name to its corresponding abbreviation used in array class names.
  • Constructor Details

    • ClassLoaderUtil

      private ClassLoaderUtil()
      New need to constructs new instances.
  • Method Details

    • addAbbreviation

      private static void addAbbreviation(String primitive, String abbreviation)
      Adds primitive type abbreviation to map of abbreviations.
      Parameters:
      primitive - Canonical name of primitive type
      abbreviation - Corresponding abbreviation of primitive type
    • getClass

      private static <T> Class<T> getClass(ClassLoader classLoader, String className, boolean initialize) throws ClassNotFoundException
      Gets the class represented by className using the classLoader. This implementation supports names like "java.lang.String[]" as well as "[Ljava.lang.String;".
      Type Parameters:
      T - The expected class type.
      Parameters:
      classLoader - the class loader to use to load the class
      className - the class name
      initialize - whether the class must be initialized
      Returns:
      the class represented by className using the classLoader
      Throws:
      ClassNotFoundException - if the class is not found
    • getClass

      public static <T> Class<T> getClass(String className, boolean initialize) throws ClassNotFoundException
      Gets the class represented by className using the current thread's context class loader. This implementation supports names like "java.lang.String[]" as well as "[Ljava.lang.String;".
      Type Parameters:
      T - The expected class type.
      Parameters:
      className - the class name
      initialize - whether the class must be initialized
      Returns:
      the class represented by className using the current thread's context class loader
      Throws:
      ClassNotFoundException - if the class is not found
    • toCanonicalName

      private static String toCanonicalName(String className)
      Converts a class name to a JLS style class name.
      Parameters:
      className - the class name
      Returns:
      the converted name