KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > jsp > taglib > util > ContextCollector


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10
11 package org.mmbase.bridge.jsp.taglib.util;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import javax.servlet.jsp.JspTagException JavaDoc;
17 import javax.servlet.jsp.PageContext JavaDoc;
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 /**
25  * A helper class for Lists, to implement ContextProvider. This ContextContainer writes every key to
26  * it's parent too, so it is 'transparent'.
27  *
28  * @author Michiel Meeuwissen
29  * @version $Id: ContextCollector.java,v 1.17.2.1 2006/11/22 14:52:10 michiel Exp $
30  * @since MMBase-1.7
31  */

32 public class ContextCollector extends StandaloneContextContainer {
33     private static final Logger log = Logging.getLoggerInstance(ContextCollector.class);
34
35     private Set JavaDoc parentCheckedKeys = new HashSet JavaDoc();
36
37     public ContextCollector(ContextProvider p) throws JspTagException JavaDoc {
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 JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
41                     if (parentCheckedKeys.contains(key)) {
42                         parent.put(key, value);
43                     } else {
44                         parentCheckedKeys.add(key);
45                         try {
46                             parent.register((String JavaDoc) key, value);
47                         } catch (JspTagException JavaDoc jte) {
48                             throw new RuntimeException JavaDoc(jte);
49                         }
50                     }
51                     return super.put(key, value);
52                 }
53             };
54     }
55
56
57     public void unRegister(String JavaDoc key) throws JspTagException JavaDoc {
58         super.unRegister(key);
59         parent.unRegister(key);
60
61     }
62     protected void register(String JavaDoc newid, Object JavaDoc n, boolean check, boolean checkParent) throws JspTagException JavaDoc {
63         if (! check) {
64             parent.unRegister(newid);
65         }
66         super.register(newid, n, check, checkParent);
67
68     }
69
70     /**
71      * @deprecated
72      */

73     public ContextContainer getContextContainer() {
74         return this;
75     }
76
77
78
79     public void doAfterBody() throws JspTagException JavaDoc {
80         clear();
81     }
82
83     public void release(PageContext JavaDoc pc, ContextContainer p) {
84         parentCheckedKeys.clear();
85         super.release(pc, p);
86     }
87
88 }
89
Popular Tags