public static class PolicyUtils.ServiceProvider extends Object
Constructor and Description |
---|
PolicyUtils.ServiceProvider() |
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
load(Class<T> serviceClass)
Locates and incrementally instantiates the available providers of a
given service using the context class loader.
|
static <T> T[] |
load(Class<T> serviceClass,
ClassLoader loader)
Locates and incrementally instantiates the available providers of a
given service using the given class loader.
|
public static <T> T[] load(Class<T> serviceClass, ClassLoader loader)
This method transforms the name of the given service class into a provider-configuration filename as described above and then uses the getResources method of the given class loader to find all available files with that name. These files are then read and parsed to produce a list of provider-class names. Eventually each provider class is instantiated and array of those instances is returned.
Because it is possible for extensions to be installed into a running Java virtual machine, this method may return different results each time it is invoked.
serviceClass
- The service's abstract service class. Must not be null
.loader
- The class loader to be used to load provider-configuration files
and instantiate provider classes, or null if the system
class loader (or, failing that the bootstrap class loader) is to
be usedNullPointerException
- in case service
input parameter is null
.ServiceConfigurationError
- If a provider-configuration file violates the specified format
or names a provider class that cannot be found and instantiatedload(Class)
public static <T> T[] load(Class<T> serviceClass)
ClassLoader cl = Thread.currentThread().getContextClassLoader(); return PolicyUtils.ServiceProvider.load(service, cl);
serviceClass
- The service's abstract service class. Must not be null
.NullPointerException
- in case service
input parameter is null
.ServiceConfigurationError
- If a provider-configuration file violates the specified format
or names a provider class that cannot be found and instantiatedload(Class, ClassLoader)
Copyright © 2006-2015 Oracle Corporation. All Rights Reserved.