Example usage for org.apache.commons.discovery ResourceClassIterator nextResourceClass

List of usage examples for org.apache.commons.discovery ResourceClassIterator nextResourceClass

Introduction

In this page you can find the example usage for org.apache.commons.discovery ResourceClassIterator nextResourceClass.

Prototype

public abstract ResourceClass nextResourceClass();

Source Link

Usage

From source file:org.apache.axis.AxisProperties.java

public static Object newInstance(final Class spiClass, final Class constructorParamTypes[],
        final Object constructorParams[]) {
    return AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            ResourceClassIterator services = getResourceClassIterator(spiClass);

            Object obj = null;/*from w w w.jav  a2 s.c  o  m*/
            while (obj == null && services.hasNext()) {
                Class service = services.nextResourceClass().loadClass();

                /* service == null
                 * if class resource wasn't loadable
                 */
                if (service != null) {
                    /* OK, class loaded.. attempt to instantiate it.
                     */
                    try {
                        ClassUtils.verifyAncestory(spiClass, service);
                        obj = ClassUtils.newInstance(service, constructorParamTypes, constructorParams);
                    } catch (InvocationTargetException e) {
                        if (e.getTargetException() instanceof java.lang.NoClassDefFoundError) {
                            log.debug(Messages.getMessage("exception00"), e);
                        } else {
                            log.warn(Messages.getMessage("exception00"), e);
                        }
                    } catch (Exception e) {
                        log.warn(Messages.getMessage("exception00"), e);
                    }
                }
            }

            return obj;
        }
    });
}

From source file:org.apache.axis.configuration.EngineConfigurationFactoryFinder.java

/**
 * Create the default engine configuration and detect whether the user
 * has overridden this with their own./*from   ww  w.  j  a v  a 2s . co  m*/
 *
 * The discovery mechanism will use the following logic:
 *
 * - discover all available EngineConfigurationFactories
 *   - find all META-INF/services/org.apache.axis.EngineConfigurationFactory
 *     files available through class loaders.
 *   - read files (see Discovery) to obtain implementation(s) of that
 *     interface
 * - For each impl, call 'newFactory(Object param)'
 * - Each impl should examine the 'param' and return a new factory ONLY
 *   - if it knows what to do with it
 *     (i.e. it knows what to do with the 'real' type)
 *   - it can find it's configuration information
 * - Return first non-null factory found.
 * - Try EngineConfigurationFactoryServlet.newFactory(obj)
 * - Try EngineConfigurationFactoryDefault.newFactory(obj)
 * - If zero found (all return null), throw exception
 *
 * ***
 * This needs more work: System.properties, etc.
 * Discovery will have more tools to help with that
 * (in the manner of use below) in the near future.
 * ***
 *
 */
public static EngineConfigurationFactory newFactory(final Object obj) {
    /**
     * recreate on each call is critical to gaining
     * the right class loaders.  Do not cache.
     */
    final Object[] params = new Object[] { obj };

    /**
     * Find and examine each service
     */
    return (EngineConfigurationFactory) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            ResourceClassIterator services = AxisProperties.getResourceClassIterator(mySpi);

            EngineConfigurationFactory factory = null;

            while (factory == null && services.hasNext()) {
                try {
                    Class service = services.nextResourceClass().loadClass();

                    /* service == null
                     * if class resource wasn't loadable
                     */
                    if (service != null) {
                        factory = newFactory(service, newFactoryParamTypes, params);
                    }
                } catch (Exception e) {
                    // there was an exception creating the factory
                    // the most likely cause was the JDK 1.4 problem
                    // in the discovery code that requires servlet.jar
                    // to be in the client classpath.  For now, fall
                    // through to the next factory
                }
            }

            if (factory != null) {
                if (log.isDebugEnabled()) {
                    log.debug(Messages.getMessage("engineFactory", factory.getClass().getName()));
                }
            } else {
                log.error(Messages.getMessage("engineConfigFactoryMissing"));
                // we should be throwing an exception here,
                //
                // but again, requires more refactoring than we want to swallow
                // at this point in time.  Ifthis DOES occur, it's a coding error:
                // factory should NEVER be null.
                // Testing will find this, as NullPointerExceptions will be generated
                // elsewhere.
            }

            return factory;
        }
    });
}

From source file:picocash.services.ServiceDiscover.java

public static List<Object> getAll(Class<?> clazz) {
    DiscoverClasses clss = new DiscoverClasses();

    ResourceClassIterator iter = clss.findResourceClasses(clazz.getName());
    while (iter.hasNext()) {

        Object object = iter.nextResourceClass().loadClass();
        log.debug(object);/*from w  ww  . j  a v a  2s.co m*/

    }
    return null;
}