if (addDeltaRequest && (deltaRequest != null))
deltaRequest.setAttribute(name, value);
// Construct an event with the new value
HttpSessionBindingEvent event = null;
// Call the valueBound() method if necessary
if (value instanceof HttpSessionBindingListener && notify) {
// Don't call any notification if replacing with the same value
Object oldValue = attributes.get(name);
if (value != oldValue) {
event = new HttpSessionBindingEvent(getSession(), name, value);
try {
((HttpSessionBindingListener) value).valueBound(event);
} catch (Exception x) {
log.error(smp.getString("deltaSession.valueBound.ex"), x);
}
}
}
// Replace or add this attribute
Object unbound = attributes.put(name, value);
// Call the valueUnbound() method if necessary
if ((unbound != null) && (unbound != value) && notify
&& (unbound instanceof HttpSessionBindingListener)) {
try {
((HttpSessionBindingListener) unbound)
.valueUnbound(new HttpSessionBindingEvent(
(HttpSession) getSession(), name));
} catch (Exception x) {
log.error(smp.getString("deltaSession.valueBinding.ex"), x);
}
}
//dont notify any listeners
if (!notify)
return;
// Notify interested application event listeners
Context context = (Context) manager.getContainer();
//fix for standalone manager without container
if (context != null) {
Object listeners[] = context.getApplicationEventListeners();
if (listeners == null)
return;
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof HttpSessionAttributeListener))
continue;
HttpSessionAttributeListener listener = (HttpSessionAttributeListener) listeners[i];
try {
if (unbound != null) {
fireContainerEvent(context,
"beforeSessionAttributeReplaced", listener);
if (event == null) {
event = new HttpSessionBindingEvent(getSession(),
name, unbound);
}
listener.attributeReplaced(event);
fireContainerEvent(context,
"afterSessionAttributeReplaced", listener);
} else {
fireContainerEvent(context,
"beforeSessionAttributeAdded", listener);
if (event == null) {
event = new HttpSessionBindingEvent(getSession(),
name, value);
}
listener.attributeAdded(event);
fireContainerEvent(context,
"afterSessionAttributeAdded", listener);