1 3 package jodd.petite.scope; 4 5 import jodd.servlet.RequestContextListener; 6 import jodd.madvoc.MadvocException; 7 8 import javax.servlet.http.HttpServletRequest ; 9 import java.util.HashMap ; 10 import java.util.Map ; 11 12 16 public class SessionScope implements Scope { 17 18 protected Map <String , Object > instances = new HashMap <String , Object >(); 19 20 public Object lookup(String name) { 21 HttpServletRequest request = RequestContextListener.getRequest(); 22 if (request == null) { 23 throw new MadvocException("No request binded to current thread (maybe RequestContextListener is not specified?)."); 24 } 25 String id = request.getSession().getId() + '-' + name; 26 return instances.get(id); 27 } 28 29 public void register(String name, Object object) { 30 HttpServletRequest request = RequestContextListener.getRequest(); 31 if (request == null) { 32 throw new MadvocException("No request binded to current thread (maybe RequestContextListener is not specified?)."); 33 } 34 String id = request.getSession().getId() + '-' + name; 35 instances.put(id, object); 36 } 37 38 } 39 40 41 42 | Popular Tags |