org.ops4j.spi
Class ServiceProviderFinder

java.lang.Object
  extended by org.ops4j.spi.ServiceProviderFinder

public class ServiceProviderFinder
extends Object

Convenience methods for obtaining implementations of a given service via ServiceLoader. A service is defined by an interface or an abstract class.

Author:
Harald Wellmann

Constructor Summary
ServiceProviderFinder()
           
 
Method Summary
static
<T> T
findAnyServiceProvider(Class<T> klass)
          Finds any provider for a given service.
static
<T> List<T>
findServiceProviders(Class<T> klass)
          Finds all providers for a given service.
static
<T> T
loadAnyServiceProvider(Class<T> klass)
          Returns any provider for a given service and throws an exception when no provider is found on the classpath.
static
<T> T
loadUniqueServiceProvider(Class<T> klass)
          Returns the unique service provider for a given service and throws an exception if there is no unique provider
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceProviderFinder

public ServiceProviderFinder()
Method Detail

findServiceProviders

public static <T> List<T> findServiceProviders(Class<T> klass)
Finds all providers for a given service.

Parameters:
klass - service interface or class
Returns:
list of all providers (not null)

findAnyServiceProvider

public static <T> T findAnyServiceProvider(Class<T> klass)
Finds any provider for a given service.

Parameters:
klass - service interface or class
Returns:
the first provider found, or null

loadAnyServiceProvider

public static <T> T loadAnyServiceProvider(Class<T> klass)
Returns any provider for a given service and throws an exception when no provider is found on the classpath.

Parameters:
klass - service interface or class
Returns:
the first provider found
Throws:
NoServiceProviderException

loadUniqueServiceProvider

public static <T> T loadUniqueServiceProvider(Class<T> klass)
Returns the unique service provider for a given service and throws an exception if there is no unique provider

Parameters:
klass - service interface or class
Returns:
the first provider found
Throws:
NoServiceProviderException
NonUniqueServiceProviderException


Copyright © 2006-2013 OPS4J - Open Participation Software for Java. All Rights Reserved.