KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > interceptors > BookstoreCalcFieldAndSearchInterceptor


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/examples/bookstore/WEB-INF/src/interceptors/BookstoreCalcFieldAndSearchInterceptor.java,v 1.2 2005/02/19 21:50:21 hkollmann Exp $
3  * $Revision: 1.2 $
4  * $Date: 2005/02/19 21:50:21 $
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 interceptors;
24 import org.dbforms.config.DbEventInterceptorData;
25 import org.dbforms.config.MultipleValidationException;
26 import org.dbforms.config.ResultSetVector;
27 import org.dbforms.config.ValidationException;
28
29 import org.dbforms.event.DbEventInterceptorSupport;
30
31
32
33 /**
34  * DOCUMENT ME!
35  *
36  * @author $author$
37  * @version $Revision: 1.2 $
38  */

39 public class BookstoreCalcFieldAndSearchInterceptor
40    extends DbEventInterceptorSupport {
41    /**
42     * DOCUMENT ME!
43     *
44     * @param data DOCUMENT ME!
45     *
46     * @return DOCUMENT ME!
47     *
48     * @throws ValidationException DOCUMENT ME!
49     * @throws MultipleValidationException DOCUMENT ME!
50     */

51    public int preAddRow(DbEventInterceptorData data)
52       throws ValidationException, MultipleValidationException {
53        ResultSetVector rsv = (ResultSetVector) data.getAttribute(DbEventInterceptorData.RESULTSET);
54        Object JavaDoc[] row = (Object JavaDoc[]) data.getAttribute(DbEventInterceptorData.OBJECTROW);
55        int colISBN = rsv.getFieldIndex("ISBN");
56        int res;
57        if (row[colISBN] == null) {
58           res = IGNORE_OPERATION;
59        } else {
60           res = GRANT_OPERATION;
61        }
62        return res;
63    }
64
65
66    /**
67     * DOCUMENT ME!
68     *
69     * @param data DOCUMENT ME!
70     *
71     * @throws ValidationException DOCUMENT ME!
72     * @throws MultipleValidationException DOCUMENT ME!
73     */

74    public void postAddRow(DbEventInterceptorData data) {
75       ResultSetVector rsv = (ResultSetVector) data.getAttribute(DbEventInterceptorData.RESULTSET);
76       Object JavaDoc[] row = (Object JavaDoc[]) data.getAttribute(DbEventInterceptorData.OBJECTROW);
77       int colISBN = rsv.getFieldIndex("ISBN");
78       int colTITEL = rsv.getFieldIndex("TITLE");
79       int colSBN_TITEL = rsv.getFieldIndex("ISBN_TITLE");
80       row[colSBN_TITEL] = "+-" + row[colISBN] + "-CALC-" + row[colTITEL] + "-+";
81
82       int colROWNUM = rsv.getFieldIndex("ROW_NUM");
83       Integer JavaDoc oRowNum = (Integer JavaDoc) data.getAttribute("ROWNUM");
84       int rowNum = 0;
85
86       if (oRowNum != null) {
87          rowNum = oRowNum.intValue();
88       }
89
90       rowNum++;
91       oRowNum = new Integer JavaDoc(rowNum);
92       data.setAttribute("ROWNUM", oRowNum);
93       row[colROWNUM] = oRowNum;
94    }
95 }
96
Popular Tags