1 10 11 package org.mmbase.bridge.jsp.taglib.util; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import javax.servlet.jsp.JspTagException ; 17 import javax.servlet.jsp.PageContext ; 18 19 import org.mmbase.bridge.jsp.taglib.ContextProvider; 20 21 import org.mmbase.util.logging.Logger; 22 import org.mmbase.util.logging.Logging; 23 24 32 public class ContextCollector extends StandaloneContextContainer { 33 private static final Logger log = Logging.getLoggerInstance(ContextCollector.class); 34 35 private Set parentCheckedKeys = new HashSet (); 36 37 public ContextCollector(ContextProvider p) throws JspTagException { 38 super(p.getPageContext(), "CONTEXT-COLLECTOR " + (p.getId() == null ? "" : "-" + p.getId()), p.getContextContainer()); 39 backing = new BasicBacking(p.getPageContext(), parent instanceof PageContextContainer) { 40 public Object put(Object key, Object value) { 41 if (parentCheckedKeys.contains(key)) { 42 parent.put(key, value); 43 } else { 44 parentCheckedKeys.add(key); 45 try { 46 parent.register((String ) key, value); 47 } catch (JspTagException jte) { 48 throw new RuntimeException (jte); 49 } 50 } 51 return super.put(key, value); 52 } 53 }; 54 } 55 56 57 public void unRegister(String key) throws JspTagException { 58 super.unRegister(key); 59 parent.unRegister(key); 60 61 } 62 protected void register(String newid, Object n, boolean check, boolean checkParent) throws JspTagException { 63 if (! check) { 64 parent.unRegister(newid); 65 } 66 super.register(newid, n, check, checkParent); 67 68 } 69 70 73 public ContextContainer getContextContainer() { 74 return this; 75 } 76 77 78 79 public void doAfterBody() throws JspTagException { 80 clear(); 81 } 82 83 public void release(PageContext pc, ContextContainer p) { 84 parentCheckedKeys.clear(); 85 super.release(pc, p); 86 } 87 88 } 89 | Popular Tags |