Skip to content

Commit

Permalink
HSEARCH-1268 Add method to ClassLoaderHelper to pass a fallback
Browse files Browse the repository at this point in the history
ClassLoader
  • Loading branch information
DavideD committed Feb 5, 2013
1 parent 8836074 commit 915e399
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,39 @@ private static void getResources(String resourceName, ClassLoader cl, Set<URL> u
* @return a new instance of classNameToLoad
* @throws SearchException wrapping other error types with a proper error message for all kind of problems, like
* classNotFound, missing proper constructor, wrong type, security errors.
*
* @deprecated Use {@link ClassLoaderHelper#instanceFromName(Class, String, ClassLoader, String)} instead
*/
@Deprecated
public static <T> T instanceFromName(Class<T> targetSuperType, String classNameToLoad,
Class<?> caller, String componentDescription) {
final Class<?> clazzDef;
clazzDef = classForName( classNameToLoad, caller.getClassLoader(), componentDescription );
return instanceFromName( targetSuperType, classNameToLoad, caller.getClassLoader(), componentDescription );
}

/**
* Creates an instance of a target class specified by the fully qualified class name using a {@link ClassLoader}
* as fallback when the class cannot be found in the context one.
*
* @param <T>
* matches the type of targetSuperType: defines the return type
* @param targetSuperType
* the return type of the function, the classNameToLoad will be checked
* to be assignable to this type.
* @param classNameToLoad
* a fully qualified class name, whose type is assignable to targetSuperType
* @param fallbackClassLoader
* the ClassLoader used when the class cannot be found in the context one
* @param componentDescription
* a meaningful description of the role the instance will have,
* used to enrich error messages to describe the context of the error
* @return a new instance of classNameToLoad
* @throws 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 instanceFromName(Class<T> targetSuperType, String classNameToLoad, ClassLoader fallbackClassLoader,
String componentDescription) {
final Class<?> clazzDef = classForName( classNameToLoad, fallbackClassLoader, componentDescription );
return instanceFromClass( targetSuperType, clazzDef, componentDescription );
}

Expand Down

0 comments on commit 915e399

Please sign in to comment.