Package org.apache.tika.config
Class ServiceLoader
- java.lang.Object
-
- org.apache.tika.config.ServiceLoader
-
public class ServiceLoader extends java.lang.Object
Internal utility class that Tika uses to look up service providers.- Since:
- Apache Tika 0.9
-
-
Constructor Summary
Constructors Constructor Description ServiceLoader()
ServiceLoader(java.lang.ClassLoader loader)
ServiceLoader(java.lang.ClassLoader loader, LoadErrorHandler handler)
ServiceLoader(java.lang.ClassLoader loader, LoadErrorHandler handler, boolean dynamic)
ServiceLoader(java.lang.ClassLoader loader, LoadErrorHandler handler, InitializableProblemHandler initializableProblemHandler, boolean dynamic)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Enumeration<java.net.URL>
findServiceResources(java.lang.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 initializablesjava.lang.ClassLoader
getLoader()
LoadErrorHandler
getLoadErrorHandler()
Returns the load error handler used by this loader.java.io.InputStream
getResourceAsStream(java.lang.String name)
Returns an input stream for reading the specified resource from the configured class loader.<T> java.lang.Class<? extends T>
getServiceClass(java.lang.Class<T> iface, java.lang.String name)
Loads and returns the named service class that's expected to implement the given interface.boolean
isDynamic()
Returns if the service loader is static or dynamic<T> java.util.List<T>
loadDynamicServiceProviders(java.lang.Class<T> iface)
Returns the available dynamic service providers of the given type.<T> java.util.List<T>
loadServiceProviders(java.lang.Class<T> iface)
Returns all the available service providers of the given type.<T> java.util.List<T>
loadStaticServiceProviders(java.lang.Class<T> iface)
Returns the available static service providers of the given type.static void
setContextClassLoader(java.lang.ClassLoader loader)
Sets the context class loader to use for all threads that access this class.
-
-
-
Constructor Detail
-
ServiceLoader
public ServiceLoader(java.lang.ClassLoader loader, LoadErrorHandler handler, InitializableProblemHandler initializableProblemHandler, boolean dynamic)
-
ServiceLoader
public ServiceLoader(java.lang.ClassLoader loader, LoadErrorHandler handler, boolean dynamic)
-
ServiceLoader
public ServiceLoader(java.lang.ClassLoader loader, LoadErrorHandler handler)
-
ServiceLoader
public ServiceLoader(java.lang.ClassLoader loader)
-
ServiceLoader
public ServiceLoader()
-
-
Method Detail
-
setContextClassLoader
public static void setContextClassLoader(java.lang.ClassLoader loader)
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, ornull
to 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
-
getLoadErrorHandler
public LoadErrorHandler getLoadErrorHandler()
Returns the load error handler used by this loader.- Returns:
- load error handler
- Since:
- Apache Tika 1.3
-
getInitializableProblemHandler
public InitializableProblemHandler getInitializableProblemHandler()
Returns the handler for problems with initializables- Returns:
- handler for problems with initializables
- Since:
- Apache Tika 1.15.1
-
getResourceAsStream
public java.io.InputStream getResourceAsStream(java.lang.String name)
Returns an input stream for reading the specified resource from the configured class loader.- Parameters:
name
- resource name- Returns:
- input stream, or
null
if the resource was not found - Since:
- Apache Tika 1.1
- See Also:
ClassLoader.getResourceAsStream(String)
-
getLoader
public java.lang.ClassLoader getLoader()
- Returns:
- ClassLoader used by this ServiceLoader
- Since:
- Apache Tika 1.15.1
- See Also:
for the context's ClassLoader
-
getServiceClass
public <T> java.lang.Class<? extends T> getServiceClass(java.lang.Class<T> iface, java.lang.String name) throws java.lang.ClassNotFoundException
Loads and returns the named service class that's expected to implement the given interface. Note that this class does not use theLoadErrorHandler
, aClassNotFoundException
is always returned for unknown classes or classes of the wrong type- Parameters:
iface
- service interfacename
- service class name- Returns:
- service class
- Throws:
java.lang.ClassNotFoundException
- if the service class can not be found or does not implement the given interface- Since:
- Apache Tika 1.1
- See Also:
Class.forName(String, boolean, ClassLoader)
-
findServiceResources
public java.util.Enumeration<java.net.URL> findServiceResources(java.lang.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.
-
loadServiceProviders
public <T> java.util.List<T> loadServiceProviders(java.lang.Class<T> iface)
Returns all the available service providers of the given type.- Parameters:
iface
- service provider interface- Returns:
- available service providers
-
loadDynamicServiceProviders
public <T> java.util.List<T> loadDynamicServiceProviders(java.lang.Class<T> iface)
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
-
loadStaticServiceProviders
public <T> java.util.List<T> loadStaticServiceProviders(java.lang.Class<T> iface)
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 interface- Returns:
- static service providers
- Since:
- Apache Tika 1.2
-
-