1 package jfun.yan.xfire; 2 3 import jfun.yan.factory.Factory; 4 import jfun.yan.factory.Pool; 5 import jfun.yan.factory.PooledFactory; 6 import jfun.yan.factory.SimplePool; 7 8 import org.codehaus.xfire.MessageContext; 9 import org.codehaus.xfire.service.Service; 10 import org.codehaus.xfire.transport.Session; 11 12 18 public class SessionScopePolicy implements ScopePolicy { 19 24 protected Object getServiceKey(Service service){ 25 return "service." + service.getSimpleName(); 26 } 27 public Factory applyScope(Factory f, MessageContext ctxt) { 28 return new PooledFactory(f, 29 getSessionScope(getServiceKey(ctxt.getService()), ctxt.getSession())); 30 } 31 public String toString(){ 32 return "session scope"; 33 } 34 private static Pool getSessionScope(final Object key, final Session session){ 35 return new SimplePool(){ 36 public Object get() { 37 return session.get(key); 38 } 39 public void set(Object val) { 40 session.put(key, val); 41 } 42 public String toString(){ 43 return "session scope"; 44 } 45 49 protected Object getMutex(){ 50 return Service.class; 51 } 52 }; 53 } 54 protected SessionScopePolicy(){} 55 private static final SessionScopePolicy singleton = new SessionScopePolicy(); 56 59 public static ScopePolicy instance(){ 60 return singleton; 61 } 62 } 63 | Popular Tags |