Package org.apache.tika.config
Class ServiceLoader
java.lang.Object
org.apache.tika.config.ServiceLoader
Internal utility class that Tika uses to look up service providers.
Supports both static service loading using the
ServiceLoader mechanism (and via
OSGi Service Loader Mediator)
as well as dynamic loading via OSGi service tracking (from the TikaActivator class).- Since:
- Apache Tika 0.9
-
Constructor Summary
ConstructorsConstructorDescriptionServiceLoader(ClassLoader loader) ServiceLoader(ClassLoader loader, boolean dynamic) -
Method Summary
Modifier and TypeMethodDescriptionfindServiceResources(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.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.identifyStaticServiceProviders(Class<T> iface) Returns the defined static service providers of the given type, without attempting to load them.booleanReturns 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) <T> List<T>loadStaticServiceProviders(Class<T> iface, Collection<Class<? extends T>> excludes) Returns the available static service providers of the given type.static voidsetContextClassLoader(ClassLoader loader) Sets the context class loader to use for all threads that access this class.
-
Constructor Details
-
ServiceLoader
-
ServiceLoader
-
ServiceLoader
public ServiceLoader()
-
-
Method Details
-
setContextClassLoader
Sets the context class loader to use for all threads that access this class. Used for example in an OSGi environment to avoid problems with the default context class loader.- Parameters:
loader- default context class loader, ornullto automatically pick the loader
-
isDynamic
public boolean isDynamic()Returns if the service loader is static or dynamic- Returns:
- dynamic or static loading
- Since:
- Apache Tika 1.10
-
getResourceAsStream
Returns an input stream for reading the specified resource from the configured class loader.- Parameters:
name- resource name- Returns:
- input stream, or
nullif the resource was not found - Since:
- Apache Tika 1.1
- See Also:
-
getLoader
- Returns:
- ClassLoader used by this ServiceLoader
- Since:
- Apache Tika 1.15.1
- See Also:
-
for the context's ClassLoader
-
getServiceClass
public <T> Class<? extends T> getServiceClass(Class<T> iface, String name) throws ClassNotFoundException Loads and returns the named service class that's expected to implement the given interface.- Parameters:
iface- service interfacename- service class name- Returns:
- service class
- Throws:
ClassNotFoundException- if the service class can not be found or does not implement the given interface- Since:
- Apache Tika 1.1
- See Also:
-
findServiceResources
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. -
loadServiceProviders
Returns all the available service providers of the given type. As of versions after 2.4.1, this removes duplicate classes- Parameters:
iface- service provider interface- Returns:
- available service providers
-
loadDynamicServiceProviders
Returns the available dynamic service providers of the given type. The returned list is newly allocated and may be freely modified by the caller.- Parameters:
iface- service provider interface- Returns:
- dynamic service providers
- Since:
- Apache Tika 1.2
-
identifyStaticServiceProviders
Returns the defined static service providers of the given type, without attempting to load them. The providers are loaded using the service provider mechanism using the configured class loader (if any).- Parameters:
iface- service provider interface- Returns:
- static list of uninitialised service providers
- Since:
- Apache Tika 1.6
-
loadStaticServiceProviders
-
loadStaticServiceProviders
public <T> List<T> loadStaticServiceProviders(Class<T> iface, Collection<Class<? extends T>> excludes) Returns the available static service providers of the given type. The providers are loaded using the service provider mechanism using the configured class loader (if any). The returned list is newly allocated and may be freely modified by the caller.- Parameters:
iface- service provider interfaceexcludes- -- do not load these classes- Returns:
- static service providers
- Since:
- Apache Tika 1.2
-