Example usage for org.apache.commons.discovery.tools Service providers

List of usage examples for org.apache.commons.discovery.tools Service providers

Introduction

In this page you can find the example usage for org.apache.commons.discovery.tools Service providers.

Prototype

public static Enumeration providers(final SPInterface spi, ClassLoaders loaders) 

Source Link

Document

This version lets you specify constructor arguments..

Usage

From source file:org.codehaus.cargo.generic.AbstractFactoryRegistry.java

/**
 * Lists up {@link AbstractFactoryRegistry}s that are discovered.
 * // w ww. j  av  a 2 s .  c  om
 * @param classLoader See {@link #register(ClassLoader, DeployableFactory)} for more details.
 * @return always non-null but can be empty.
 */
private static List<AbstractFactoryRegistry> list(ClassLoader classLoader) {
    ClassLoader cl;
    ClassLoaders loaders = new ClassLoaders();

    cl = classLoader;
    if (cl != null) {
        loaders.put(cl);
    }

    cl = Thread.currentThread().getContextClassLoader();
    if (cl != null) {
        loaders.put(cl);
    }

    cl = AbstractFactoryRegistry.class.getClassLoader();
    if (cl != null) {
        loaders.put(cl);
    }

    cl = ResourceUtils.getResourceLoader();
    if (cl != null) {
        loaders.put(cl);
    }

    cl = JDKHooks.getJDKHooks().getSystemClassLoader();
    if (cl != null) {
        loaders.put(cl);
    }

    if (loaders.size() == 0) {
        // this is not our day. bail out.
        return Collections.EMPTY_LIST;
    }

    List<AbstractFactoryRegistry> registries = new ArrayList<AbstractFactoryRegistry>();
    Enumeration providers = Service.providers(new SPInterface(AbstractFactoryRegistry.class), loaders);
    while (providers.hasMoreElements()) {
        Object provider = providers.nextElement();
        if (provider instanceof AbstractFactoryRegistry) {
            registries.add((AbstractFactoryRegistry) provider);
        }
    }

    return registries;
}