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);
}
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);
}
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();
}
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;
}
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);
}
Aggregations