Search in sources :

Example 41 with Enumeration

use of java.util.Enumeration in project guice by google.

the class FilterDefinition method init.

public void init(final ServletContext servletContext, Injector injector, Set<Filter> initializedSoFar) throws ServletException {
    // This absolutely must be a singleton, and so is only initialized once.
    if (!Scopes.isSingleton(injector.getBinding(filterKey))) {
        throw new ServletException("Filters must be bound as singletons. " + filterKey + " was not bound in singleton scope.");
    }
    Filter filter = injector.getInstance(filterKey);
    this.filter.set(filter);
    // in the filter chain.
    if (initializedSoFar.contains(filter)) {
        return;
    }
    //initialize our filter with the configured context params and servlet context
    filter.init(new FilterConfig() {

        @Override
        public String getFilterName() {
            return filterKey.toString();
        }

        @Override
        public ServletContext getServletContext() {
            return servletContext;
        }

        @Override
        public String getInitParameter(String s) {
            return initParams.get(s);
        }

        @Override
        public Enumeration getInitParameterNames() {
            return Iterators.asEnumeration(initParams.keySet().iterator());
        }
    });
    initializedSoFar.add(filter);
}
Also used : ServletException(javax.servlet.ServletException) Enumeration(java.util.Enumeration) Filter(javax.servlet.Filter) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig)

Example 42 with Enumeration

use of java.util.Enumeration in project guice by google.

the class FilterDefinitionTest method testFilterInitAndConfig.

public final void testFilterInitAndConfig() throws ServletException {
    Injector injector = createMock(Injector.class);
    Binding binding = createMock(Binding.class);
    final MockFilter mockFilter = new MockFilter();
    expect(binding.acceptScopingVisitor((BindingScopingVisitor) anyObject())).andReturn(true);
    expect(injector.getBinding(Key.get(Filter.class))).andReturn(binding);
    expect(injector.getInstance(Key.get(Filter.class))).andReturn(mockFilter).anyTimes();
    replay(binding, injector);
    //some init params
    //noinspection SSBasedInspection
    final Map<String, String> initParams = new ImmutableMap.Builder<String, String>().put("ahsd", "asdas24dok").put("ahssd", "asdasd124ok").build();
    ServletContext servletContext = createMock(ServletContext.class);
    final String contextName = "thing__!@@44";
    expect(servletContext.getServletContextName()).andReturn(contextName);
    replay(servletContext);
    String pattern = "/*";
    final FilterDefinition filterDef = new FilterDefinition(Key.get(Filter.class), UriPatternType.get(UriPatternType.SERVLET, pattern), initParams, null);
    filterDef.init(servletContext, injector, Sets.<Filter>newIdentityHashSet());
    assertTrue(filterDef.getFilter() instanceof MockFilter);
    final FilterConfig filterConfig = mockFilter.getConfig();
    assertTrue(null != filterConfig);
    assertEquals(filterConfig.getServletContext().getServletContextName(), contextName);
    assertEquals(filterConfig.getFilterName(), Key.get(Filter.class).toString());
    final Enumeration names = filterConfig.getInitParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        assertTrue(initParams.containsKey(name));
        assertEquals(filterConfig.getInitParameter(name), initParams.get(name));
    }
    verify(binding, injector, servletContext);
}
Also used : Binding(com.google.inject.Binding) Enumeration(java.util.Enumeration) Filter(javax.servlet.Filter) Injector(com.google.inject.Injector) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 43 with Enumeration

use of java.util.Enumeration in project j2objc by google.

the class ParserAdapter method endElement.

/**
     * Adapter implementation method; do not call.
     * Adapt a SAX1 end element event.
     *
     * @param qName The qualified (prefixed) name.
     * @exception SAXException The client may raise a
     *            processing exception.
     * @see org.xml.sax.DocumentHandler#endElement
     */
public void endElement(String qName) throws SAXException {
    // processing, dispatch this quickly.
    if (!namespaces) {
        if (contentHandler != null) {
            contentHandler.endElement("", "", qName.intern());
        }
        return;
    }
    // Split the name.
    String[] names = processName(qName, false, false);
    if (contentHandler != null) {
        contentHandler.endElement(names[0], names[1], names[2]);
        Enumeration prefixes = nsSupport.getDeclaredPrefixes();
        while (prefixes.hasMoreElements()) {
            String prefix = (String) prefixes.nextElement();
            contentHandler.endPrefixMapping(prefix);
        }
    }
    nsSupport.popContext();
}
Also used : Enumeration(java.util.Enumeration)

Example 44 with Enumeration

use of java.util.Enumeration in project j2objc by google.

the class XSLTElementDef method getRequiredElem.

/**
   * Get required elements that were not found.
   *
   * @return required elements that were not found.
   */
String getRequiredElem() {
    if (m_requiredFound == null)
        return null;
    Enumeration elems = m_requiredFound.elements();
    String s = "";
    boolean first = true;
    while (elems.hasMoreElements()) {
        if (first)
            first = false;
        else
            s = s + ", ";
        s = s + (String) elems.nextElement();
    }
    return s;
}
Also used : Enumeration(java.util.Enumeration)

Example 45 with Enumeration

use of java.util.Enumeration in project j2objc by google.

the class ConcurrentHashMapTest method testKeys.

/**
     *   keys returns an enumeration containing all the keys from the map
     */
public void testKeys() {
    ConcurrentHashMap map = map5();
    Enumeration e = map.keys();
    int count = 0;
    while (e.hasMoreElements()) {
        count++;
        e.nextElement();
    }
    assertEquals(5, count);
}
Also used : Enumeration(java.util.Enumeration)

Aggregations

Enumeration (java.util.Enumeration)1418 IOException (java.io.IOException)247 ArrayList (java.util.ArrayList)183 File (java.io.File)122 Vector (java.util.Vector)98 Properties (java.util.Properties)97 HashMap (java.util.HashMap)96 List (java.util.List)89 URL (java.net.URL)74 HashSet (java.util.HashSet)71 Map (java.util.Map)71 Hashtable (java.util.Hashtable)70 Iterator (java.util.Iterator)70 Set (java.util.Set)67 InputStream (java.io.InputStream)62 ZipEntry (java.util.zip.ZipEntry)62 ServletContext (javax.servlet.ServletContext)55 ZipFile (java.util.zip.ZipFile)51 FileInputStream (java.io.FileInputStream)48 ServletException (javax.servlet.ServletException)46