List of usage examples for javax.servlet ServletRequestAttributeListener attributeReplaced
default public void attributeReplaced(ServletRequestAttributeEvent srae)
From source file:org.apache.coyote.tomcat5.CoyoteRequest.java
/** * Set the specified request attribute to the specified value. * * @param name Name of the request attribute to set * @param value The associated value// w w w .j ava2s .c om */ public void setAttribute(String name, Object value) { // Name cannot be null if (name == null) throw new IllegalArgumentException(sm.getString("coyoteRequest.setAttribute.namenull")); // Null value is the same as removeAttribute() if (value == null) { removeAttribute(name); return; } if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) { dispatcherType = value; return; } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) { requestDispatcherPath = value; return; } Object oldValue = null; boolean replaced = false; // Add or replace the specified attribute // Check for read only attribute // requests are per thread so synchronization unnecessary if (readOnlyAttributes.containsKey(name)) { return; } oldValue = attributes.put(name, value); if (oldValue != null) { replaced = true; } // Notify interested application event listeners Object listeners[] = context.getApplicationEventListeners(); if ((listeners == null) || (listeners.length == 0)) return; ServletRequestAttributeEvent event = null; if (replaced) event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, oldValue); else event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, value); for (int i = 0; i < listeners.length; i++) { if (!(listeners[i] instanceof ServletRequestAttributeListener)) continue; ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners[i]; try { if (replaced) { listener.attributeReplaced(event); } else { listener.attributeAdded(event); } } catch (Throwable t) { log(sm.getString("coyoteRequest.attributeEvent"), t); // Error valve will pick this execption up and display it to user attributes.put(Globals.EXCEPTION_ATTR, t); } } }
From source file:org.ireland.jnetty.http.HttpServletRequestImpl.java
/** * Notify interested ServletRequestAttributeListeners that attribute has been Replaced. * /*from w w w.ja v a2 s. com*/ * ?? */ private void notifyAttributeReplaced(String name, Object oldValue) { if (_requestAttributeListeners != null && !_requestAttributeListeners.isEmpty()) { final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(servletContext, this, name, oldValue); for (ServletRequestAttributeListener listener : _requestAttributeListeners) { listener.attributeReplaced(event); } } }