KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > StaticData


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/StaticData.java,v 1.12 2004/08/18 12:26:08 hkollmann Exp $
3  * $Revision: 1.12 $
4  * $Date: 2004/08/18 12:26:08 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.taglib;
25
26 import org.dbforms.util.KeyValuePair;
27
28 import java.sql.Connection JavaDoc;
29
30 import java.util.Collection JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import javax.servlet.jsp.JspException JavaDoc;
34 import javax.servlet.jsp.PageContext JavaDoc;
35
36
37
38 /**
39  * DOCUMENT ME!
40  *
41  * @author $author$
42  * @version $Revision: 1.12 $
43  */

44 public class StaticData extends TagSupportWithScriptHandler
45    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc, StaticDataAddInterface {
46    private String JavaDoc name;
47    private Vector JavaDoc data;
48
49    /**
50     * set the name of the embedded data. every embedded data entity on a jsp
51     * page has to have a unique name. this name is used for storing (caching)
52     * and retrieving data in Page-Scope. this is useful if a tag gets
53     * evaluated many times -> we do not the tag get parsed more than once
54     * #fixme: encode name in order to avoid naming conficts!
55     *
56     * @param name DOCUMENT ME!
57     */

58    public void setName(String JavaDoc name) {
59       this.name = name;
60    }
61
62
63    /**
64     * returns the unique name of the embedded data
65     *
66     * @return DOCUMENT ME!
67     */

68    public String JavaDoc getName() {
69       return name;
70    }
71
72
73    /**
74     * DOCUMENT ME!
75     *
76     * @param pair DOCUMENT ME!
77     */

78    public void addElement(KeyValuePair pair) {
79       data.add(pair);
80    }
81
82
83    /**
84     * DOCUMENT ME!
85     *
86     * @return DOCUMENT ME!
87     *
88     * @throws JspException DOCUMENT ME!
89     */

90    public int doAfterBody() throws JspException JavaDoc {
91       // make parsed data available to other instances
92
pageContext.setAttribute(name, data, PageContext.PAGE_SCOPE);
93
94       return SKIP_BODY; // 1 iteration only
95
}
96
97
98    /**
99     * DOCUMENT ME!
100     *
101     * @param t DOCUMENT ME!
102     *
103     * @throws Throwable DOCUMENT ME!
104     */

105    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
106       throw t;
107    }
108
109
110    /**
111     * DOCUMENT ME!
112     *
113     * @return DOCUMENT ME!
114     *
115     * @throws JspException DOCUMENT ME!
116     */

117    public int doEndTag() throws JspException JavaDoc {
118       ((DataContainer) getParent()).setEmbeddedData(data); // DbBaseMultiTag are: select, radio, checkbox!
119

120       return EVAL_PAGE;
121    }
122
123
124    /**
125     * DOCUMENT ME!
126     */

127    public void doFinally() {
128       name = null;
129       data = null;
130    }
131
132
133    /**
134     * DOCUMENT ME!
135     *
136     * @return DOCUMENT ME!
137     *
138     * @throws JspException DOCUMENT ME!
139     */

140    public int doStartTag() throws JspException JavaDoc {
141       // was the data generated by another instance on the same page yet?
142
data = (Vector JavaDoc) pageContext.getAttribute(name, PageContext.PAGE_SCOPE);
143
144       // if not, we do it
145
// (the embedded staticDataItem's will fill the hashtable)
146
if (data == null) {
147          data = new Vector JavaDoc();
148
149          return EVAL_BODY_BUFFERED;
150       } else {
151          return SKIP_BODY;
152       }
153    }
154
155
156    /**
157     * for use from parent element [radio, select, etc.]
158     *
159     * @param con DOCUMENT ME!
160     *
161     * @return DOCUMENT ME!
162     */

163    protected Collection JavaDoc fetchData(Connection JavaDoc con) {
164       return data;
165    }
166 }
167
Popular Tags