1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.taglib;
25
26 import javax.servlet.jsp.JspException;
27 import javax.servlet.jsp.PageContext;
28
29 import javax.sql.DataSource;
30
31
32
33 /***
34 * DOCUMENT ME!
35 *
36 * @author $author$
37 * @version $Revision: 1.2 $
38 */
39 public class DbSetDataSourceTag extends AbstractDbBaseHandlerTag
40 implements javax.servlet.jsp.tagext.TryCatchFinally {
41 private String dataSource;
42 private String dbConnectionName;
43
44 /***
45 * DOCUMENT ME!
46 *
47 * @param string
48 */
49 public void setDataSource(String string) {
50 dataSource = string;
51 }
52
53
54 /***
55 * DOCUMENT ME!
56 *
57 * @return
58 */
59 public String getDataSource() {
60 return dataSource;
61 }
62
63
64 /***
65 * DOCUMENT ME!
66 *
67 * @param name DOCUMENT ME!
68 */
69 public void setDbConnectionName(String name) {
70 dbConnectionName = name;
71 }
72
73
74 /***
75 * DOCUMENT ME!
76 *
77 * @return DOCUMENT ME!
78 */
79 public String getDbConnectionName() {
80 return dbConnectionName;
81 }
82
83
84 /***
85 * DOCUMENT ME!
86 */
87 public void doFinally() {
88 dbConnectionName = null;
89 super.doFinally();
90 }
91
92
93 /***
94 * DOCUMENT ME!
95 *
96 * @return DOCUMENT ME!
97 *
98 * @throws JspException DOCUMENT ME!
99 * @throws IllegalArgumentException DOCUMENT ME!
100 */
101 public int doStartTag() throws JspException {
102 try {
103
104 DataSource ds = getConfig()
105 .getDataSource(dbConnectionName);
106 pageContext.setAttribute(getDataSource(), ds, PageContext.PAGE_SCOPE);
107 } catch (Exception e) {
108 throw new JspException("Database error" + e.getMessage());
109 }
110
111 return SKIP_BODY;
112 }
113 }