public class ServiceLoader extends Object
Constructor and Description |
---|
ServiceLoader() |
ServiceLoader(ClassLoader loader) |
ServiceLoader(ClassLoader loader,
LoadErrorHandler handler) |
ServiceLoader(ClassLoader loader,
LoadErrorHandler handler,
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.
|
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.
|
<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, 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 LoadErrorHandler getLoadErrorHandler()
public InputStream getResourceAsStream(String name)
name
- resource namenull
if the resource was not foundClassLoader.getResourceAsStream(String)
public <T> Class<? extends T> getServiceClass(Class<T> iface, String name) throws ClassNotFoundException
iface
- 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-2015 The Apache Software Foundation. All Rights Reserved.