1 6 package org.mortbay.j2ee.session; 7 8 import java.util.ArrayList ; 9 import java.util.ListIterator ; 10 11 import javax.servlet.http.HttpSession ; 12 13 import org.jfox.ioc.logger.Logger; 14 15 public class 16 Container 17 extends ArrayList 18 implements Cloneable 19 { 20 protected static final Logger _log= Logger.getLogger(Container.class); 21 22 25 36 public Object 37 clone() 38 { 39 Container c=new Container(); 40 41 try 42 { 43 State state=null; 44 45 for (ListIterator i=listIterator(size()); i.hasPrevious();) 46 { 47 State lastState=state; 48 StateInterceptor si=(StateInterceptor)i.previous(); 49 si=(StateInterceptor)si.getClass().newInstance(); 50 si.setState(lastState); 51 state=si; 52 c.add(0,state); 53 } 54 } 55 catch (Exception e) 56 { 57 _log.error("could not clone Container", e); 58 } 59 60 return c; 61 } 62 63 65 public static HttpSession 66 newContainer(Manager manager, String id, State state, int maxInactiveInterval, long currentSecond, StateInterceptor[] interceptors) 67 { 68 70 StateAdaptor adp=new StateAdaptor(id, manager, maxInactiveInterval, currentSecond); 71 72 State last=state; 73 try 74 { 75 Class [] ctorParams={}; 76 for (int i=interceptors.length; i>0; i--) 77 { 78 StateInterceptor si=interceptors[i-1]; 79 StateInterceptor interceptor=(StateInterceptor)si.clone(); 81 si.setManager(manager); si.setSession(adp); interceptor.setState(last); interceptor.start(); 85 last=interceptor; 86 } 87 } 88 catch (Exception e) 89 { 90 _log.error("could not build distributed HttpSession container", e); 91 } 92 93 adp.setState(last); 94 95 return adp; 96 } 97 98 public static State 99 destroyContainer(HttpSession session, StateInterceptor[] interceptors) 100 { 101 103 StateAdaptor sa=(StateAdaptor)session; 104 State last=sa.getState(); sa.setState(null); 105 106 for (int i=interceptors.length; i>0; i--) 107 { 108 StateInterceptor si=(StateInterceptor)last; 109 si.stop(); 110 State s=si.getState(); 111 si.setState(null); 112 last=s; 113 } 114 115 return last; 116 } 117 } 118 | Popular Tags |