Package org.postgresql.util
Class ClassUtils
- java.lang.Object
-
- org.postgresql.util.ClassUtils
-
public final class ClassUtils extends java.lang.ObjectUtility class for safe class loading operations.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> java.lang.Class<? extends T>forName(java.lang.String className, java.lang.Class<T> expectedClass, java.lang.ClassLoader classLoader)Deprecated.useforName(String, Class, ClassLoaderStrategy, ClassLoader), which also lets the caller fall back to the thread context classloaderstatic <T> java.lang.Class<? extends T>forName(java.lang.String className, java.lang.Class<T> expectedClass, ClassLoaderStrategy strategy, java.lang.ClassLoader driverClassLoader)Loads a class named by a connection property and validates that it is assignable to the expected type.
-
-
-
Method Detail
-
forName
public static <T> java.lang.Class<? extends T> forName(java.lang.String className, java.lang.Class<T> expectedClass, ClassLoaderStrategy strategy, java.lang.ClassLoader driverClassLoader) throws java.lang.ClassNotFoundExceptionLoads a class named by a connection property and validates that it is assignable to the expected type. The class is loaded withinitialize=falseso that its static initialiser does not run until the type check has passed.The classloaders to try, and their order, come from
strategy. The first classloader that resolves the name wins; aClassNotFoundExceptionfrom one classloader falls through to the next. A class that resolves but is not a subtype ofexpectedClassfails fast with aClassCastExceptionrather than falling through.- Type Parameters:
T- the expected type- Parameters:
className- the name of the class to loadexpectedClass- the expected superclass or interfacestrategy- the order in which to try the classloadersdriverClassLoader- the driver's own classloader- Returns:
- the loaded class as a subclass of the expected type
- Throws:
java.lang.ClassNotFoundException- if none of the classloaders can find the class
-
forName
@Deprecated public static <T> java.lang.Class<? extends T> forName(java.lang.String className, java.lang.Class<T> expectedClass, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundExceptionDeprecated.useforName(String, Class, ClassLoaderStrategy, ClassLoader), which also lets the caller fall back to the thread context classloaderLoads a class by name from the given classloader only, validating that it is assignable to the expected type. AnullclassLoader means the bootstrap classloader, matchingClass.forName(String, boolean, ClassLoader).- Type Parameters:
T- the expected type- Parameters:
className- the name of the class to loadexpectedClass- the expected superclass or interfaceclassLoader- the classloader to use- Returns:
- the loaded class as a subclass of the expected type
- Throws:
java.lang.ClassNotFoundException- if the class cannot be found
-
-