KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/TableData.java,v 1.19 2004/10/20 10:52:03 hkollmann Exp $
3  * $Revision: 1.19 $
4  * $Date: 2004/10/20 10:52:03 $
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 package org.dbforms.taglib;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 import org.dbforms.config.DbEventInterceptorData;
28 import org.dbforms.config.ResultSetVector;
29
30 import org.dbforms.util.StringUtil;
31
32 import java.sql.Connection JavaDoc;
33 import java.sql.PreparedStatement JavaDoc;
34 import java.sql.SQLException JavaDoc;
35
36 import java.util.List JavaDoc;
37 import java.util.Vector JavaDoc;
38
39 import javax.servlet.http.HttpServletRequest JavaDoc;
40
41
42
43 /**
44  * external data to be nested into radio, checkbox or select - tag! (useful
45  * only in conjunction with radio, checkbox or select - tag)
46  *
47  * <p>
48  * this tag provides data to radio, checkbox or select - tags. it may be used
49  * for cross-references to other tables.
50  * </p>
51  *
52  * @author Joachim Peer
53  */

54 public class TableData extends EmbeddedData
55    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
56    private static Log logCat = LogFactory.getLog(TableData.class.getName());
57
58    // logging category for this class
59
private String JavaDoc foreignTable;
60    private String JavaDoc orderBy;
61    private String JavaDoc storeField;
62    private String JavaDoc visibleFields;
63
64    /**
65     * DOCUMENT ME!
66     *
67     * @param foreignTable DOCUMENT ME!
68     */

69    public void setForeignTable(String JavaDoc foreignTable) {
70       this.foreignTable = foreignTable;
71    }
72
73
74    /**
75     * DOCUMENT ME!
76     *
77     * @return DOCUMENT ME!
78     */

79    public String JavaDoc getForeignTable() {
80       return foreignTable;
81    }
82
83
84    /**
85     * DOCUMENT ME!
86     *
87     * @param orderBy DOCUMENT ME!
88     */

89    public void setOrderBy(String JavaDoc orderBy) {
90       this.orderBy = orderBy;
91       logCat.info("setOrderBy(\"" + orderBy + "\")");
92    }
93
94
95    /**
96     * DOCUMENT ME!
97     *
98     * @return DOCUMENT ME!
99     */

100    public String JavaDoc getOrderBy() {
101       return orderBy;
102    }
103
104
105    /**
106     * DOCUMENT ME!
107     *
108     * @param storeField DOCUMENT ME!
109     */

110    public void setStoreField(String JavaDoc storeField) {
111       this.storeField = storeField;
112    }
113
114
115    /**
116     * DOCUMENT ME!
117     *
118     * @return DOCUMENT ME!
119     */

120    public String JavaDoc getStoreField() {
121       return storeField;
122    }
123
124
125    /**
126     * DOCUMENT ME!
127     *
128     * @param visibleFields DOCUMENT ME!
129     */

130    public void setVisibleFields(String JavaDoc visibleFields) {
131       this.visibleFields = visibleFields;
132    }
133
134
135    /**
136     * DOCUMENT ME!
137     *
138     * @return DOCUMENT ME!
139     */

140    public String JavaDoc getVisibleFields() {
141       return visibleFields;
142    }
143
144
145    /**
146     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
147     */

148    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
149       throw t;
150    }
151
152
153    /**
154     * DOCUMENT ME!
155     */

156    public void doFinally() {
157       foreignTable = null;
158       visibleFields = null;
159       storeField = null;
160       orderBy = null;
161       super.doFinally();
162    }
163
164
165    /**
166     * returns Hashtable with data. Its keys represent the "value"-fields for
167     * the DataContainer-Tag, its values represent the visible fields for
168     * the Multitags. (DataContainer are: select, radio, checkbox and a
169     * special flavour of Label).
170     *
171     * @param con DOCUMENT ME!
172     *
173     * @return DOCUMENT ME!
174     */

175    protected List JavaDoc fetchData(Connection JavaDoc con) throws SQLException JavaDoc {
176       Vector vf = StringUtil.splitString(visibleFields, ",;~");
177
178       StringBuffer JavaDoc queryBuf = new StringBuffer JavaDoc();
179
180       queryBuf.append("SELECT ");
181       queryBuf.append(storeField);
182       queryBuf.append(", ");
183
184       for (int i = 0; i < vf.size(); i++) {
185          queryBuf.append((String JavaDoc) vf.elementAt(i));
186
187          if (i < (vf.size() - 1)) {
188             queryBuf.append(", ");
189          }
190       }
191
192       queryBuf.append(" FROM ");
193       queryBuf.append(foreignTable);
194
195       if (orderBy != null) {
196          queryBuf.append(" ORDER BY ");
197          queryBuf.append(orderBy);
198       }
199
200       logCat.info("about to execute:" + queryBuf.toString());
201
202       PreparedStatement JavaDoc ps = con.prepareStatement(queryBuf.toString());
203       ResultSetVector rsv = null;
204
205       try {
206          rsv = new ResultSetVector();
207
208          HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext
209             .getRequest();
210          DbEventInterceptorData data = new DbEventInterceptorData(request,
211                getConfig(), con, null);
212          data.setAttribute(DbEventInterceptorData.PAGECONTEXT,
213                 pageContext);
214          rsv.addResultSet(data, ps.executeQuery());
215       } finally {
216          ps.close(); // #JP Jun 27, 2001
217
}
218
219       return formatEmbeddedResultRows(rsv);
220    }
221 }
222
Popular Tags