Example usage for java.lang ClassLoader getResources

List of usage examples for java.lang ClassLoader getResources

Introduction

In this page you can find the example usage for java.lang ClassLoader getResources.

Prototype

public Enumeration<URL> getResources(String name) throws IOException 

Source Link

Document

Finds all the resources with the given name.

Usage

From source file:org.richfaces.tests.metamer.ftest.extension.attributes.collector.taglib.AttributesCollectorFromTaglib.java

private List<URL> getTaglibFiles(String... resources) throws IOException {
    ClassLoader cl = UIStatus.class.getClassLoader();
    List<URL> taglibFiles = Lists.newArrayList();
    for (String resource : resources) {
        Enumeration<URL> resourceURLs = cl.getResources(resource);
        while (resourceURLs.hasMoreElements()) {
            URL url = resourceURLs.nextElement();
            if (url.getPath().matches(RICHFACES_JAR_REGEXP)) {
                taglibFiles.add(url);/*  ww w.ja  v  a2s.co m*/
            }
        }
    }
    return taglibFiles;
}

From source file:com.agimatec.validation.jsr303.xml.ValidationParser.java

private InputStream getInputStream(String path) throws IOException {
    ClassLoader loader = PrivilegedActions.getClassLoader(getClass());
    Enumeration<URL> urls = loader.getResources(path);
    if (urls.hasMoreElements()) {
        URL url = urls.nextElement();
        if (urls.hasMoreElements()) {
            // spec says: If more than one META-INF/validation.xml file
            // is found in the classpath, a ValidationException is raised.
            throw new ValidationException("More than one " + path + " is found in the classpath");
        }/*ww  w.  j av  a2s .c o  m*/
        return url.openStream();
    } else {
        return null;
    }
}

From source file:org.apache.nutch.webapp.common.PluginResourceLoader.java

public Enumeration getResources(String name) throws IOException {
    Iterator i = classloaders.iterator();

    while (i.hasNext()) {
        ClassLoader loader = (ClassLoader) i.next();
        Enumeration retVal = loader.getResources(name);
        if (retVal != null) {
            return retVal;
        }// w ww.  ja v a2  s . c o  m
    }
    return null;
}

From source file:de.klemp.middleware.controller.Controller.java

/**
 * !!!! Important Method for creating new classes !!!! This method returns
 * the different classes of the first and second component. If a new class
 * is created, then it has to be added into this method. This method is
 * needed for the GUI. Method which use this method: getClassNames(...),
 * searchMethods(), getMethod()//from w w  w .  j  a  v a2  s .  c  o  m
 * 
 * @param component
 *            1 or 2
 * @return ArrayList: list with objects of the classes
 */
private static ArrayList<Object> getClasses(String component) {
    // http://tutorials.jenkov.com/java-reflection/dynamic-class-loading-reloading.html
    // http://stackoverflow.com/questions/1456930/how-do-i-read-all-classes-from-a-java-package-in-the-classpath
    // http://www.dzone.com/snippets/get-all-classes-within-package
    ArrayList<Object> classes = new ArrayList<Object>();
    Enumeration<URL> urls;
    try {
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        urls = loader.getResources(component);
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            File file = new File(url.getFile());
            File[] files = file.listFiles();
            for (int i = 0; i < files.length; i++) {
                String[] f = files[i].getName().split("\\.");
                Class c;

                try {
                    c = loader.loadClass(component + "." + f[0]);
                    classes.add(c.newInstance());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                    logger.error("Classes could not be refreshed", e);
                }

            }
        }
    } catch (IOException e) {
        logger.error("SQL Exception", e);
    }
    return classes;

}

From source file:com.haulmont.cuba.desktop.sys.DesktopExternalUIComponentsSource.java

protected void _registerComponents(String componentDescriptorPath) throws IOException, ClassNotFoundException {
    ClassLoader classLoader = App.class.getClassLoader();
    Enumeration<URL> resources = classLoader.getResources(componentDescriptorPath);
    while (resources.hasMoreElements()) {
        URL url = resources.nextElement();
        try (InputStream is = url.openStream()) {
            _registerComponent(is);//from w ww  .  j av  a2  s  .  c  o m
        }
    }
}

From source file:org.nuxeo.ecm.webengine.loader.store.ResourceStoreClassLoader.java

@Override
public Enumeration<URL> getResources(String name) throws IOException {
    Enumeration<URL> urls = findResources(name);
    if (urls == null) {
        final ClassLoader parent = getParent();
        if (parent != null) {
            urls = parent.getResources(name);
        }//from   ww w  .  j  a v a2 s. c o  m
    }
    return urls;
}

From source file:com.appleframework.jmx.connector.framework.ConnectorRegistry.java

@SuppressWarnings("deprecation")
private void loadMetadata(ClassLoader cl) throws Exception {
    // Fix a bug in the Registry class
    try {/*from   www .  j  a  v  a 2 s  .  c  o m*/
        Enumeration<?> en = cl.getResources(MODELER_MANIFEST);
        while (en.hasMoreElements()) {
            URL url = (URL) en.nextElement();
            InputStream is = url.openStream();
            loadDescriptors("MbeansDescriptorsDOMSource", is, null);
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        throw ex;
    }
}

From source file:org.apache.xmlgraphics.util.ClasspathResource.java

private void loadManifests() {
        Enumeration e;//from   ww  w .j av a 2 s. c  om
        try {

            Iterator it = getClassLoadersForResources().iterator();
            while (it.hasNext()) {
                ClassLoader classLoader = (ClassLoader) it.next();

                e = classLoader.getResources(MANIFEST_PATH);

                while (e.hasMoreElements()) {
                    final URL u = (URL) e.nextElement();
                    try {
                        final Manifest manifest = new Manifest(u.openStream());
                        final Map entries = manifest.getEntries();
                        final Iterator entrysetiterator = entries.entrySet().iterator();
                        while (entrysetiterator.hasNext()) {
                            final Map.Entry entry = (Map.Entry) entrysetiterator.next();
                            final String name = (String) entry.getKey();
                            final Attributes attributes = (Attributes) entry.getValue();
                            final String contentType = attributes.getValue(CONTENT_TYPE_KEY);
                            if (contentType != null) {
                                addToMapping(contentType, name, classLoader);
                            }
                        }
                    } catch (IOException io) {
                        // TODO: Log.
                    }
                }
            }

        } catch (IOException io) {
            // TODO: Log.
        }
    }

From source file:org.mule.module.launcher.application.CompositeApplicationClassLoader.java

@Override
public Enumeration<URL> getResources(String s) throws IOException {
    final Map<String, URL> resources = new HashMap<String, URL>();

    for (ClassLoader classLoader : classLoaders) {
        Enumeration<URL> partialResources = classLoader.getResources(s);

        while (partialResources.hasMoreElements()) {
            URL url = partialResources.nextElement();
            if (resources.get(url.toString()) == null) {
                resources.put(url.toString(), url);
            }//w w  w.  java  2 s .  c o m
        }
    }

    return new EnumerationAdapter<URL>(resources.values());
}

From source file:org.callimachusproject.xproc.Pipeline.java

private void loadConfig(XdmNodeFactory resolver, XProcConfiguration config) throws IOException {
    ClassLoader cl = getClass().getClassLoader();
    Enumeration<URL> resources = cl.getResources("META-INF/xmlcalabash.xml");
    while (resources.hasMoreElements()) {
        try {//w w w. j  a  v  a2s.  c  om
            URL puri = resources.nextElement();
            InputStream in = puri.openStream();
            config.parse(resolver.parse(puri.toExternalForm(), in));
        } catch (SAXException sae) {
            throw new XProcException(sae);
        }
    }
}