/** * Removes an attribute from the servlet context. * * @param name the name of the attribute to remove. */ 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.log(Level.FINE, e.toString(), e); } } } }
/** * Sets an application attribute. * * @param name the name of the attribute * @param value the value of the attribute */ 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.log(Level.FINE, e.toString(), e); } } } }