use of java.util.EventListener in project jetty.project by eclipse.
the class WebListenerAnnotation method apply.
/**
* @see DiscoveredAnnotation#apply()
*/
public void apply() {
Class<? extends java.util.EventListener> clazz = (Class<? extends EventListener>) getTargetClass();
if (clazz == null) {
LOG.warn(_className + " cannot be loaded");
return;
}
try {
if (ServletContextListener.class.isAssignableFrom(clazz) || ServletContextAttributeListener.class.isAssignableFrom(clazz) || ServletRequestListener.class.isAssignableFrom(clazz) || ServletRequestAttributeListener.class.isAssignableFrom(clazz) || HttpSessionListener.class.isAssignableFrom(clazz) || HttpSessionAttributeListener.class.isAssignableFrom(clazz) || HttpSessionIdListener.class.isAssignableFrom(clazz)) {
java.util.EventListener listener = (java.util.EventListener) _context.getServletContext().createInstance(clazz);
MetaData metaData = _context.getMetaData();
if (metaData.getOrigin(clazz.getName() + ".listener") == Origin.NotSet) {
ListenerHolder h = _context.getServletHandler().newListenerHolder(new Source(Source.Origin.ANNOTATION, clazz.getName()));
h.setListener(listener);
_context.getServletHandler().addListener(h);
_context.addEventListener(listener);
}
} else
LOG.warn(clazz.getName() + " does not implement one of the servlet listener interfaces");
} catch (Exception e) {
LOG.warn(e);
}
}
use of java.util.EventListener in project jetty.project by eclipse.
the class StandardDescriptorProcessor method visitListener.
public void visitListener(WebAppContext context, Descriptor descriptor, XmlParser.Node node) {
String className = node.getString("listener-class", false, true);
EventListener listener = null;
try {
if (className != null && className.length() > 0) {
//Servlet Spec 3.0 p 74
//Duplicate listener declarations don't result in duplicate listener instances
EventListener[] listeners = context.getEventListeners();
if (listeners != null) {
for (EventListener l : listeners) {
if (l.getClass().getName().equals(className))
return;
}
}
((WebDescriptor) descriptor).addClassName(className);
Class<? extends EventListener> listenerClass = (Class<? extends EventListener>) context.loadClass(className);
listener = newListenerInstance(context, listenerClass, descriptor);
if (!(listener instanceof EventListener)) {
LOG.warn("Not an EventListener: " + listener);
return;
}
context.addEventListener(listener);
context.getMetaData().setOrigin(className + ".listener", descriptor);
}
} catch (Exception e) {
LOG.warn("Could not instantiate listener " + className, e);
return;
}
}
use of java.util.EventListener in project jetty.project by eclipse.
the class SessionHandler method clearEventListeners.
/* ------------------------------------------------------------ */
/**
* Removes all event listeners for session-related events.
*
* @see #removeEventListener(EventListener)
*/
public void clearEventListeners() {
for (EventListener e : getBeans(EventListener.class)) removeBean(e);
_sessionAttributeListeners.clear();
_sessionListeners.clear();
_sessionIdListeners.clear();
}
use of java.util.EventListener in project spring-boot by spring-projects.
the class ServletListenerRegistrationBeanTests method cannotRegisterUnsupportedType.
@Test
public void cannotRegisterUnsupportedType() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Listener is not of a supported type");
new ServletListenerRegistrationBean<EventListener>(new EventListener() {
});
}
use of java.util.EventListener in project robovm by robovm.
the class OldEventListenerProxyTest method testGetListener.
public void testGetListener() {
EventListener el = new Mock_EventListener();
EventListenerProxy elp = new Mock_EventListenerProxy(el);
assertSame(el, elp.getListener());
}
Aggregations