1 16 package org.mortbay.j2ee.session; 17 18 20 import java.rmi.RemoteException ; 21 22 import javax.servlet.http.HttpSessionBindingEvent ; 23 import javax.servlet.http.HttpSessionBindingListener ; 24 25 import org.jfox.ioc.logger.Logger; 26 27 29 47 public class BindingInterceptor 48 extends StateInterceptor 49 { 50 protected static final Logger _log=Logger.getLogger(BindingInterceptor.class); 51 53 57 protected Object 58 notifyValueUnbound(String name, Object value) 59 { 60 if (!(value instanceof HttpSessionBindingListener )) 61 return value; 62 63 HttpSessionBindingEvent event=new HttpSessionBindingEvent (getSession(), name, value); 64 ((HttpSessionBindingListener )value).valueUnbound(event); 65 event=null; 66 67 return value; 68 } 69 70 protected Object 71 notifyValueBound(String name, Object value) 72 { 73 if (!(value instanceof HttpSessionBindingListener )) 74 return value; 75 76 HttpSessionBindingEvent event=new HttpSessionBindingEvent (getSession(), name, value); 77 ((HttpSessionBindingListener )value).valueBound(event); 78 event=null; 79 80 return value; 81 } 82 83 94 104 public Object 105 setAttribute(String name, Object value, boolean returnValue) 106 throws RemoteException 107 { 108 111 boolean needOldValue=true; 112 113 Object oldValue=super.setAttribute(name, value, true); 115 116 118 try 119 { 120 if (oldValue!=null) 121 notifyValueUnbound(name, oldValue); 122 123 notifyValueBound(name, value); 124 125 if (oldValue!=null) 127 getManager().notifyAttributeReplaced(getSession(), name, oldValue); 128 else 129 getManager().notifyAttributeAdded(getSession(), name, value); 130 } 131 catch (Throwable t) 132 { 133 _log.error("error in user owned Listener - notifications may be incomplete", t); 134 } 135 136 return oldValue; 137 } 138 139 148 public Object 149 removeAttribute(String name, boolean returnValue) 150 throws RemoteException 151 { 152 Object oldValue=super.removeAttribute(name, true); 154 155 if (oldValue!=null) 156 { 157 try 158 { 159 notifyValueUnbound(name, oldValue); 160 getManager().notifyAttributeRemoved(getSession(), name, oldValue); 161 } 162 catch (Throwable t) 163 { 164 _log.error("error in user owned Listener - notifications may be incomplete", t); 165 } 166 } 167 168 return oldValue; 169 } 170 171 } 173 | Popular Tags |