Example usage for org.apache.commons.discovery.jdk JDKHooks getJDKHooks

List of usage examples for org.apache.commons.discovery.jdk JDKHooks getJDKHooks

Introduction

In this page you can find the example usage for org.apache.commons.discovery.jdk JDKHooks getJDKHooks.

Prototype

public static final JDKHooks getJDKHooks() 

Source Link

Document

Return singleton object representing JVM hooks/tools.

Usage

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

/**
 * Lists up {@link AbstractFactoryRegistry}s that are discovered.
 * /*w ww . ja  v  a2 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;
}