KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jstl > rt > SqlSetDataSourceTag


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source 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, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jstl.rt;
30
31 import com.caucho.log.Log;
32 import com.caucho.util.L10N;
33
34 import javax.servlet.jsp.JspException JavaDoc;
35 import javax.servlet.jsp.jstl.core.Config;
36 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
37 import javax.sql.DataSource JavaDoc;
38 import java.util.logging.Logger JavaDoc;
39
40 public class SqlSetDataSourceTag extends TagSupport JavaDoc {
41   private static final Logger JavaDoc log = Log.open(SqlSetDataSourceTag.class);
42   private static final L10N L = new L10N(SqlSetDataSourceTag.class);
43   
44   private Object JavaDoc _dataSource;
45   
46   private String JavaDoc _url;
47   private String JavaDoc _driver;
48   private String JavaDoc _user;
49   private String JavaDoc _password;
50   
51   private String JavaDoc _var;
52   private String JavaDoc _scope;
53
54   /**
55    * Sets the object for the dataSource.
56    */

57   public void setDataSource(Object JavaDoc dataSource)
58   {
59     _dataSource = dataSource;
60   }
61
62   /**
63    * Sets the URL.
64    */

65   public void setUrl(String JavaDoc url)
66   {
67     _url = url;
68   }
69
70   /**
71    * Sets the driver.
72    */

73   public void setDriver(String JavaDoc driver)
74   {
75     _driver = driver;
76   }
77
78   /**
79    * Sets the user.
80    */

81   public void setUser(String JavaDoc user)
82   {
83     _user = user;
84   }
85
86   /**
87    * Sets the password.
88    */

89   public void setPassword(String JavaDoc password)
90   {
91     _password = password;
92   }
93
94   /**
95    * Sets the variable name.
96    */

97   public void setVar(String JavaDoc var)
98   {
99     _var = var;
100   }
101
102   /**
103    * Sets the scope.
104    */

105   public void setScope(String JavaDoc scope)
106   {
107     _scope = scope;
108   }
109
110   public int doStartTag() throws JspException JavaDoc
111   {
112     String JavaDoc var = _var;
113
114     if (var == null)
115       var = Config.SQL_DATA_SOURCE;
116
117     DataSource JavaDoc dataSource = null;
118
119     if (_dataSource != null)
120       dataSource = SqlQueryTag.getDataSource(pageContext, _dataSource);
121     else
122       dataSource = openDataSource(_driver, _url, _user, _password);
123
124     CoreSetTag.setValue(pageContext, var, _scope, dataSource);
125     
126     return SKIP_BODY;
127   }
128
129   private DataSource JavaDoc openDataSource(String JavaDoc driver, String JavaDoc url,
130                     String JavaDoc user, String JavaDoc password)
131     throws JspException JavaDoc
132   {
133     try {
134       return com.caucho.jstl.el.SqlSetDataSourceTag.openDataSource(driver, url, user, password);
135     } catch (Exception JavaDoc e) {
136       throw new JspException JavaDoc(e);
137     }
138   }
139 }
140
Popular Tags