List of usage examples for javax.servlet ServletContextAttributeListener attributeReplaced
default public void attributeReplaced(ServletContextAttributeEvent event)
From source file:org.ireland.jnetty.webapp.ServletContextImpl.java
/** * Sets an application attribute.//from ww w . j ava 2 s . c om * * @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: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 w w w . j a v a 2 s .co m*/ l.attributeReplaced(event); } } }