KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > dbtags > preparedstatement > BaseSetterBodyTag


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

17 package org.apache.taglibs.dbtags.preparedstatement;
18
19 import java.sql.PreparedStatement JavaDoc;
20
21 import javax.servlet.jsp.JspTagException JavaDoc;
22 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
23
24 /**
25  * Base class for all the setter body tags in the
26  * preparedstatement package.
27  *
28  * @author Morgan Delagrange
29  */

30 public class BaseSetterBodyTag extends BodyTagSupport JavaDoc {
31   
32   protected int _position = 1;
33   protected String JavaDoc _attributeName = null;
34   
35   /**
36    * Sets the column number of the prepared statement.
37    *
38    * @param position column index
39    */

40   public void setPosition(int position) {
41     _position = position;
42   }
43   
44   /**
45    * Name of the page attribute that will be assigned
46    * to the statement.
47    *
48    * @param attributeName
49    * attribute name
50    */

51   public void setName(String JavaDoc attributeName) {
52     _attributeName = attributeName;
53   }
54       
55   /**
56    * Gets the page attribute for the tag
57    *
58    * @param name name of the attribute
59    * @return the page attribute
60    * @exception JspTagException
61    * thrown when the page attribute does not exist
62    */

63   protected Object JavaDoc getAttribute(String JavaDoc name)
64       throws JspTagException JavaDoc {
65     Object JavaDoc object = pageContext.getAttribute(name);
66     
67     if (object == null) {
68       throw new JspTagException JavaDoc("attribute " + name + " does not exist");
69     }
70       
71     return object;
72   }
73
74   /**
75    * get the PreparedStatement from the enclosing tag
76    *
77    * @return the PreparedStatement
78    * @exception JspTagException
79    * thrown if no PreparedStatement exists
80    */

81   protected PreparedStatement JavaDoc getPreparedStatement()
82       throws JspTagException JavaDoc {
83     try {
84       PreparedStatementImplTag stmtTag =
85       (PreparedStatementImplTag) findAncestorWithClass(this, Class.forName("org.apache.taglibs.dbtags.preparedstatement.PreparedStatementImplTag"));
86       return stmtTag.getPreparedStatement();
87     } catch (ClassNotFoundException JavaDoc e) {
88       throw new JspTagException JavaDoc(e.toString());
89     }
90   }
91
92   public void release() {
93     _position = 1;
94     _attributeName = null;
95   }
96 }
97
Popular Tags