KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbSetDataSource.java,v 1.4 2004/08/18 12:26:08 hkollmann Exp $
3  * $Revision: 1.4 $
4  * $Date: 2004/08/18 12:26:08 $
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 javax.servlet.jsp.JspException JavaDoc;
27 import javax.servlet.jsp.PageContext JavaDoc;
28
29 import javax.sql.DataSource JavaDoc;
30
31
32
33 /**
34  * DOCUMENT ME!
35  *
36  * @author $author$
37  * @version $Revision: 1.4 $
38  */

39 public class DbSetDataSource extends DbBaseHandlerTag
40    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
41    private String JavaDoc dataSource;
42    private String JavaDoc dbConnectionName;
43
44    /**
45     * DOCUMENT ME!
46     *
47     * @param string
48     */

49    public void setDataSource(String JavaDoc string) {
50       dataSource = string;
51    }
52
53
54    /**
55     * DOCUMENT ME!
56     *
57     * @return
58     */

59    public String JavaDoc getDataSource() {
60       return dataSource;
61    }
62
63
64    /**
65     * DOCUMENT ME!
66     *
67     * @param name DOCUMENT ME!
68     */

69    public void setDbConnectionName(String JavaDoc name) {
70       dbConnectionName = name;
71    }
72
73
74    /**
75     * DOCUMENT ME!
76     *
77     * @return DOCUMENT ME!
78     */

79    public String JavaDoc getDbConnectionName() {
80       return dbConnectionName;
81    }
82
83
84    /**
85     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
86     */

87    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
88       throw t;
89    }
90
91
92    /**
93     * DOCUMENT ME!
94     */

95    public void doFinally() {
96       dbConnectionName = null;
97       super.doFinally();
98    }
99
100
101    /**
102     * DOCUMENT ME!
103     *
104     * @return DOCUMENT ME!
105     *
106     * @throws JspException DOCUMENT ME!
107     * @throws IllegalArgumentException DOCUMENT ME!
108     */

109    public int doStartTag() throws JspException JavaDoc {
110       try {
111          // get the connection and place it in attribute;
112
DataSource JavaDoc ds = getConfig()
113                             .getDataSource(dbConnectionName);
114          pageContext.setAttribute(getDataSource(), ds, PageContext.PAGE_SCOPE);
115       } catch (Exception JavaDoc e) {
116          throw new JspException JavaDoc("Database error" + e.getMessage());
117       }
118
119       return SKIP_BODY;
120    }
121 }
122
Popular Tags