KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > dbtags > resultset > WasNullTag


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.resultset;
17
18 import java.sql.ResultSet JavaDoc;
19 import java.sql.SQLException JavaDoc;
20
21 import javax.servlet.jsp.JspTagException JavaDoc;
22 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
23
24 /**
25  * <p>Executes its body if the last getColumn tag received a null value
26  * from the database. You must be inside a resultset tag and there must
27  * be a previous getColumn tag, or an error will be generated.</p>
28  *
29  * <p>The subclass WasNotNull sets the "value" property to false,
30  * and therefore executes its tag body is the last column was
31  * <i>not</i> null.</p>
32  *
33  * <p>JSP Tag Lib Descriptor
34  * <pre>
35  * &lt;name>wasNull&lt;/name>
36  * &lt;tagclass>org.apache.taglibs.dbtags.resultset.WasNullTag&lt;/tagclass>
37  * &lt;bodycontent>JSP&lt;/bodycontent>
38  * &lt;info>Executes its body if the last getColumn tag received a null value
39  * from the database. You must be inside a resultset tag and there must
40  * be a previous getColumn tag, or an error will be generated.&lt;/info>
41  * </pre>
42  *
43  * @author Morgan Delagrange
44  * @see WasNotNullTag
45  */

46 public class WasNullTag extends TagSupport JavaDoc {
47
48   private boolean _value = true;
49
50   /**
51    * Sets the necessary boolean value in order to
52    * execute the tag body.
53    *
54    * @param value
55    */

56   public void setValue(boolean value) {
57     _value = value;
58   }
59
60   /**
61    * Get the ResultSet object from the enclosing resultset tag
62    *
63    * @return ResultSet of the resultset tag
64    * @exception ClassNotFoundException
65    */

66   private ResultSet JavaDoc getResultSet() throws ClassNotFoundException JavaDoc {
67     ResultSetTag rsetTag =
68       (ResultSetTag) findAncestorWithClass(this, Class.forName("org.apache.taglibs.dbtags.resultset.ResultSetTag"));
69     return rsetTag.getResultSet();
70   }
71
72   public int doStartTag() throws JspTagException JavaDoc {
73     try {
74       ResultSet JavaDoc rset = getResultSet();
75       boolean wasNull = rset.wasNull();
76
77       // evaluate the body only if wasNull matches the desired
78
// value (true or false)
79
if (wasNull == _value) {
80         return EVAL_BODY_INCLUDE;
81       } else {
82         return SKIP_BODY;
83       }
84     } catch (ClassNotFoundException JavaDoc e) {
85       throw new JspTagException JavaDoc(e.toString());
86     } catch (SQLException JavaDoc e) {
87       throw new JspTagException JavaDoc(e.toString());
88     }
89   }
90
91   public void release() {
92     _value = true;
93   }
94 }
95
96
Popular Tags