public class ClassLoaderHelper extends Object
Modifier and Type | Method and Description |
---|---|
static <T> Class<? extends T> |
classForName(Class<T> targetSuperType,
String classNameToLoad,
String componentDescription,
ClassResolver classResolver) |
static Class |
classForName(String classNameToLoad,
ClassResolver classResolver)
Perform resolution of a class name.
|
static Class<?> |
classForName(String classNameToLoad,
String componentDescription,
ClassResolver classResolver) |
static <T> T |
instanceFromClass(Class<T> targetSuperType,
Class<?> classToLoad,
String componentDescription)
Creates an instance of target class
|
static <T> T |
instanceFromClass(Class<T> targetSuperType,
Class<?> classToLoad,
String componentDescription,
Map<String,String> constructorParameter)
Creates an instance of target class having a Map of strings as constructor parameter.
|
static <T> T |
instanceFromName(Class<T> targetSuperType,
String classNameToLoad,
String componentDescription,
ClassResolver classResolver)
Creates an instance of a target class specified by the fully qualified class name using a
ClassLoader
as fallback when the class cannot be found in the context one. |
static <T> T |
untypedInstanceFromClass(Class<T> classToLoad,
String componentDescription)
Creates an instance of target class.
|
public static <T> T instanceFromName(Class<T> targetSuperType, String classNameToLoad, String componentDescription, ClassResolver classResolver)
ClassLoader
as fallback when the class cannot be found in the context one.T
- matches the type of targetSuperType: defines the return typetargetSuperType
- the return type of the function, the classNameToLoad will be checked
to be assignable to this type.classNameToLoad
- a fully qualified class name, whose type is assignable to targetSuperTypecomponentDescription
- a meaningful description of the role the instance will have,
used to enrich error messages to describe the context of the errorclassResolver
- the ClassResolver
to use to load classesclassNameToLoad
SearchException
- wrapping other error types with a proper error message for all kind of problems, like
classNotFound, missing proper constructor, wrong type, security errors.public static <T> T instanceFromClass(Class<T> targetSuperType, Class<?> classToLoad, String componentDescription)
T
- the type of targetSuperType: defines the return typetargetSuperType
- the created instance will be checked to be assignable to this typeclassToLoad
- the class to be instantiatedcomponentDescription
- a role name/description to contextualize error messagesSearchException
- wrapping other error types with a proper error message for all kind of problems, like
missing proper constructor, wrong type, securitymanager errors.public static <T> T untypedInstanceFromClass(Class<T> classToLoad, String componentDescription)
instanceFromClass(Class, Class, String)
but not checking
the created instance will be of any specific type: using instanceFromClass(Class, Class, String)
should
be preferred whenever possible.T
- the type of targetSuperType: defines the return typeclassToLoad
- the class to be instantiatedcomponentDescription
- a role name/description to contextualize error messages. Ideally should be provided, but it can handle null.SearchException
- wrapping other error types with a proper error message for all kind of problems, like
missing proper constructor, securitymanager errors.public static <T> T instanceFromClass(Class<T> targetSuperType, Class<?> classToLoad, String componentDescription, Map<String,String> constructorParameter)
T
- the type of targetSuperType: defines the return typetargetSuperType
- the created instance will be checked to be assignable to this typeclassToLoad
- the class to be instantiatedcomponentDescription
- a role name/description to contextualize error messagesconstructorParameter
- a Map to be passed to the constructor. The loaded type must have such a constructor.SearchException
- wrapping other error types with a proper error message for all kind of problems, like
missing proper constructor, wrong type, security errors.public static Class<?> classForName(String classNameToLoad, String componentDescription, ClassResolver classResolver)
public static <T> Class<? extends T> classForName(Class<T> targetSuperType, String classNameToLoad, String componentDescription, ClassResolver classResolver)
public static Class classForName(String classNameToLoad, ClassResolver classResolver)
Here we first check the context classloader, if one, before delegating to
Class.forName(String, boolean, ClassLoader)
using the caller's classloader
classNameToLoad
- The class nameclassResolver
- The ClassResolver
to use to load classesClassLoadingException
- From Class.forName(String, boolean, ClassLoader)
.Copyright © 2006-2018 Red Hat, Inc. and others. Licensed under the GNU Lesser General Public License (LGPL), version 2.1 or later.