KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > el > core > WhenTag


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
17 package org.apache.taglibs.standard.tag.el.core;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.JspTagException JavaDoc;
21
22 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
23 import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
24 import org.apache.taglibs.standard.tag.common.core.WhenTagSupport;
25
26 /**
27  * <p>Tag handler for &lt;when&gt; in JSTL's expression-evaluating
28  * library.</p>
29  *
30  * @author Shawn Bayern
31  */

32
33 public class WhenTag extends WhenTagSupport {
34
35     //*********************************************************************
36
// Constructor and lifecycle management
37

38     // initialize inherited and local state
39
public WhenTag() {
40         super();
41         init();
42     }
43
44     // Releases any resources we may have (or inherit)
45
public void release() {
46         super.release();
47         init();
48     }
49
50
51     //*********************************************************************
52
// Supplied conditional logic
53

54     protected boolean condition() throws JspTagException JavaDoc {
55         try {
56             Object JavaDoc r = ExpressionEvaluatorManager.evaluate(
57                 "test", test, Boolean JavaDoc.class, this, pageContext);
58             if (r == null)
59             throw new NullAttributeException("when", "test");
60             else
61                 return (((Boolean JavaDoc) r).booleanValue());
62     } catch (JspException JavaDoc ex) {
63         throw new JspTagException JavaDoc(ex.toString(), ex);
64     }
65     }
66
67
68     //*********************************************************************
69
// Private state
70

71     private String JavaDoc test; // the value of the 'test' attribute
72

73
74     //*********************************************************************
75
// Accessors
76

77     // receives the tag's 'test' attribute
78
public void setTest(String JavaDoc test) {
79         this.test = test;
80     }
81
82
83     //*********************************************************************
84
// Private utility methods
85

86     // resets internal state
87
private void init() {
88         test = null;
89     }
90 }
91
Popular Tags