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> Optional<Class<P>> |
findFirstGenericArgument(Class<S> scannedClass,
Class<G> genericType) |
static Optional<ParameterizedType> |
findParameterizedType(Class<?> subclass,
Class<?> genericType)
Find the parameterized instantiation of a particular interface implemented by a class.
|
static Optional<Type> |
getFirstGenericParameter(Type type)
Extract the first generic type argument for a 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 Optional<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 Optional<Class<?>> tryToLoadClassWithTCCL(String fullyQualifiedClassName)
public static <S,G,P> Optional<Class<P>> findFirstGenericArgument(Class<S> scannedClass, Class<G> genericType)
public static Optional<ParameterizedType> findParameterizedType(Class<?> subclass, Class<?> genericType)
subclass
- Implementing classgenericType
- Interface to search forpublic static Optional<Type> getFirstGenericParameter(Type type)
type
- Type to examineNullPointerException
- if type
is nullCopyright © 2020 OpenDaylight. All rights reserved.