Search in sources :

Example 1 with ListenerHolder

use of org.eclipse.jetty.servlet.ListenerHolder 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);
    }
}
Also used : HttpSessionListener(javax.servlet.http.HttpSessionListener) ServletRequestListener(javax.servlet.ServletRequestListener) ListenerHolder(org.eclipse.jetty.servlet.ListenerHolder) Source(org.eclipse.jetty.servlet.Source) EventListener(java.util.EventListener) MetaData(org.eclipse.jetty.webapp.MetaData) EventListener(java.util.EventListener) HttpSessionIdListener(javax.servlet.http.HttpSessionIdListener)

Example 2 with ListenerHolder

use of org.eclipse.jetty.servlet.ListenerHolder in project jetty.project by eclipse.

the class StandardDescriptorProcessor method newListenerInstance.

public EventListener newListenerInstance(WebAppContext context, Class<? extends EventListener> clazz, Descriptor descriptor) throws Exception {
    ListenerHolder h = context.getServletHandler().newListenerHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
    EventListener l = context.getServletContext().createInstance(clazz);
    h.setListener(l);
    context.getServletHandler().addListener(h);
    return l;
}
Also used : EventListener(java.util.EventListener) ListenerHolder(org.eclipse.jetty.servlet.ListenerHolder) Source(org.eclipse.jetty.servlet.Source)

Aggregations

EventListener (java.util.EventListener)2 ListenerHolder (org.eclipse.jetty.servlet.ListenerHolder)2 Source (org.eclipse.jetty.servlet.Source)2 ServletRequestListener (javax.servlet.ServletRequestListener)1 HttpSessionIdListener (javax.servlet.http.HttpSessionIdListener)1 HttpSessionListener (javax.servlet.http.HttpSessionListener)1 MetaData (org.eclipse.jetty.webapp.MetaData)1