View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/event/DbEventInterceptorSupport.java,v 1.19 2005/11/29 19:18:37 hkollmann Exp $
3    * $Revision: 1.19 $
4    * $Date: 2005/11/29 19:18:37 $
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;
25  
26  import org.dbforms.config.DbFormsConfig;
27  import org.dbforms.config.Field;
28  import org.dbforms.config.FieldValue;
29  import org.dbforms.config.FieldValues;
30  import org.dbforms.config.MultipleValidationException;
31  import org.dbforms.config.Table;
32  import org.dbforms.config.ValidationException;
33  import org.dbforms.interfaces.DbEventInterceptorData;
34  import org.dbforms.interfaces.IDbEventInterceptor;
35  
36  import java.sql.Connection;
37  
38  import java.util.Map;
39  
40  import javax.servlet.http.HttpServletRequest;
41  
42  
43  
44  /***
45   * convenience class
46   *
47   * @author Joe Peer
48   */
49  public class DbEventInterceptorSupport implements IDbEventInterceptor {
50     private Map params;
51  
52     /* (non-Javadoc)
53      * @see org.dbforms.config.DbEventInterceptor#setParameterMap(java.util.Map)
54      */
55     public void setParameterMap(Map params) {
56        this.params = params;
57     }
58  
59  
60     /* (non-Javadoc)
61      * @see org.dbforms.config.DbEventInterceptor#getParameterMap()
62      */
63     public Map getParameterMap() {
64        return params;
65     }
66  
67     /* (non-Javadoc)
68      * @see org.dbforms.config.DbEventInterceptor#getParameterMap()
69      */
70     public String getParameter(String key) {
71        return (String)params.get(key);
72     }
73  
74  
75     /* (non-Javadoc)
76      * @see org.dbforms.config.DbEventInterceptor#postAddRow(org.dbforms.config.DbEventInterceptorData)
77      */
78     public void postAddRow(DbEventInterceptorData data) {
79     }
80  
81  
82     /* (non-Javadoc)
83      * @see org.dbforms.config.DbEventInterceptor#postDelete(org.dbforms.config.Table, org.dbforms.config.DbEventInterceptorData)
84      */
85     public void postDelete(DbEventInterceptorData data) {
86        postDelete(data.getRequest(), data.getConfig(), data.getConnection());
87     }
88  
89  
90     /***
91      * DOCUMENT ME!
92      *
93      * @param request DOCUMENT ME!
94      * @param config DOCUMENT ME!
95      * @param con DOCUMENT ME!
96      *
97      * @deprecated
98      */
99     public void postDelete(HttpServletRequest request,
100                           DbFormsConfig      config,
101                           Connection         con) {
102    }
103 
104 
105    /* (non-Javadoc)
106     * @see org.dbforms.config.DbEventInterceptor#postInsert(org.dbforms.config.Table, org.dbforms.config.DbEventInterceptorData)
107     */
108    public void postInsert(DbEventInterceptorData data) {
109       postInsert(data.getRequest(), data.getConfig(), data.getConnection());
110    }
111 
112 
113    /***
114     * DOCUMENT ME!
115     *
116     * @param request DOCUMENT ME!
117     * @param config DOCUMENT ME!
118     * @param con DOCUMENT ME!
119     *
120     * @deprecated
121     */
122    public void postInsert(HttpServletRequest request,
123                           DbFormsConfig      config,
124                           Connection         con) {
125    }
126 
127 
128    /* (non-Javadoc)
129     * @see org.dbforms.config.DbEventInterceptor#postSelect(org.dbforms.config.Table, org.dbforms.config.DbEventInterceptorData)
130     */
131    public void postSelect(DbEventInterceptorData data) {
132       postSelect(data.getRequest(), data.getConfig(), data.getConnection());
133    }
134 
135 
136    /***
137     * DOCUMENT ME!
138     *
139     * @param request DOCUMENT ME!
140     * @param config DOCUMENT ME!
141     * @param con DOCUMENT ME!
142     *
143     * @deprecated
144     */
145    public void postSelect(HttpServletRequest request,
146                           DbFormsConfig      config,
147                           Connection         con) {
148    }
149 
150 
151    /* (non-Javadoc)
152     * @see org.dbforms.config.DbEventInterceptor#postUpdate(org.dbforms.config.Table, org.dbforms.config.DbEventInterceptorData)
153     */
154    public void postUpdate(DbEventInterceptorData data) {
155       postUpdate(data.getRequest(), data.getConfig(), data.getConnection());
156    }
157 
158 
159    /***
160     * DOCUMENT ME!
161     *
162     * @param request DOCUMENT ME!
163     * @param config DOCUMENT ME!
164     * @param con DOCUMENT ME!
165     *
166     * @deprecated
167     */
168    public void postUpdate(HttpServletRequest request,
169                           DbFormsConfig      config,
170                           Connection         con) {
171    }
172 
173 
174    /* (non-Javadoc)
175     * @see org.dbforms.config.DbEventInterceptor#preAddRow(org.dbforms.config.DbEventInterceptorData)
176     */
177    public int preAddRow(DbEventInterceptorData data)
178                  throws ValidationException, MultipleValidationException {
179       return GRANT_OPERATION;
180    }
181 
182 
183    /* (non-Javadoc)
184     * @see org.dbforms.config.DbEventInterceptor#preDelete(org.dbforms.config.Table, org.dbforms.config.DbEventInterceptorData)
185     */
186    public int preDelete(DbEventInterceptorData data)
187                  throws ValidationException, MultipleValidationException {
188       return preDelete(data.getRequest(), data.getTable(),
189                        (FieldValues) data.getAttribute(DbEventInterceptorData.FIELDVALUES),
190                        data.getConfig(), data.getConnection());
191    }
192 
193 
194    /***
195     * DOCUMENT ME!
196     *
197     * @param request DOCUMENT ME!
198     * @param table DOCUMENT ME!
199     * @param fieldValues DOCUMENT ME!
200     * @param config DOCUMENT ME!
201     * @param con DOCUMENT ME!
202     *
203     * @return DOCUMENT ME!
204     *
205     * @throws ValidationException DOCUMENT ME!
206     *
207     * @deprecated
208     */
209    public int preDelete(HttpServletRequest request,
210                         Table              table,
211                         FieldValues        fieldValues,
212                         DbFormsConfig      config,
213                         Connection         con) throws ValidationException {
214       return GRANT_OPERATION;
215    }
216 
217 
218    /* (non-Javadoc)
219     * @see org.dbforms.config.DbEventInterceptor#preInsert(org.dbforms.config.Table, org.dbforms.config.DbEventInterceptorData)
220     */
221    public int preInsert(DbEventInterceptorData data)
222                  throws ValidationException, MultipleValidationException {
223       return preInsert(data.getRequest(), data.getTable(),
224                        (FieldValues) data.getAttribute(DbEventInterceptorData.FIELDVALUES),
225                        data.getConfig(), data.getConnection());
226    }
227 
228 
229    /***
230     * DOCUMENT ME!
231     *
232     * @param request DOCUMENT ME!
233     * @param table DOCUMENT ME!
234     * @param fieldValues DOCUMENT ME!
235     * @param config DOCUMENT ME!
236     * @param con DOCUMENT ME!
237     *
238     * @return DOCUMENT ME!
239     *
240     * @throws ValidationException DOCUMENT ME!
241     *
242     * @deprecated
243     */
244    public int preInsert(HttpServletRequest request,
245                         Table              table,
246                         FieldValues        fieldValues,
247                         DbFormsConfig      config,
248                         Connection         con) throws ValidationException {
249       return GRANT_OPERATION;
250    }
251 
252 
253    /* (non-Javadoc)
254     * @see org.dbforms.config.DbEventInterceptor#preSelect(org.dbforms.config.Table, org.dbforms.config.DbEventInterceptorData)
255     */
256    public int preSelect(DbEventInterceptorData data)
257                  throws ValidationException, MultipleValidationException {
258       return preSelect(data.getRequest(), data.getConfig(), data.getConnection());
259    }
260 
261 
262    /***
263     * DOCUMENT ME!
264     *
265     * @param request DOCUMENT ME!
266     * @param config DOCUMENT ME!
267     * @param con DOCUMENT ME!
268     *
269     * @return DOCUMENT ME!
270     *
271     * @throws ValidationException DOCUMENT ME!
272     *
273     * @deprecated
274     */
275    public int preSelect(HttpServletRequest request,
276                         DbFormsConfig      config,
277                         Connection         con) throws ValidationException {
278       return GRANT_OPERATION;
279    }
280 
281 
282    /* (non-Javadoc)
283     * @see org.dbforms.config.DbEventInterceptor#preUpdate(org.dbforms.config.Table, org.dbforms.config.DbEventInterceptorData)
284     */
285    public int preUpdate(DbEventInterceptorData data)
286                  throws ValidationException, MultipleValidationException {
287       return preUpdate(data.getRequest(), data.getTable(),
288                        (FieldValues) data.getAttribute(DbEventInterceptorData.FIELDVALUES),
289                        data.getConfig(), data.getConnection());
290    }
291 
292 
293    /***
294     * DOCUMENT ME!
295     *
296     * @param request DOCUMENT ME!
297     * @param table DOCUMENT ME!
298     * @param fieldValues DOCUMENT ME!
299     * @param config DOCUMENT ME!
300     * @param con DOCUMENT ME!
301     *
302     * @return DOCUMENT ME!
303     *
304     * @throws ValidationException DOCUMENT ME!
305     *
306     * @deprecated
307     */
308    public int preUpdate(HttpServletRequest request,
309                         Table              table,
310                         FieldValues        fieldValues,
311                         DbFormsConfig      config,
312                         Connection         con) throws ValidationException {
313       return GRANT_OPERATION;
314    }
315 
316 
317    /***
318     * adds or replace a value in the fieldValues
319     *
320     * @param table wich should be used to lookup for the fieldName
321     * @param fieldValues to add/replace value to
322     * @param fieldName to add/replace value
323     * @param value to add/replace
324     */
325    protected void setValue(Table       table,
326                            FieldValues fieldValues,
327                            String      fieldName,
328                            String      value) {
329       FieldValue fv = fieldValues.get(fieldName);
330       Field      f = table.getFieldByName(fieldName);
331 
332       if (f != null) {
333          if (fv == null) {
334             fv = new FieldValue(f, value);
335             fieldValues.put(fv);
336          } else {
337             fv.setFieldValue(value);
338          }
339       }
340    }
341 }