Package org.postgresql.util
Class ClassUtils
java.lang.Object
org.postgresql.util.ClassUtils
Utility class for safe class loading operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Class<? extends T> forName(String className, Class<T> expectedClass, ClassLoader classLoader) Deprecated.static <T> Class<? extends T> forName(String className, Class<T> expectedClass, ClassLoaderStrategy strategy, ClassLoader driverClassLoader) Loads a class named by a connection property and validates that it is assignable to the expected type.
-
Method Details
-
forName
public static <T> Class<? extends T> forName(String className, Class<T> expectedClass, ClassLoaderStrategy strategy, ClassLoader driverClassLoader) throws ClassNotFoundException Loads 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:
ClassNotFoundException- if none of the classloaders can find the class
-
forName
@Deprecated public static <T> Class<? extends T> forName(String className, Class<T> expectedClass, ClassLoader classLoader) throws ClassNotFoundException Deprecated.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:
ClassNotFoundException- if the class cannot be found
-
forName(String, Class, ClassLoaderStrategy, ClassLoader), which also lets the caller fall back to the thread context classloader