View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/StaticDataTag.java,v 1.2 2006/01/13 13:38:51 hkollmann Exp $
3    * $Revision: 1.2 $
4    * $Date: 2006/01/13 13:38:51 $
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.interfaces.IDataContainer;
27  import org.dbforms.interfaces.IStaticDataList;
28  import org.dbforms.interfaces.StaticData;
29  
30  import java.sql.Connection;
31  
32  import java.util.Collection;
33  import java.util.Vector;
34  
35  import javax.servlet.jsp.JspException;
36  import javax.servlet.jsp.PageContext;
37  
38  
39  
40  /***
41   * DOCUMENT ME!
42   *
43   * @author $author$
44   * @version $Revision: 1.2 $
45   */
46  public class StaticDataTag extends AbstractScriptHandlerTag
47     implements javax.servlet.jsp.tagext.TryCatchFinally, IStaticDataList {
48     private String name;
49     private Vector data;
50  
51     /***
52      * set the name of the embedded data. every embedded data entity on a jsp
53      * page has to have a unique name. this name is used for storing (caching)
54      * and retrieving data in Page-Scope. this is useful if a tag gets
55      * evaluated many times -> we do not the tag get parsed more than once
56      * #fixme: encode name in order to avoid naming conficts!
57      *
58      * @param name DOCUMENT ME!
59      */
60     public void setName(String name) {
61        this.name = name;
62     }
63  
64  
65     /***
66      * returns the unique name of the embedded data
67      *
68      * @return DOCUMENT ME!
69      */
70     public String getName() {
71        return name;
72     }
73  
74  
75     /***
76      * DOCUMENT ME!
77      *
78      * @param pair DOCUMENT ME!
79      */
80     public void addElement(StaticData pair) {
81        data.add(pair);
82     }
83  
84  
85     /***
86      * DOCUMENT ME!
87      *
88      * @return DOCUMENT ME!
89      *
90      * @throws JspException DOCUMENT ME!
91      */
92     public int doAfterBody() throws JspException {
93        // make parsed data available to other instances
94        pageContext.setAttribute(name, data, PageContext.PAGE_SCOPE);
95  
96        return SKIP_BODY; // 1 iteration only
97     }
98  
99  
100    /***
101     * DOCUMENT ME!
102     *
103     * @return DOCUMENT ME!
104     *
105     * @throws JspException DOCUMENT ME!
106     */
107    public int doEndTag() throws JspException {
108       ((IDataContainer) getParent()).setEmbeddedData(data); // DbBaseMultiTag are: select, radio, checkbox!
109 
110       return EVAL_PAGE;
111    }
112 
113 
114    /***
115     * DOCUMENT ME!
116     */
117    public void doFinally() {
118       name = null;
119       data = null;
120    }
121 
122 
123    /***
124     * DOCUMENT ME!
125     *
126     * @return DOCUMENT ME!
127     *
128     * @throws JspException DOCUMENT ME!
129     */
130    public int doStartTag() throws JspException {
131       // was the data generated by another instance on the same page yet?
132       data = (Vector) pageContext.getAttribute(name, PageContext.PAGE_SCOPE);
133 
134       // if not, we do it
135       // (the embedded  staticDataItem's will fill the hashtable)
136       if (data == null) {
137          data = new Vector();
138 
139          return EVAL_BODY_BUFFERED;
140       } else {
141          return SKIP_BODY;
142       }
143    }
144 
145 
146    /***
147     * for use from parent element [radio, select, etc.]
148     *
149     * @param con DOCUMENT ME!
150     *
151     * @return DOCUMENT ME!
152     */
153    protected Collection fetchData(Connection con) {
154       return data;
155    }
156 }