Example usage for org.apache.commons.discovery.resource ClassLoaders size

List of usage examples for org.apache.commons.discovery.resource ClassLoaders size

Introduction

In this page you can find the example usage for org.apache.commons.discovery.resource ClassLoaders size.

Prototype

public int size() 

Source Link

Usage

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

/**
 * Lists up {@link AbstractFactoryRegistry}s that are discovered.
 * /*from   w  ww  .  jav a  2s  .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;
}