KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > dbtags > connection > DriverTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.taglibs.dbtags.connection;
17
18 import javax.servlet.jsp.JspTagException JavaDoc;
19 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
20
21 /**
22  * <p>JSP tag driver, sets the java.sql.Driver class name for the
23  * enclosing connection tag. The driver name is read from the indicated
24  * initParameter, if the parameter is set, or from the body of the tag
25  * if it is not.</p>
26  *
27  * <p>JSP Tag Lib Descriptor
28  * <pre>
29  * &lt;name>driver&lt;/name>
30  * &lt;tagclass>org.apache.taglibs.dbtags.connection.DriverTag&lt;/tagclass>
31  * &lt;bodycontent>JSP&lt;/bodycontent>
32  * &lt;info>Sets the java.sql.Driver class name for the enclosing
33  * connection tag according to the initParameter, if specified, or the
34  * body of the tag. The tag body will be trimmed.&lt;/info>
35  * &lt;attribute>
36  * &lt;name>initParameter&lt;/name>
37  * &lt;required>false&lt;/required>
38  * &lt;rtexprvalue>false&lt;/rtexprvalue>
39  * &lt;/attribute>
40  * </pre>
41  *
42  * @author Morgan Delagrange
43  * @see ConnectionTag
44  */

45 public class DriverTag extends BodyTagSupport JavaDoc {
46   
47   private String JavaDoc _driverClass = null;
48
49   /**
50    * The name of the init parameter containing the driver name.
51    *
52    * @param paramName driver class name
53    */

54   public void setInitParameter(String JavaDoc paramName) {
55     _driverClass = pageContext.getServletContext().getInitParameter(paramName);
56   }
57
58   public int doEndTag() throws JspTagException JavaDoc{
59     try {
60       ConnectionTag connTag =
61         (ConnectionTag) findAncestorWithClass(this, Class.forName("org.apache.taglibs.dbtags.connection.ConnectionTag"));
62       if (_driverClass == null) {
63         _driverClass = getBodyContent().getString().trim();
64       }
65
66       connTag.setDriver(_driverClass);
67     }
68      catch (ClassNotFoundException JavaDoc e) {
69       throw new JspTagException JavaDoc(e.toString());
70     }
71     return EVAL_PAGE;
72   }
73
74   public void release() {
75     _driverClass = null;
76   }
77   
78 }
79
Popular Tags