Example usage for org.apache.commons.discovery.resource.names DiscoverServiceNames findResourceNames

List of usage examples for org.apache.commons.discovery.resource.names DiscoverServiceNames findResourceNames

Introduction

In this page you can find the example usage for org.apache.commons.discovery.resource.names DiscoverServiceNames findResourceNames.

Prototype

public ResourceNameIterator findResourceNames(final String serviceName) 

Source Link

Usage

From source file:org.apache.axis.components.encoding.XMLEncoderFactory.java

/**
 Look for file META-INF/services/org.apache.axis.components.encoding.XMLEncoder
 in all the JARS, get the classes listed in those files and add them to 
 encoders list if they are valid encoders. 
        /*from   ww w .  j  av a2s.c  om*/
 Here is how the scheme would work.
        
 A company providing a new encoder will jar up their encoder related
 classes in a JAR file. The following file containing the name of the new 
 encoder class is also made part of this JAR file. 
        
 META-INF/services/org.apache.axis.components.encoding.XMLEncoder
        
 By making this JAR part of the webapp, the new encoder will be 
 automatically discovered. 
 */
private static void loadPluggableEncoders() {
    ClassLoader clzLoader = XMLEncoder.class.getClassLoader();
    ClassLoaders loaders = new ClassLoaders();
    loaders.put(clzLoader);
    DiscoverServiceNames dsn = new DiscoverServiceNames(loaders);
    ResourceNameIterator iter = dsn.findResourceNames(PLUGABLE_PROVIDER_FILENAME);
    while (iter.hasNext()) {
        String className = iter.nextResourceName();
        try {
            Object o = Class.forName(className).newInstance();
            if (o instanceof XMLEncoder) {
                XMLEncoder encoder = (XMLEncoder) o;
                encoderMap.put(encoder.getEncoding(), encoder);
                encoderMap.put(encoder.getEncoding().toLowerCase(), encoder);
            }
        } catch (Exception e) {
            String msg = e + JavaUtils.LS + JavaUtils.stackToString(e);
            log.info(Messages.getMessage("exception01", msg));
            continue;
        }
    }
}

From source file:org.apache.axis.deployment.wsdd.WSDDProvider.java

/**
   Look for file META-INF/services/org.apache.axis.deployment.wsdd.Provider
   in all the JARS, get the classes listed in those files and add them to 
   providers list if they are valid providers. 
        /*from ww w  .ja  va 2s.com*/
   Here is how the scheme would work.
        
   A company providing a new provider will jar up their provider related
   classes in a JAR file. The following file containing the name of the new 
   provider class is also made part of this JAR file. 
        
   META-INF/services/org.apache.axis.deployment.wsdd.Provider
        
   By making this JAR part of the webapp, the new provider will be 
   automatically discovered. 
*/
private static void loadPluggableProviders() {
    ClassLoader clzLoader = WSDDProvider.class.getClassLoader();
    ClassLoaders loaders = new ClassLoaders();
    loaders.put(clzLoader);
    DiscoverServiceNames dsn = new DiscoverServiceNames(loaders);
    ResourceNameIterator iter = dsn.findResourceNames(PLUGABLE_PROVIDER_FILENAME);
    while (iter.hasNext()) {
        String className = iter.nextResourceName();
        try {
            Object o = Class.forName(className).newInstance();
            if (o instanceof WSDDProvider) {
                WSDDProvider provider = (WSDDProvider) o;
                String providerName = provider.getName();
                QName q = new QName(WSDDConstants.URI_WSDD_JAVA, providerName);
                providers.put(q, provider);
            }
        } catch (Exception e) {
            String msg = e + JavaUtils.LS + JavaUtils.stackToString(e);
            log.info(Messages.getMessage("exception01", msg));
            continue;
        }
    }
}