Java Collections.enumeration Examples

Java Collections.enumeration - 30 examples found. These are the top rated real world Java examples of java.util.Collections.enumeration extracted from open source projects. You can rate examples to help us improve the quality of examples.
 /*
  * @see org.mortbay.util.Attributes#getAttributeNames()
  */
 public static Enumeration getAttributeNamesCopy(Attributes attrs) {
   if (attrs instanceof AttributesMap)
     return Collections.enumeration(((AttributesMap) attrs)._map.keySet());
   ArrayList names = new ArrayList();
   Enumeration e = attrs.getAttributeNames();
   while (e.hasMoreElements()) names.add(e.nextElement());
   return Collections.enumeration(names);
 }
  /**
   * Return an <code>Enumeration</code> of the names of the initialization parameters for this
   * Filter.
   */
  @Override
  public Enumeration<String> getInitParameterNames() {
    Map<String, String> map = filterDef.getParameterMap();

    if (map == null) {
      return Collections.enumeration(emptyString);
    }

    return Collections.enumeration(map.keySet());
  }
 /**
  * Note: For element with {@code #nestedBlock}, this will hide the {@code #nestedBlock} when
  * that's a {@link MixedContent}.
  */
 public Enumeration children() {
   if (nestedBlock instanceof MixedContent) {
     return nestedBlock.children();
   }
   if (nestedBlock != null) {
     return Collections.enumeration(Collections.singletonList(nestedBlock));
   } else if (regulatedChildBuffer != null) {
     return new _ArrayEnumeration(regulatedChildBuffer, regulatedChildCount);
   }
   return Collections.enumeration(Collections.EMPTY_LIST);
 }
  @Override
  public Enumeration<URL> getResources(final String name) throws IOException {
    if (!getState().isAvailable()) {
      return null;
    }

    if ("META-INF/services/javax.servlet.ServletContainerInitializer".equals(name)) {
      final Collection<URL> list = new ArrayList<>(Collections.list(super.getResources(name)));
      final Iterator<URL> it = list.iterator();
      while (it.hasNext()) {
        final URL next = it.next();
        final File file = Files.toFile(next);
        if (!file.isFile() && NewLoaderLogic.skip(next)) {
          it.remove();
        }
      }
      return Collections.enumeration(list);
    }
    if ("META-INF/services/javax.websocket.ContainerProvider".equals(name)) {
      final Collection<URL> list = new ArrayList<>(Collections.list(super.getResources(name)));
      final Iterator<URL> it = list.iterator();
      while (it.hasNext()) {
        final URL next = it.next();
        final File file = Files.toFile(next);
        if (!file.isFile() && NewLoaderLogic.skip(next)) {
          it.remove();
        }
      }
      return Collections.enumeration(list);
    }
    if ("META-INF/faces-config.xml".equals(name)) { // mojarra workaround
      try {
        if (WebBeansContext.currentInstance() == null
            && Boolean.parseBoolean(
                SystemInstance.get().getProperty("tomee.jsf.ignore-owb", "true"))) {
          final Collection<URL> list = new HashSet<>(Collections.list(super.getResources(name)));
          final Iterator<URL> it = list.iterator();
          while (it.hasNext()) {
            final String fileName = Files.toFile(it.next()).getName();
            if (fileName.startsWith("openwebbeans-" /*jsf|el22*/) && fileName.endsWith(".jar")) {
              it.remove();
            }
          }
          return Collections.enumeration(list);
        }
      } catch (final Throwable th) {
        // no-op
      }
    }
    return URLClassLoaderFirst.filterResources(name, super.getResources(name));
  }
Example #5
0
  /** @see java.lang.ClassLoader#findResources(java.lang.String) */
  @Override
  public Enumeration<URL> findResources(String resourceName) throws IOException {
    ArrayList<URL> cachedUrls = resourceAllCache.get(resourceName);
    if (cachedUrls != null) return Collections.enumeration(cachedUrls);

    ArrayList<URL> urlList = new ArrayList<>();
    int classesDirectoryListSize = classesDirectoryList.size();
    for (int i = 0; i < classesDirectoryListSize; i++) {
      File classesDir = classesDirectoryList.get(i);
      File testFile = new File(classesDir.getAbsolutePath() + "/" + resourceName);
      try {
        if (testFile.exists() && testFile.isFile()) urlList.add(testFile.toURI().toURL());
      } catch (MalformedURLException e) {
        System.out.println(
            "Error making URL for ["
                + resourceName
                + "] in classes directory ["
                + classesDir
                + "]: "
                + e.toString());
      }
    }
    int jarFileListSize = jarFileList.size();
    for (int i = 0; i < jarFileListSize; i++) {
      JarFile jarFile = jarFileList.get(i);
      JarEntry jarEntry = jarFile.getJarEntry(resourceName);
      if (jarEntry != null) {
        try {
          String jarFileName = jarFile.getName();
          if (jarFileName.contains("\\")) jarFileName = jarFileName.replace('\\', '/');
          urlList.add(new URL("jar:file:" + jarFileName + "!/" + jarEntry));
        } catch (MalformedURLException e) {
          System.out.println(
              "Error making URL for ["
                  + resourceName
                  + "] in jar ["
                  + jarFile
                  + "]: "
                  + e.toString());
        }
      }
    }
    // add all resources found in parent loader too
    Enumeration<URL> superResources = getParent().getResources(resourceName);
    while (superResources.hasMoreElements()) urlList.add(superResources.nextElement());
    resourceAllCache.putIfAbsent(resourceName, urlList);
    // System.out.println("finding all resources with name " + resourceName + " got " + urlList);
    return Collections.enumeration(urlList);
  }
 @Override
 public Enumeration<String> getKeys() {
   // TODO Auto-generated method stub
   return null != delegate
       ? delegate.getKeys()
       : Collections.<String>enumeration(Collections.<String>emptyList());
 }