net.sourceforge.fluxion.spi.utils
Class SPIUtils

java.lang.Object
  extended by net.sourceforge.fluxion.spi.utils.SPIUtils

public class SPIUtils
extends java.lang.Object

Utils classes for accessing methods related to this implementation of the Sun SPI framework. This class provides static methods for service discovery and instantiation.

For example:


 // loop over all providers
 for(MyService ms: SPIUtils.getServiceProviders(MyService.class))
 {
   ...
 }
 

Author:
Tony Burdett, Matthew Pocock

Constructor Summary
SPIUtils()
           
 
Method Summary
static
<SPI> java.util.Set<java.lang.Class<? extends SPI>>
getServiceProviderClasses(java.lang.Class<SPI> spi)
          Get a Set of all the classes that are providers for this Spi using the current ClassLoader.
static
<SPI> java.util.Set<java.lang.Class<? extends SPI>>
getServiceProviderClasses(java.lang.ClassLoader loader, java.lang.Class<SPI> spi)
          Get a Set of all the classes that are providers for this Spi using the supplied ClassLoader.
static
<SPI> java.util.Set<SPI>
getServiceProviders(java.lang.Class<SPI> spi)
          Get a Set of all providers in the current classpath for the suppied SPI.
static
<SPI> java.util.Set<SPI>
getServiceProviders(java.lang.ClassLoader loader, java.lang.Class<SPI> spi)
          Get a Set of all providers present in the specified class loader for the given SPI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SPIUtils

public SPIUtils()
Method Detail

getServiceProviders

public static <SPI> java.util.Set<SPI> getServiceProviders(java.lang.Class<SPI> spi)
                                              throws ServiceConfigurationError
Get a Set of all providers in the current classpath for the suppied SPI. Any providers found will be loaded and instantiated when this method is invoked, so a set of ready-created instances will be returned.

Parameters:
spi - the SPI to discover providers for
Returns:
an Set of all providers
Throws:
ServiceConfigurationError - if any of the providers could not be loaded

getServiceProviders

public static <SPI> java.util.Set<SPI> getServiceProviders(java.lang.ClassLoader loader,
                                                           java.lang.Class<SPI> spi)
                                              throws ServiceConfigurationError
Get a Set of all providers present in the specified class loader for the given SPI. Any providers found will be loaded when this method is invoked.

Parameters:
loader - the ClassLoader to scan for providers
spi - The SPI to locate providers for
Returns:
an Set over all providers
Throws:
ServiceConfigurationError - if any of the providers could not be loaded

getServiceProviderClasses

public static <SPI> java.util.Set<java.lang.Class<? extends SPI>> getServiceProviderClasses(java.lang.Class<SPI> spi)
                                                                               throws ServiceConfigurationError
Get a Set of all the classes that are providers for this Spi using the current ClassLoader. These classes will be returned directly, the caller should take responsibility for instantianting them.

Parameters:
spi - the SPI class to locate
Returns:
a Set of the Spi classes
Throws:
ServiceConfigurationError - if the classes listed as SPIs could not be loaded

getServiceProviderClasses

public static <SPI> java.util.Set<java.lang.Class<? extends SPI>> getServiceProviderClasses(java.lang.ClassLoader loader,
                                                                                            java.lang.Class<SPI> spi)
                                                                               throws ServiceConfigurationError
Get a Set of all the classes that are providers for this Spi using the supplied ClassLoader. These classes will be returned directly, the caller should take responsibility for instantianting them.

Parameters:
loader - the ClassLoader to scan for providers
spi - the SPI to locate providers for
Returns:
an Iterable over the Spi classes
Throws:
ServiceConfigurationError - if the classes listed as SPIs could not be loaded


Copyright © 2010. All Rights Reserved.