KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > event > classic > GotoEvent


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/event/classic/GotoEvent.java,v 1.18 2005/02/19 21:26:30 hkollmann Exp $
3  * $Revision: 1.18 $
4  * $Date: 2005/02/19 21:26:30 $
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.event.classic;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.dbforms.config.*;
30
31 import org.dbforms.event.NavigationEvent;
32
33 import org.dbforms.util.*;
34
35 import java.io.UnsupportedEncodingException JavaDoc;
36
37 import java.sql.*;
38
39 import javax.servlet.http.*;
40
41
42
43 /**
44  * DOCUMENT ME!
45  *
46  * @author Joe Peer
47  *
48  * @deprecated This event forces the controller to forward the current request
49  * to a Request-Dispatcher specified by the Application-Developer
50  * in a "org.dbforms.taglib.DbGotoButton".
51  */

52 public class GotoEvent extends NavigationEvent {
53    // logging category for this class;
54
static Log logCat = LogFactory.getLog(GotoEvent.class.getName());
55    private String JavaDoc childField;
56    private String JavaDoc parentField;
57
58    // where to go in associated table
59
private String JavaDoc position;
60    private String JavaDoc tableList = null;
61    private String JavaDoc whereClause = null;
62    private Table srcTable;
63
64    /**
65     * <p>
66     * constructor - parses the event details
67     * </p>
68     *
69     * <p>
70     * Depending on the way the attributes where provided by the developer,
71     * different ways are used for resolving the dispatcher the user wants to
72     * get called and the position he wants the ResultSet to be scrolled to.
73     * </p>
74     *
75     * @param action DOCUMENT ME!
76     * @param request DOCUMENT ME!
77     * @param config DOCUMENT ME!
78     */

79    public GotoEvent(String JavaDoc action,
80                     HttpServletRequest request,
81                     DbFormsConfig config) {
82       super(action, request, config);
83
84       String JavaDoc destTable = ParseUtil.getParameter(request,
85                                                 "data" + action + "_destTable");
86
87       if (destTable == null) {
88          setTable(null);
89
90          return; // if the user wants a simple, dumb link and we want no form to be navigated through
91
}
92
93       //# fixme: decision for *1* of the 2 approaches should be met soon!! (either id- OR name-based lookup)
94
setTable(config.getTableByName(destTable));
95
96       if (getTable() == null) {
97          setTable(config.getTable(Integer.parseInt(destTable)));
98       }
99
100       String JavaDoc psrcTable = ParseUtil.getParameter(request,
101                                                "data" + action + "_srcTable");
102
103       if (psrcTable != null) {
104          this.srcTable = config.getTableByName(psrcTable);
105
106          if (this.srcTable == null) {
107             this.srcTable = config.getTable(Integer.parseInt(psrcTable));
108          }
109
110          childField = ParseUtil.getParameter(request,
111                                              "data" + action + "_childField");
112          parentField = ParseUtil.getParameter(request,
113                                               "data" + action + "_parentField");
114       }
115
116       // the position to go to within the destination-jsp's-table can be given
117
// more or less directly
118
String JavaDoc destPos = ParseUtil.getParameter(request,
119                                               "data" + action + "_destPos");
120
121       // the direct way - i.e. "1:5:value"
122
if (destPos != null) {
123          this.position = destPos;
124       } else {
125          String JavaDoc keyToDestPos = ParseUtil.getParameter(request,
126                                                       "data" + action
127                                                       + "_keyToDestPos");
128
129          // the 1-leveled indirect way: i.e. "k_1_1" whereby k_1_1 leads to "1:2:23"
130
if (keyToDestPos != null) {
131             this.position = ParseUtil.getParameter(request, keyToDestPos);
132          } else {
133             String JavaDoc keyToKeyToDestPos = ParseUtil.getParameter(request,
134                                                               "data" + action
135                                                               + "_keyToKeyToDestPos");
136
137             // the 2-leveled indirect way: i.e. "my_sel" wherby "mysel" leads to "1_1",
138
// which leads to "1:2:23"
139
if (keyToKeyToDestPos != null) {
140                String JavaDoc widgetValue = ParseUtil.getParameter(request,
141                                                            keyToKeyToDestPos); // i.e. "1_1"
142

143                this.position = ParseUtil.getParameter(request,
144                                                       "k_" + widgetValue); // i.e. 1:2:23
145
}
146          }
147       }
148
149       logCat.info("--->pos=" + position);
150    }
151
152
153    /**
154     * this constructer is not called by the controller but, actually, BY THE
155     * VIEW for example if the FormTag "gotoPrefix" attribute is set an a
156     * GotoEvent needs to be instanciated
157     *
158     * @param table DOCUMENT ME!
159     * @param request DOCUMENT ME!
160     * @param config DOCUMENT ME!
161     * @param position DOCUMENT ME!
162     */

163    public GotoEvent(Table table,
164                     HttpServletRequest request,
165                     DbFormsConfig config,
166                     String JavaDoc position) {
167       super(table, request, config);
168       this.position = position;
169    }
170
171
172    /**
173     * this constructer is not called by the controller but, actually, BY THE
174     * VIEW for example if the FormTag needs a free form select, this
175     * constructor is called
176     *
177     * @param table DOCUMENT ME!
178     * @param request DOCUMENT ME!
179     * @param config DOCUMENT ME!
180     * @param whereClause DOCUMENT ME!
181     * @param tableList DOCUMENT ME!
182     */

183    public GotoEvent(Table table,
184                     HttpServletRequest request,
185                     DbFormsConfig config,
186                     String JavaDoc whereClause,
187                     String JavaDoc tableList) {
188       super(table, request, config);
189       this.whereClause = whereClause;
190       this.tableList = tableList;
191    }
192
193    /**
194     * Process the current event.
195     *
196     * @param childFieldValues FieldValue array used to restrict a set of data
197     * @param orderConstraint FieldValue array used to build a cumulation of
198     * rules for ordering (sorting) and restricting fields to the actual
199     * block of data
200     * @param firstPosition DOCUMENT ME!
201     * @param sqlFilterParams a string identifying the last resultset position
202     * @param count record count
203     * @param firstPosition a string identifying the first resultset position
204     * @param lastPosition DOCUMENT ME!
205     * @param dbConnectionName name of the used db connection. Can be used to
206     * get an own db connection, e.g. to hold it during the session (see
207     * DataSourceJDBC for example!)
208     * @param con the JDBC Connection object
209     *
210     * @return a ResultSetVector object
211     *
212     * @exception SQLException if any error occurs
213     */

214    public ResultSetVector processEvent(FieldValue[] childFieldValues,
215                                        FieldValue[] orderConstraint,
216                                        String JavaDoc sqlFilter,
217                                        FieldValue[] sqlFilterParams,
218                                        int count,
219                                        String JavaDoc firstPosition,
220                                        String JavaDoc lastPosition,
221                                        DbEventInterceptorData interceptorData)
222                                 throws SQLException {
223       if (Util.isNull(whereClause)) {
224          try {
225             position = Util.decode(position, getRequest().getCharacterEncoding());
226          } catch (UnsupportedEncodingException JavaDoc e) {
227             logCat.error(e);
228             throw new SQLException(e.getMessage());
229          }
230
231          // Standard way
232
int compMode = (!Util.isNull(position)) ? Constants.COMPARE_INCLUSIVE
233                                                  : Constants.COMPARE_NONE;
234
235          if (!Util.isNull(position)
236                    && (srcTable != null)
237                    && !Util.isNull(childField)
238                    && !Util.isNull(parentField)) {
239             FieldValues fv = getTable()
240                                 .mapChildFieldValues(srcTable, parentField,
241                                                      childField, position);
242
243             if (fv != null) {
244                childFieldValues = fv.toArray();
245                compMode = Constants.COMPARE_NONE;
246             }
247          } else if (!Util.isNull(position)) {
248             getTable()
249                .fillWithValues(orderConstraint, position);
250          }
251
252          logCat.info("gotopos = " + position);
253
254          return getTable()
255                    .doConstrainedSelect(childFieldValues, orderConstraint,
256                                         sqlFilter, sqlFilterParams, compMode,
257                                         count, interceptorData);
258       } else {
259          // free form select
260
return getTable()
261                    .doFreeFormSelect(whereClause,
262                                      tableList, count, interceptorData);
263       }
264    }
265 }
266
Popular Tags