public final class ClassLoaderUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <T,R> R |
applyWithClassLoader(@NonNull ClassLoader cls,
@NonNull Function<T,R> function,
T input)
Immediately call
Function.apply(Object) with provided ClassLoader . |
static <V> V |
callWithClassLoader(@NonNull ClassLoader cls,
@NonNull Callable<V> callable)
Immediately call
Callable.call() with provided ClassLoader . |
static <S,G,P> Class<P> |
findFirstGenericArgument(Class<S> scannedClass,
Class<G> genericType) |
static ParameterizedType |
findParameterizedType(Class<?> subclass,
Class<?> genericType) |
static Type |
getFirstGenericParameter(Type type) |
static <V> V |
getWithClassLoader(@NonNull ClassLoader cls,
@NonNull Supplier<V> supplier)
Immediately call
Supplier.get() with provided ClassLoader . |
static Class<?> |
loadClass(ClassLoader cls,
String name)
Loads class using this supplied classloader.
|
static Class<?> |
loadClassWithTCCL(String name) |
static void |
runWithClassLoader(@NonNull ClassLoader cls,
@NonNull Runnable runnable)
Immediately call
Runnable.run() with provided ClassLoader . |
static Class<?> |
tryToLoadClassWithTCCL(String fullyQualifiedClassName) |
@Beta public static <T,R> R applyWithClassLoader(@NonNull ClassLoader cls, @NonNull Function<T,R> function, T input)
Function.apply(Object)
with provided ClassLoader
. This method safely switches
the thread's Thread Context Class Loader to the specified class loader for the duration of execution of that
method.cls
- ClassLoader
to be used.function
- Function to be applied.input
- Function inputNullPointerException
- if class loader or function is null@Beta public static <V> V callWithClassLoader(@NonNull ClassLoader cls, @NonNull Callable<V> callable) throws Exception
Callable.call()
with provided ClassLoader
. This method safely switches
the thread's Thread Context Class Loader to the specified class loader for the duration of execution of that
method.cls
- ClassLoader
to be used.callable
- Function to be executed.NullPointerException
- if class loader or callable is nullException
@Beta public static <V> V getWithClassLoader(@NonNull ClassLoader cls, @NonNull Supplier<V> supplier)
Supplier.get()
with provided ClassLoader
. This method safely switches
the thread's Thread Context Class Loader to the specified class loader for the duration of execution of that
method.cls
- ClassLoader
to be used.supplier
- Function to be executed.NullPointerException
- if class loader or supplier is null@Beta public static void runWithClassLoader(@NonNull ClassLoader cls, @NonNull Runnable runnable)
Runnable.run()
with provided ClassLoader
. This method safely switches
the thread's Thread Context Class Loader to the specified class loader for the duration of execution of that
method.cls
- ClassLoader
to be used.runnable
- Function to be executed.NullPointerException
- if class loader or runnable is nullpublic static Class<?> loadClass(ClassLoader cls, String name) throws ClassNotFoundException
name
- String name of class.ClassNotFoundException
public static Class<?> loadClassWithTCCL(String name) throws ClassNotFoundException
ClassNotFoundException
public static Class<?> tryToLoadClassWithTCCL(String fullyQualifiedClassName)
public static <S,G,P> Class<P> findFirstGenericArgument(Class<S> scannedClass, Class<G> genericType)
public static ParameterizedType findParameterizedType(Class<?> subclass, Class<?> genericType)
Copyright © 2019 OpenDaylight. All rights reserved.