1 20 package org.enhydra.barracuda.plankton.http; 21 22 import java.lang.ref.*; 23 import javax.servlet.*; 24 25 import org.apache.log4j.*; 26 27 import org.enhydra.barracuda.plankton.data.ReferenceFactory; 28 29 30 36 public class ContextServices { 37 38 public static final String KEY = ContextServices.class.getName()+".Key"; 40 41 protected static final Logger logger = Logger.getLogger(ContextServices.class.getName()); 42 43 53 public static Object getObjectFromCache(ServletContext context, Object key, ReferenceFactory factory) { 54 Reference r = (Reference) context.getAttribute(KEY+key); 55 Object obj = null; 56 if (r!=null) obj = r.get(); 57 if (r==null || obj==null) { 58 r = factory.getObjectReference(); 59 obj = r.get(); 60 context.setAttribute(KEY+key, r); 61 if (logger.isDebugEnabled()) logger.debug("Created reference:"+r); 62 } 63 if (logger.isDebugEnabled()) logger.debug("Returning object from cache:"+obj); 64 return obj; 65 } 66 67 68 69 } 70 | Popular Tags |