private static boolean isWeb(final Class<?> beanClass) { if (Servlet.class.isAssignableFrom(beanClass) || Filter.class.isAssignableFrom(beanClass)) { return true; } if (EventListener.class.isAssignableFrom(beanClass)) { return HttpSessionAttributeListener.class.isAssignableFrom(beanClass) || ServletContextListener.class.isAssignableFrom(beanClass) || ServletRequestListener.class.isAssignableFrom(beanClass) || ServletContextAttributeListener.class.isAssignableFrom(beanClass) || HttpSessionListener.class.isAssignableFrom(beanClass) || HttpSessionBindingListener.class.isAssignableFrom(beanClass) || HttpSessionActivationListener.class.isAssignableFrom(beanClass) || HttpSessionIdListener.class.isAssignableFrom(beanClass) || ServletRequestAttributeListener.class.isAssignableFrom(beanClass); } return false; }
@Override public <T extends EventListener> void addListener(T t) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException( sm.getString("applicationContext.addListener.ise", getContextPath())); } boolean match = false; if (t instanceof ServletContextAttributeListener || t instanceof ServletRequestListener || t instanceof ServletRequestAttributeListener || t instanceof HttpSessionAttributeListener) { context.addApplicationEventListener(t); match = true; } if (t instanceof HttpSessionListener || (t instanceof ServletContextListener && newServletContextListenerAllowed)) { // Add listener directly to the list of instances rather than to // the list of class names. context.addApplicationLifecycleListener(t); match = true; } if (match) return; if (t instanceof ServletContextListener) { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.sclNotAllowed", t.getClass().getName())); } else { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.wrongType", t.getClass().getName())); } }
/** * Remove the context attribute with the specified name, if any. * * @param name * Name of the context attribute to be removed */ @Override public void removeAttribute(String name) { Object value = null; // Remove the specified attribute // Check for read only attribute if (readOnlyAttributes.containsKey(name)) { return; } value = attributes.remove(name); if (value == null) { return; } // Notify interested application event listeners Object listeners[] = context.getApplicationEventListeners(); if ((listeners == null) || (listeners.length == 0)) return; ServletContextAttributeEvent event = new ServletContextAttributeEvent(context.getServletContext(), name, value); for (int i = 0; i < listeners.length; i++) { if (!(listeners[i] instanceof ServletContextAttributeListener)) continue; ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners[i]; try { context.fireContainerEvent("beforeContextAttributeRemoved", listener); listener.attributeRemoved(event); context.fireContainerEvent("afterContextAttributeRemoved", listener); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); context.fireContainerEvent("afterContextAttributeRemoved", listener); // FIXME - should we do anything besides log these? log(sm.getString("applicationContext.attributeEvent"), t); } } }
@Override public <T extends EventListener> void addListener(T t) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException(sm.getString("applicationContext.addListener.ise", getContextPath())); } boolean match = false; if (t instanceof ServletContextAttributeListener || t instanceof ServletRequestListener || t instanceof ServletRequestAttributeListener || t instanceof HttpSessionAttributeListener) { context.addApplicationEventListener(t); match = true; } if (t instanceof HttpSessionListener || (t instanceof ServletContextListener && newServletContextListenerAllowed)) { // Add listener directly to the list of instances rather than to // the list of class names. context.addApplicationLifecycleListener(t); match = true; } if (match) return; if (t instanceof ServletContextListener) { throw new IllegalArgumentException( sm.getString("applicationContext.addListener.iae.sclNotAllowed", t.getClass().getName())); } else { throw new IllegalArgumentException( sm.getString("applicationContext.addListener.iae.wrongType", t.getClass().getName())); } }
private void loadListeners(WebAppConfiguration wac) throws ClassNotFoundException, IllegalAccessException, InstantiationException, WebAppConfigurationException { for (WebAppListener listener : wac.getListeners()) { String className = listener.getListenerClass(); Class<?> clazz = classLoader.loadClass(className); Object obj = clazz.newInstance(); boolean used = false; if (obj instanceof ServletContextAttributeListener) { scaListeners.add((ServletContextAttributeListener) obj); used = true; } if (obj instanceof ServletContextListener) { scListeners.add((ServletContextListener) obj); used = true; } if (obj instanceof ServletRequestListener) { srListeners.add((ServletRequestListener) obj); used = true; } if (obj instanceof ServletRequestAttributeListener) { sraListeners.add((ServletRequestAttributeListener) obj); used = true; } if (obj instanceof HttpSessionAttributeListener) { sessionAttributeListeners.add((HttpSessionAttributeListener) obj); used = true; } if (obj instanceof HttpSessionListener) { sessionListeners.add((HttpSessionListener) obj); used = true; } if (!used) { throw new WebAppConfigurationException("Don't know what to do with '" + className + "'"); } } }
private void addListenerInstance(final Object listenerInstance, final List<ServletContextAttributeListener> contextAttributeListeners, final List<ServletContextListener> contextListeners, final List<ServletRequestAttributeListener> requestAttributeListeners, final List<ServletRequestListener> requestListeners, final List<HttpSessionActivationListener> sessionActivationListeners, final List<HttpSessionAttributeListener> sessionAttributeListeners, final List<HttpSessionListener> sessionListeners) { if (listenerInstance instanceof ServletContextAttributeListener) { contextAttributeListeners.add((ServletContextAttributeListener) listenerInstance); } if (listenerInstance instanceof ServletContextListener) { contextListeners.add((ServletContextListener) listenerInstance); } if (listenerInstance instanceof ServletRequestAttributeListener) { requestAttributeListeners.add((ServletRequestAttributeListener) listenerInstance); } if (listenerInstance instanceof ServletRequestListener) { requestListeners.add((ServletRequestListener) listenerInstance); } if (listenerInstance instanceof HttpSessionActivationListener) { sessionActivationListeners.add((HttpSessionActivationListener) listenerInstance); } if (listenerInstance instanceof HttpSessionAttributeListener) { sessionAttributeListeners.add((HttpSessionAttributeListener) listenerInstance); } if (listenerInstance instanceof HttpSessionListener) { sessionListeners.add((HttpSessionListener) listenerInstance); } }
@Override public void setAttribute(String attr, Object value) { Object original = attributes.get(attr); attributes.put(attr, value); ServletContextAttributeEvent event = new ServletContextAttributeEvent(this, attr, value); if (original != null) { call(ServletContextAttributeListener.class, (l) -> l.attributeReplaced(event)); } else { call(ServletContextAttributeListener.class, (l) -> l.attributeAdded(event)); } }
@Override public void attributeAdded(final ServletContextAttributeEvent scab) { final Iterator<ServletContextAttributeListener> listeners = getContextListeners(); while (listeners.hasNext()) { listeners.next().attributeAdded(scab); } }
@Override public void attributeRemoved(final ServletContextAttributeEvent scab) { final Iterator<ServletContextAttributeListener> listeners = getContextListeners(); while (listeners.hasNext()) { listeners.next().attributeRemoved(scab); } }
@Override public void attributeReplaced(final ServletContextAttributeEvent scab) { final Iterator<ServletContextAttributeListener> listeners = getContextListeners(); while (listeners.hasNext()) { listeners.next().attributeReplaced(scab); } }
public ServletContextImpl(Bundle bundle, ServletContext context, HttpContext httpContext, ServletContextAttributeListener attributeListener, boolean sharedAttributes) { this.bundle = bundle; this.context = context; this.httpContext = httpContext; this.attributeListener = attributeListener; this.attributes = sharedAttributes ? null : new ConcurrentHashMap<String, Object>(); }
public ServletContextManager(Bundle bundle, ServletContext context, ServletContextAttributeListener attributeListener, boolean sharedAttributes) { this.bundle = bundle; this.context = context; this.attributeListener = attributeListener; this.contextMap = new HashMap<HttpContext, ExtServletContext>(); this.sharedAttributes = sharedAttributes; }
public HttpServiceFactory(ServletContext context, HandlerRegistry handlerRegistry, ServletContextAttributeListener attributeListener, boolean sharedContextAttributes) { this.context = context; this.attributeListener = attributeListener; this.handlerRegistry = handlerRegistry; this.sharedContextAttributes = sharedContextAttributes; }
/** * Remove the context attribute with the specified name, if any. * * @param name Name of the context attribute to be removed */ @Override public void removeAttribute(String name) { Object value = null; // Remove the specified attribute // Check for read only attribute if (readOnlyAttributes.containsKey(name)){ return; } value = attributes.remove(name); if (value == null) { return; } // Notify interested application event listeners Object listeners[] = context.getApplicationEventListeners(); if ((listeners == null) || (listeners.length == 0)) return; ServletContextAttributeEvent event = new ServletContextAttributeEvent(context.getServletContext(), name, value); for (int i = 0; i < listeners.length; i++) { if (!(listeners[i] instanceof ServletContextAttributeListener)) continue; ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners[i]; try { context.fireContainerEvent("beforeContextAttributeRemoved", listener); listener.attributeRemoved(event); context.fireContainerEvent("afterContextAttributeRemoved", listener); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); context.fireContainerEvent("afterContextAttributeRemoved", listener); // FIXME - should we do anything besides log these? log(sm.getString("applicationContext.attributeEvent"), t); } } }
/** * Remove the context attribute with the specified name, if any. * * @param name Name of the context attribute to be removed */ public void removeAttribute(String name) { Object value = null; boolean found = false; // Remove the specified attribute // Check for read only attribute if (readOnlyAttributes.containsKey(name)) return; found = attributes.containsKey(name); if (found) { value = attributes.get(name); attributes.remove(name); } else { return; } // Notify interested application event listeners Object listeners[] = context.getApplicationEventListeners(); if ((listeners == null) || (listeners.length == 0)) return; ServletContextAttributeEvent event = new ServletContextAttributeEvent(context.getServletContext(), name, value); for (int i = 0; i < listeners.length; i++) { if (!(listeners[i] instanceof ServletContextAttributeListener)) continue; ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners[i]; try { context.fireContainerEvent("beforeContextAttributeRemoved", listener); listener.attributeRemoved(event); context.fireContainerEvent("afterContextAttributeRemoved", listener); } catch (Throwable t) { context.fireContainerEvent("afterContextAttributeRemoved", listener); // FIXME - should we do anything besides log these? log(sm.getString("applicationContext.attributeEvent"), t); } } }
public void servletContextAttributeAdded(final String name, final Object value) { final ServletContextAttributeEvent sre = new ServletContextAttributeEvent(servletContext, name, value); for (int i = 0; i < servletContextAttributeListeners.length; ++i) { this.<ServletContextAttributeListener>get(servletContextAttributeListeners[i]).attributeAdded(sre); } }
public void servletContextAttributeRemoved(final String name, final Object value) { final ServletContextAttributeEvent sre = new ServletContextAttributeEvent(servletContext, name, value); for (int i = 0; i < servletContextAttributeListeners.length; ++i) { this.<ServletContextAttributeListener>get(servletContextAttributeListeners[i]).attributeRemoved(sre); } }
public void servletContextAttributeReplaced(final String name, final Object value) { final ServletContextAttributeEvent sre = new ServletContextAttributeEvent(servletContext, name, value); for (int i = 0; i < servletContextAttributeListeners.length; ++i) { this.<ServletContextAttributeListener>get(servletContextAttributeListeners[i]).attributeReplaced(sre); } }
/** * Remove the context attribute with the specified name, if any. * * @param name Name of the context attribute to be removed */ public void removeAttribute(String name) { Object value = null; boolean found = false; // Remove the specified attribute synchronized (attributes) { // Check for read only attribute if (readOnlyAttributes.containsKey(name)) return; found = attributes.containsKey(name); if (found) { value = attributes.get(name); attributes.remove(name); } else { return; } } // Notify interested application event listeners Object listeners[] = context.getApplicationListeners(); if ((listeners == null) || (listeners.length == 0)) return; ServletContextAttributeEvent event = new ServletContextAttributeEvent(context.getServletContext(), name, value); for (int i = 0; i < listeners.length; i++) { if (!(listeners[i] instanceof ServletContextAttributeListener)) continue; ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners[i]; try { context.fireContainerEvent("beforeContextAttributeRemoved", listener); listener.attributeRemoved(event); context.fireContainerEvent("afterContextAttributeRemoved", listener); } catch (Throwable t) { context.fireContainerEvent("afterContextAttributeRemoved", listener); // FIXME - should we do anything besides log these? log(sm.getString("applicationContext.attributeEvent"), t); } } }
ServletContextAttributeListener getGlobalServletContextAttributeListener() { return scaListeners; }
public ServletContextAttributeListenerList() { listeners = new ArrayList<ServletContextAttributeListener>(); }
public void add(ServletContextAttributeListener listener) { listeners.add(listener); }
public void attributeAdded(ServletContextAttributeEvent event) { for (ServletContextAttributeListener listener : listeners) { listener.attributeAdded(event); } }
public void attributeRemoved(ServletContextAttributeEvent event) { for (ServletContextAttributeListener listener : listeners) { listener.attributeRemoved(event); } }
public void attributeReplaced(ServletContextAttributeEvent event) { for (ServletContextAttributeListener listener : listeners) { listener.attributeReplaced(event); } }
@Override public void removeAttribute(String attr) { ServletContextAttributeEvent event = new ServletContextAttributeEvent(this, attr, attributes.remove(attr)); call(ServletContextAttributeListener.class, (l) -> l.attributeRemoved(event)); }
public ServletContextAttributeListenerManager(BundleContext context) { super(context, ServletContextAttributeListener.class); }
/** * Remove the context attribute with the specified name, if any. * * @param name Name of the context attribute to be removed */ @Override public void removeAttribute(String name) { Object value = null; boolean found = false; // Remove the specified attribute // Check for read only attribute if (readOnlyAttributes.containsKey(name)) return; found = attributes.containsKey(name); if (found) { value = attributes.get(name); attributes.remove(name); } else { return; } // Notify interested application event listeners Object listeners[] = context.getApplicationEventListeners(); if ((listeners == null) || (listeners.length == 0)) return; ServletContextAttributeEvent event = new ServletContextAttributeEvent(context.getServletContext(), name, value); for (int i = 0; i < listeners.length; i++) { if (!(listeners[i] instanceof ServletContextAttributeListener)) continue; ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners[i]; try { context.fireContainerEvent("beforeContextAttributeRemoved", listener); listener.attributeRemoved(event); context.fireContainerEvent("afterContextAttributeRemoved", listener); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); context.fireContainerEvent("afterContextAttributeRemoved", listener); // FIXME - should we do anything besides log these? log(sm.getString("applicationContext.attributeEvent"), t); } } }
@Override public <T extends EventListener> void addListener(T t) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException( sm.getString("applicationContext.addListener.ise", getContextPath())); } // TODO SERVLET3 // throw UnsupportedOperationException - if this context was passed to the // {@link ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)} // method of a {@link ServletContextListener} that was not declared // in web.xml, a web-fragment or annotated with // {@link javax.servlet.annotation.WebListener}. boolean match = false; if (t instanceof ServletContextAttributeListener || t instanceof ServletRequestListener || t instanceof ServletRequestAttributeListener || t instanceof HttpSessionAttributeListener) { context.addApplicationEventListener(t); match = true; } if (t instanceof HttpSessionListener || (t instanceof ServletContextListener && newServletContextListenerAllowed)) { context.addApplicationLifecycleListener(t); match = true; } if (match) return; if (t instanceof ServletContextListener) { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.sclNotAllowed", t.getClass().getName())); } else { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.wrongType", t.getClass().getName())); } }