Package org.apache.commons.jxpath.util
Class ClassLoaderUtil
java.lang.Object
org.apache.commons.jxpath.util.ClassLoaderUtil
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
FieldsModifier and TypeFieldDescriptionMaps a primitive class name to its corresponding abbreviation used in array class names. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddAbbreviation(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 byclassNameusing theclassLoader.static <T> Class<T> Gets the class represented byclassNameusing the current thread's context class loader.private static StringtoCanonicalName(String className) Converts a class name to a JLS style class name.
-
Field Details
-
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
Adds primitive type abbreviation to map of abbreviations.- Parameters:
primitive- Canonical name of primitive typeabbreviation- Corresponding abbreviation of primitive type
-
getClass
private static <T> Class<T> getClass(ClassLoader classLoader, String className, boolean initialize) throws ClassNotFoundException Gets the class represented byclassNameusing theclassLoader. 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 classclassName- the class nameinitialize- whether the class must be initialized- Returns:
- the class represented by
classNameusing theclassLoader - 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 byclassNameusing 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 nameinitialize- whether the class must be initialized- Returns:
- the class represented by
classNameusing the current thread's context class loader - Throws:
ClassNotFoundException- if the class is not found
-
toCanonicalName
Converts a class name to a JLS style class name.- Parameters:
className- the class name- Returns:
- the converted name
-