Package org.forgerock.util
Class Loader
java.lang.Object
org.forgerock.util.Loader
Provides methods for dynamically loading classes.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>
Returns theClass
object associated with the class or interface with the given name, ornull
if the class could not be returned for any reason.static ClassLoader
Returns the class loader that should be used consistently throughout the application.static URL
getResource
(String name) Finds the resource with the given name.static <E> List<E>
Loads services of a particular type into a list.static <E> List<E>
loadList
(Class<E> serviceType, ClassLoader classLoader) Loads services of a particular type into a list.Loads services of a particular type into a map.loadMap
(Class<V> serviceType, ClassLoader classLoader) Loads services of a particular type into a map.static Object
newInstance
(String name) Creates a new instance of a named class.static <T> T
newInstance
(String name, Class<T> type) Creates a new instance of a named class.
-
Method Details
-
getClassLoader
Returns the class loader that should be used consistently throughout the application.- Returns:
- the class loader that should be used consistently throughout the application.
-
getClass
Returns theClass
object associated with the class or interface with the given name, ornull
if the class could not be returned for any reason.- Parameters:
name
- the fully qualified name of the desired class.- Returns:
- the Class object for the class with the specified name.
-
newInstance
Creates a new instance of a named class. The class is instantiated as if by anew
expression with an empty argument list. If the class cannot be instantiated for any reason,null
is returned.- Parameters:
name
- the fully qualified name of the class to instantiate.- Returns:
- the newly instantiated object, or
null
if it could not be instantiated.
-
newInstance
Creates a new instance of a named class. The class is instantiated as if by anew
expression with an empty argument list. If the class cannot be instantiated for any reason,null
is returned.- Type Parameters:
T
- class type- Parameters:
name
- the fully qualified name of the class to instantiate.type
- the class of the type of object to instantiate.- Returns:
- the newly instantiated object, or
null
if it could not be instantiated.
-
loadMap
Loads services of a particular type into a map. Such services implement theIndexed
interface to provide a key to index the service by in the map.- Type Parameters:
K
- key typeV
- service type- Parameters:
serviceType
- the class type of services to load.- Returns:
- a map containing the loaded services, indexed by the services' keys.
-
loadMap
public static <K,V extends Indexed<K>> Map<K,V> loadMap(Class<V> serviceType, ClassLoader classLoader) Loads services of a particular type into a map. Such services implement theIndexed
interface to provide a key to index the service by in the map.- Type Parameters:
K
- key typeV
- service type- Parameters:
serviceType
- the class type of services to load.classLoader
- The classLoader to use.- Returns:
- a map containing the loaded services, indexed by the services' keys.
-
loadList
Loads services of a particular type into a list.- Type Parameters:
E
- service type- Parameters:
serviceType
- the class type of services to load.- Returns:
- a list containing the loaded services.
-
loadList
Loads services of a particular type into a list.- Type Parameters:
E
- service type- Parameters:
serviceType
- the class type of services to load.classLoader
- the classLoader to use.- Returns:
- a list containing the loaded services.
-
getResource
Finds the resource with the given name.- Parameters:
name
- the resource name.- Returns:
- A
URL
object for reading the resource, ornull
if the resource could not be found. - See Also:
-