Package org.apache.commons.discovery

Examples of org.apache.commons.discovery.ResourceIterator


         * Look for the keystore in classpaths
         */
        DiscoverResources disc = new DiscoverResources();
        disc.addClassLoader(JDKHooks.getJDKHooks().getThreadContextClassLoader());
        disc.addClassLoader(loader);
        ResourceIterator iterator = disc.findResources(location);
        if (iterator.hasNext()) {
            Resource resource = iterator.nextResource();
            is = resource.getResourceAsStream();
        }

        /**
         * If we don't find it, then look on the file system.
View Full Code Here


         * Look for the keystore in classpaths
         */
        DiscoverResources disc = new DiscoverResources();
        disc.addClassLoader(JDKHooks.getJDKHooks().getThreadContextClassLoader());
        disc.addClassLoader(this.getClass().getClassLoader());
        ResourceIterator iterator = disc.findResources(location);
        if (iterator.hasNext()) {
            Resource resource = iterator.nextResource();
            is = resource.getResourceAsStream();
        }
       
        /**
         * If we don't find it, then look on the file system.
View Full Code Here

                DiscoverResources disc = new DiscoverResources();
                disc.addClassLoader(JDKHooks.getJDKHooks()
                        .getThreadContextClassLoader());
                disc.addClassLoader(classLoader);

                ResourceIterator iterator = disc
                        .findResources(keyStorelocation);
                if (iterator.hasNext()) {
                    Resource resource = iterator.nextResource();
                    is = resource.getResourceAsStream();
                }

                if (is == null) {
                    iterator = disc.findResources("META-INF/"
                            + keyStorelocation);
                    if (iterator.hasNext()) {
                        Resource resource = iterator.nextResource();
                        is = resource.getResourceAsStream();
                    }
                }
            }
            if (is == null) {
View Full Code Here

     *
     * @param inputNames The resources name iterator has to be located
     * @return The located resources iterator
     */
    public ResourceIterator findResources(final ResourceNameIterator inputNames) {
        return new ResourceIterator() {

            private ResourceIterator resources = null;

            private Resource resource = null;

View Full Code Here

    public ResourceIterator findResources(final String resourceName) {
        if (log.isDebugEnabled()) {
            log.debug("find: resourceName='" + resourceName + "'");
        }

        return new ResourceIterator() {

            private int idx = 0;

            private ClassLoader loader = null;
View Full Code Here

                log.debug("find: serviceName = '" + fileName + "'");
            }
        }


        final ResourceIterator files =
            getDiscover().findResources(fileName);

        return new ResourceNameIterator() {

            private int idx = 0;

            private List<String> classNames = null;

            private String resource = null;

            public boolean hasNext() {
                if (resource == null) {
                    resource = getNextClassName();
                }
                return resource != null;
            }

            public String nextResourceName() {
                String element = resource;
                resource = null;
                return element;
            }

            private String getNextClassName() {
                if (classNames == null || idx >= classNames.size()) {
                    classNames = getNextClassNames();
                    idx = 0;
                    if (classNames == null) {
                        return null;
                    }
                }

                String className = classNames.get(idx++);

                if (log.isDebugEnabled()) {
                    log.debug("getNextClassResource: next class='" + className + "'");
                }

                return className;
            }

            private List<String> getNextClassNames() {
                while (files.hasNext()) {
                    List<String> results = readServices(files.nextResource());
                    if (results != null  &&  results.size() > 0) {
                        return results;
                    }
                }
                return null;
View Full Code Here

     */
    public static Resource getResource(Class<?> spi,
                                       String resourceName,
                                       ClassLoaders loaders) throws DiscoveryException {
        DiscoverResources explorer = new DiscoverResources(loaders);
        ResourceIterator resources = explorer.findResources(resourceName);

        if (spi != null  &&
            !resources.hasNext()  &&
            resourceName.charAt(0) != '/') {
            /**
             * If we didn't find the resource, and if the resourceName
             * isn't an 'absolute' path name, then qualify with
             * package name of the spi.
             */
            resourceName = getPackageName(spi).replace('.','/') + "/" + resourceName;
            resources = explorer.findResources(resourceName);
        }

        return resources.hasNext()
               ? resources.nextResource()
               : null;
    }
View Full Code Here

       
        String partialPaths[] = { "/test/", "/testAlt1/", "/testAlt2/" };
        int expected = partialPaths.length;
       
        DiscoverResources discovery = new DiscoverResources(loaders);
        ResourceIterator iter = discovery.findResources(name);
        int count = 0;
       
        while (iter.hasNext()) {
            Resource resource = iter.nextResource();
            URL url = resource.getResource();
            if ( url != null ) {
                if (url.getFile().indexOf(partialPaths[count]) == -1) {
                    fail(url + " does not contain " + partialPaths[count]);
                }
View Full Code Here

                                       String resourceName,
                                       ClassLoaders loaders)
        throws DiscoveryException
    {
        DiscoverResources explorer = new DiscoverResources(loaders);
        ResourceIterator resources = explorer.findResources(resourceName);
       
        if (spi != null  &&
            !resources.hasNext()  &&
            resourceName.charAt(0) != '/')
        {
            /**
             * If we didn't find the resource, and if the resourceName
             * isn't an 'absolute' path name, then qualify with
             * package name of the spi.
             */
            resourceName = getPackageName(spi).replace('.','/') + "/" + resourceName;
            resources = explorer.findResources(resourceName);
        }
       
        return resources.hasNext()
               ? resources.nextResource()
               : null;
    }
View Full Code Here

     */
    public ResourceIterator findResources(final String resourceName) {
        if (log.isDebugEnabled())
            log.debug("find: resourceName='" + resourceName + "'");

        return new ResourceIterator() {
            private int idx = 0;
            private ClassLoader loader = null;
            private Enumeration resources = null;
            private Resource resource = null;
           
View Full Code Here

TOP

Related Classes of org.apache.commons.discovery.ResourceIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.