Class PolicyUtils.ServiceProvider

  • Enclosing class:
    PolicyUtils

    public static class PolicyUtils.ServiceProvider
    extends Object
    Wrapper for ServiceFinder class which is not part of the Java SE yet.
    • Constructor Detail

      • ServiceProvider

        public ServiceProvider()
    • Method Detail

      • load

        public static <T> T[] load​(Class<T> serviceClass,
                                   ClassLoader loader)
        Locates and incrementally instantiates the available providers of a given service using the given class loader.

        This method transforms the name of the given service class into a provider-configuration filename as described above and then uses the getResources method of the given class loader to find all available files with that name. These files are then read and parsed to produce a list of provider-class names. Eventually each provider class is instantiated and array of those instances is returned.

        Because it is possible for extensions to be installed into a running Java virtual machine, this method may return different results each time it is invoked.

        Parameters:
        serviceClass - The service's abstract service class. Must not be null.
        loader - The class loader to be used to load provider-configuration files and instantiate provider classes, or null if the system class loader (or, failing that the bootstrap class loader) is to be used
        Throws:
        NullPointerException - in case service input parameter is null.
        ServiceConfigurationError - If a provider-configuration file violates the specified format or names a provider class that cannot be found and instantiated
        See Also:
        load(Class)
      • load

        public static <T> T[] load​(Class<T> serviceClass)
        Locates and incrementally instantiates the available providers of a given service using the context class loader. This convenience method is equivalent to

           ClassLoader cl = Thread.currentThread().getContextClassLoader();
           return PolicyUtils.ServiceProvider.load(service, cl);
         
        Parameters:
        serviceClass - The service's abstract service class. Must not be null.
        Throws:
        NullPointerException - in case service input parameter is null.
        ServiceConfigurationError - If a provider-configuration file violates the specified format or names a provider class that cannot be found and instantiated
        See Also:
        load(Class, ClassLoader)