public class ServiceLoader extends Object
Constructor and Description |
---|
ServiceLoader() |
ServiceLoader(ClassLoader loader) |
ServiceLoader(ClassLoader loader,
LoadErrorHandler handler) |
ServiceLoader(ClassLoader loader,
LoadErrorHandler handler,
boolean dynamic) |
ServiceLoader(ClassLoader loader,
LoadErrorHandler handler,
InitializableProblemHandler initializableProblemHandler,
boolean dynamic) |
Modifier and Type | Method and Description |
---|---|
Enumeration<URL> |
findServiceResources(String filePattern)
Returns all the available service resources matching the
given pattern, such as all instances of tika-mimetypes.xml
on the classpath, or all org.apache.tika.parser.Parser
service files.
|
InitializableProblemHandler |
getInitializableProblemHandler()
Returns the handler for problems with initializables
|
ClassLoader |
getLoader() |
LoadErrorHandler |
getLoadErrorHandler()
Returns the load error handler used by this loader.
|
InputStream |
getResourceAsStream(String name)
Returns an input stream for reading the specified resource from the
configured class loader.
|
<T> Class<? extends T> |
getServiceClass(Class<T> iface,
String name)
Loads and returns the named service class that's expected to implement
the given interface.
|
protected <T> List<String> |
identifyStaticServiceProviders(Class<T> iface)
Returns the defined static service providers of the given type, without
attempting to load them.
|
boolean |
isDynamic()
Returns if the service loader is static or dynamic
|
<T> List<T> |
loadDynamicServiceProviders(Class<T> iface)
Returns the available dynamic service providers of the given type.
|
<T> List<T> |
loadServiceProviders(Class<T> iface)
Returns all the available service providers of the given type.
|
<T> List<T> |
loadStaticServiceProviders(Class<T> iface)
Returns the available static service providers of the given type.
|
static void |
setContextClassLoader(ClassLoader loader)
Sets the context class loader to use for all threads that access
this class.
|
public ServiceLoader(ClassLoader loader, LoadErrorHandler handler, InitializableProblemHandler initializableProblemHandler, boolean dynamic)
public ServiceLoader(ClassLoader loader, LoadErrorHandler handler, boolean dynamic)
public ServiceLoader(ClassLoader loader, LoadErrorHandler handler)
public ServiceLoader(ClassLoader loader)
public ServiceLoader()
public static void setContextClassLoader(ClassLoader loader)
loader
- default context class loader,
or null
to automatically pick the loaderpublic boolean isDynamic()
public LoadErrorHandler getLoadErrorHandler()
public InitializableProblemHandler getInitializableProblemHandler()
public InputStream getResourceAsStream(String name)
name
- resource namenull
if the resource was not foundClassLoader.getResourceAsStream(String)
public ClassLoader getLoader()
for the context's ClassLoader
public <T> Class<? extends T> getServiceClass(Class<T> iface, String name) throws ClassNotFoundException
LoadErrorHandler
, a
ClassNotFoundException
is always returned for unknown
classes or classes of the wrong typeiface
- service interfacename
- service class nameClassNotFoundException
- if the service class can not be found
or does not implement the given interfaceClass.forName(String, boolean, ClassLoader)
public Enumeration<URL> findServiceResources(String filePattern)
public <T> List<T> loadServiceProviders(Class<T> iface)
iface
- service provider interfacepublic <T> List<T> loadDynamicServiceProviders(Class<T> iface)
iface
- service provider interfaceprotected <T> List<String> identifyStaticServiceProviders(Class<T> iface)
iface
- service provider interfacepublic <T> List<T> loadStaticServiceProviders(Class<T> iface)
iface
- service provider interfaceCopyright © 2007–2021 The Apache Software Foundation. All rights reserved.