org.apache.tika.config
Class ServiceLoader

java.lang.Object
  extended by org.apache.tika.config.ServiceLoader

public class ServiceLoader
extends Object

Internal utility class that Tika uses to look up service providers.

Since:
Apache Tika 0.9

Constructor Summary
ServiceLoader()
           
ServiceLoader(ClassLoader loader)
           
ServiceLoader(ClassLoader loader, LoadErrorHandler handler)
           
ServiceLoader(ClassLoader loader, LoadErrorHandler handler, boolean dynamic)
           
 
Method Summary
 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.
 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.
<T> List<T>
loadServiceProviders(Class<T> iface)
          Returns all the available 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceLoader

public ServiceLoader(ClassLoader loader,
                     LoadErrorHandler handler,
                     boolean dynamic)

ServiceLoader

public ServiceLoader(ClassLoader loader,
                     LoadErrorHandler handler)

ServiceLoader

public ServiceLoader(ClassLoader loader)

ServiceLoader

public ServiceLoader()
Method Detail

setContextClassLoader

public static void setContextClassLoader(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, or null to automatically pick the loader

getResourceAsStream

public InputStream getResourceAsStream(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)

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 interface
name - 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:
Class.forName(String, boolean, ClassLoader)

findServiceResources

public 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.


loadServiceProviders

public <T> List<T> loadServiceProviders(Class<T> iface)
Returns all the available service providers of the given type.

Parameters:
iface - service provider interface
Returns:
available service providers


Copyright © 2007-2012 The Apache Software Foundation. All Rights Reserved.