List of usage examples for javax.servlet ServletContextAttributeEvent ServletContextAttributeEvent
public ServletContextAttributeEvent(ServletContext source, String name, Object value)
From source file:org.ireland.jnetty.webapp.ServletContextImpl.java
/** * Sets an application attribute.//w w w. j a v a 2s . com * * @param name * the name of the attribute * @param value * the value of the attribute */ @Override public void setAttribute(String name, Object value) { Object oldValue; synchronized (_attributes) { if (value != null) oldValue = _attributes.put(name, value); else oldValue = _attributes.remove(name); } // Call any listeners if (_applicationAttributeListeners != null) { ServletContextAttributeEvent event; if (oldValue != null) event = new ServletContextAttributeEvent(this, name, oldValue); else event = new ServletContextAttributeEvent(this, name, value); for (int i = 0; i < _applicationAttributeListeners.size(); i++) { ServletContextAttributeListener listener; Object objListener = _applicationAttributeListeners.get(i); listener = (ServletContextAttributeListener) objListener; try { if (oldValue != null) listener.attributeReplaced(event); else listener.attributeAdded(event); } catch (Exception e) { log(e.toString(), e); } } } }
From source file:org.ireland.jnetty.webapp.ServletContextImpl.java
/** * Removes an attribute from the servlet context. * //from w ww.ja v a 2 s .co m * @param name * the name of the attribute to remove. */ @Override public void removeAttribute(String name) { Object oldValue; synchronized (_attributes) { oldValue = _attributes.remove(name); } // Call any listeners if (_applicationAttributeListeners != null) { ServletContextAttributeEvent event; event = new ServletContextAttributeEvent(this, name, oldValue); for (int i = 0; i < _applicationAttributeListeners.size(); i++) { ServletContextAttributeListener listener; Object objListener = _applicationAttributeListeners.get(i); listener = (ServletContextAttributeListener) objListener; try { listener.attributeRemoved(event); } catch (Throwable e) { log.debug(e.toString(), e); } } } }
From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.WebApplicationHandler.java
public synchronized void setContextAttribute(String name, Object value) { Object old = super.getContextAttribute(name); super.setContextAttribute(name, value); if (_contextAttributeListeners != null) { ServletContextAttributeEvent event = new ServletContextAttributeEvent(getServletContext(), name, old != null ? old : value); for (int i = 0; i < LazyList.size(_contextAttributeListeners); i++) { ServletContextAttributeListener l = (ServletContextAttributeListener) LazyList .get(_contextAttributeListeners, i); if (old == null) l.attributeAdded(event); else if (value == null) l.attributeRemoved(event); else//from ww w . ja v a2s.c om l.attributeReplaced(event); } } }
From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.WebApplicationHandler.java
public synchronized void removeContextAttribute(String name) { Object old = super.getContextAttribute(name); super.removeContextAttribute(name); if (old != null && _contextAttributeListeners != null) { ServletContextAttributeEvent event = new ServletContextAttributeEvent(getServletContext(), name, old); for (int i = 0; i < LazyList.size(_contextAttributeListeners); i++) { ServletContextAttributeListener l = (ServletContextAttributeListener) LazyList .get(_contextAttributeListeners, i); l.attributeRemoved(event);// w ww . j ava 2s . c o m } } }