Class ClassLoaderHelper
java.lang.Object
org.hibernate.search.engine.environment.classpath.spi.ClassLoaderHelper
Utility class to load instances of other classes by using a fully qualified name,
or from a class type.
Uses reflection and throws SearchException(s) with proper descriptions of the error,
such as the target class is missing a proper constructor, is an interface, is not found...
- Author:
- Sanne Grinovero, Hardy Ferentschik, Ales Justin
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Class<? extends T>classForName(Class<T> targetSuperType, String classNameToLoad, ClassResolver classResolver) static <T> TinstanceFromClass(Class<T> targetSuperType, Class<?> classToLoad, Map<String, String> constructorParameter) Creates an instance of target class having a Map of strings as constructor parameter.static <T> TinstanceFromName(Class<T> targetSuperType, String classNameToLoad, ClassResolver classResolver) Creates an instance of a target class specified by the fully qualified class name using aClassLoaderas fallback when the class cannot be found in the context one.static <T> TuntypedInstanceFromClass(Class<T> classToLoad) Creates an instance of target class.
-
Method Details
-
instanceFromName
public static <T> T instanceFromName(Class<T> targetSuperType, String classNameToLoad, ClassResolver classResolver) Creates an instance of a target class specified by the fully qualified class name using aClassLoaderas fallback when the class cannot be found in the context one.- Type Parameters:
T- matches the type of targetSuperType: defines the return type- Parameters:
targetSuperType- 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 targetSuperTypeclassResolver- theClassResolverto use to load classes- Returns:
- a new instance of the type given by
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.
-
untypedInstanceFromClass
Creates an instance of target class.- Type Parameters:
T- the type of targetSuperType: defines the return type- Parameters:
classToLoad- the class to be instantiated- Returns:
- a new instance of classToLoad
- Throws:
SearchException- wrapping other error types with a proper error message for all kind of problems, like missing proper constructor, securitymanager errors.
-
instanceFromClass
public static <T> T instanceFromClass(Class<T> targetSuperType, Class<?> classToLoad, Map<String, String> constructorParameter) Creates an instance of target class having a Map of strings as constructor parameter. Most of the Analyzer SPIs provided by Lucene have such a constructor.- Type Parameters:
T- the type of targetSuperType: defines the return type- Parameters:
targetSuperType- the created instance will be checked to be assignable to this typeclassToLoad- the class to be instantiatedconstructorParameter- a Map to be passed to the constructor. The loaded type must have such a constructor.- Returns:
- a new instance of classToLoad
- Throws:
SearchException- wrapping other error types with a proper error message for all kind of problems, like missing proper constructor, wrong type, security errors.
-
classForName
public static <T> Class<? extends T> classForName(Class<T> targetSuperType, String classNameToLoad, ClassResolver classResolver)
-