Example usage for java.util Enumeration Enumeration

List of usage examples for java.util Enumeration Enumeration

Introduction

In this page you can find the example usage for java.util Enumeration Enumeration.

Prototype

Enumeration

Source Link

Usage

From source file:com.zz.globalsession.GlobalHttpSession.java

@Override
public Enumeration<?> getAttributeNames() {
    if (isValid()) {
        final Iterator<String> names = attributes.keySet().iterator();
        return new Enumeration<Object>() {

            public boolean hasMoreElements() {
                return names.hasNext();
            }/*from   ww  w. j  av a 2  s  .co m*/

            public Object nextElement() {
                return names.next();
            }
        };
    } else {
        return new Enumeration<Object>() {

            public boolean hasMoreElements() {
                return false;
            }

            public Object nextElement() {
                return null;
            }
        };
    }
}

From source file:ch.cyberduck.core.dav.DAVResource.java

@Override
protected void setWebdavProperties(final Enumeration responses) throws HttpException, IOException {

    super.setWebdavProperties(new Enumeration() {
        public boolean hasMoreElements() {
            return responses.hasMoreElements();
        }//from   w  ww . j  a v  a  2s . c  o m

        public Object nextElement() {
            final ResponseEntity response = (ResponseEntity) responses.nextElement();
            return new ResponseEntity() {

                public int getStatusCode() {
                    return response.getStatusCode();
                }

                public Enumeration getProperties() {
                    return response.getProperties();
                }

                public Enumeration getHistories() {
                    return response.getHistories();
                }

                public Enumeration getWorkspaces() {
                    return response.getWorkspaces();
                }

                public String getHref() {
                    if (StringUtils.isNotBlank(response.getHref())) {
                        // http://trac.cyberduck.ch/ticket/2223
                        final String escaped = StringUtils.replace(response.getHref(), " ", "%20");
                        try {
                            new java.net.URI(escaped);
                        } catch (URISyntaxException e) {
                            log.warn("Href not escaped in respose:" + response.getHref());
                            try {
                                return URIUtil.encodePath(response.getHref());
                            } catch (URIException failure) {
                                log.error("Encoding path failed:" + failure.getMessage());
                            }
                        }
                        return escaped;
                    }
                    return response.getHref();
                }
            };
        }
    });
}

From source file:org.apache.sling.engine.impl.parameters.ParameterSupport.java

public Enumeration<String> getParameterNames() {
    return new Enumeration<String>() {
        private final Iterator<String> base = ParameterSupport.this.getRequestParameterMapInternal().keySet()
                .iterator();/*w  ww. ja v a 2 s  .co m*/

        @Override
        public boolean hasMoreElements() {
            return this.base.hasNext();
        }

        @Override
        public String nextElement() {
            return this.base.next();
        }
    };
}

From source file:org.sakaiproject.kernel.component.core.ComponentClassLoader.java

/**
 * {@inheritDoc}// www  .j  a  v a2  s. c  o m
 * @see java.net.URLClassLoader#findResources(java.lang.String)
 */
@Override
public Enumeration<URL> findResources(String name) throws IOException {
    final Enumeration<URL> resources = packageRegistryService.findExportedResources(name);
    final Enumeration<URL> parent = super.findResources(name);
    return new Enumeration<URL>() {
        boolean exported = true;

        public boolean hasMoreElements() {
            boolean hasmore = false;
            if (exported) {
                hasmore = resources.hasMoreElements();
            }
            if (!hasmore) {
                exported = false;
                hasmore = parent.hasMoreElements();
            }
            return hasmore;
        }

        public URL nextElement() {
            if (exported) {
                return resources.nextElement();
            }
            return parent.nextElement();
        }
    };
}

From source file:org.sakaiproject.kernel.component.core.PackageRegistryServiceImpl.java

/**
 * {@inheritDoc}/*from   w  ww. j a  v a 2  s  .  co  m*/
 *
 * @see org.sakaiproject.kernel.api.PackageRegistryService#findExportedResources(java.lang.String)
 */
public Enumeration<URL> findExportedResources(final String name) {
    PackageExport p = root;
    String[] elements = StringUtils.split(name, '/');
    if (elements != null) {
        for (String element : elements) {
            PackageExport np = p.get(element);
            if (np == null) {
                break;
            }
            p = np;
        }
    }
    List<Exporter> exporters = p.getResourceExporters();
    final Iterator<Exporter> iexporters = exporters.iterator();
    return new Enumeration<URL>() {

        private Enumeration<URL> currentEnumerator;

        public boolean hasMoreElements() {
            // check the current enumerator
            if (currentEnumerator != null && currentEnumerator.hasMoreElements()) {
                return true;
            }
            currentEnumerator = null;
            // find the next available enumerator with elements
            while (currentEnumerator == null && iexporters.hasNext()) {
                Exporter currentExporter = iexporters.next();
                try {
                    currentEnumerator = currentExporter.findExportedResources(name);
                } catch (IOException e) {
                    LOG.error("Failed to open Exporter, ignored ", e);
                }
                if (currentEnumerator != null && currentEnumerator.hasMoreElements()) {
                    return true;
                }
            }
            return false;
        }

        public URL nextElement() {
            return currentEnumerator.nextElement();
        }
    };

}

From source file:io.neba.core.mvc.MultipartSlingHttpServletRequestTest.java

@SuppressWarnings("rawtypes")
private Enumeration fromIterator(final Iterator iterator) {
    return new Enumeration() {
        @Override/*from w  w w.  j a  v  a 2s  .  c  o  m*/
        public boolean hasMoreElements() {
            return iterator.hasNext();
        }

        @Override
        public Object nextElement() {
            return iterator.next();
        }
    };
}

From source file:org.alfresco.opencmis.CMISHttpServletRequest.java

@SuppressWarnings("unchecked")
@Override/*from  ww  w. ja  va 2 s .  c o  m*/
public Enumeration getParameterNames() {
    final Enumeration e = httpReq.getParameterNames();
    List l = new ArrayList();
    while (e.hasMoreElements()) {
        l.add(e.nextElement());
    }
    if (networkId != null) {
        l.add(Constants.PARAM_REPOSITORY_ID);
    }
    final Iterator it = l.iterator();
    Enumeration ret = new Enumeration() {
        @Override
        public boolean hasMoreElements() {
            return it.hasNext();
        }

        @Override
        public Object nextElement() {
            return it.next();
        }
    };

    return ret;
}

From source file:net.wastl.webmail.xml.XMLSystemData.java

public Enumeration getVirtualDomains() {
    final NodeList nl = sysdata.getElementsByTagName("DOMAIN");
    return new Enumeration() {
        int i = 0;

        public boolean hasMoreElements() {
            return i < nl.getLength();
        }//from w  ww  . jav  a2  s  .  com

        public Object nextElement() {
            Element elem = (Element) nl.item(i++);
            String value = XMLCommon.getTagValue(elem, "NAME");
            return value == null ? "unknown" + (i - 1) : value;
        }
    };
}

From source file:javarestart.WebClassLoader.java

/**
 * Returns none or zero resources: it just wraps findResource now.
 * TODO: extend client-server protocol to support fetching multiple resources by the given name.
 *//*  ww w .j a  v  a 2s .  c  o  m*/
@Override
public Enumeration<URL> findResources(String name) throws IOException {
    URL url = findResource(name);
    if (url == null)
        return Collections.emptyEnumeration();
    return new Enumeration<URL>() {
        private boolean hasMore = true;

        @Override
        public boolean hasMoreElements() {
            return hasMore;
        }

        @Override
        public URL nextElement() {
            hasMore = false;
            return url;
        }
    };
}

From source file:net.wastl.webmail.server.Storage.java

/**
 * @deprecated Use getUsers(String domain) instead
 *///from   w  w  w .java 2 s. co m
@Deprecated
public Enumeration getUsers() {
    final Enumeration domains = getVirtualDomains();
    return new Enumeration() {
        Enumeration enumVar = null;

        public boolean hasMoreElements() {
            return (domains.hasMoreElements() || (enumVar != null && enumVar.hasMoreElements()));
        }

        public Object nextElement() {
            if (enumVar == null || !enumVar.hasMoreElements()) {
                if (domains.hasMoreElements()) {
                    enumVar = getUsers((String) domains.nextElement());
                } else {
                    return null;
                }
            }
            return enumVar.nextElement();
        }
    };
}