KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > el > xml > ParamTag


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.xml;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20
21 import org.apache.taglibs.standard.tag.common.xml.ParamSupport;
22 import org.apache.taglibs.standard.tag.el.core.ExpressionUtil;
23
24 /**
25  * <p>A handler for &lt;param&gt; that accepts attributes as Strings
26  * and evaluates them as expressions at runtime.</p>
27  *
28  * @author Shawn Bayern
29  */

30
31 public class ParamTag extends ParamSupport {
32
33     //*********************************************************************
34
// 'Private' state (implementation details)
35

36     private String JavaDoc name_; // stores EL-based property
37
private String JavaDoc value_; // stores EL-based property
38

39
40     //*********************************************************************
41
// Constructor
42

43     public ParamTag() {
44         super();
45         init();
46     }
47
48
49     //*********************************************************************
50
// Tag logic
51

52     // evaluates expression and chains to parent
53
public int doStartTag() throws JspException JavaDoc {
54
55         // evaluate any expressions we were passed, once per invocation
56
evaluateExpressions();
57
58     // chain to the parent implementation
59
return super.doStartTag();
60     }
61
62
63     // Releases any resources we may have (or inherit)
64
public void release() {
65         super.release();
66         init();
67     }
68
69
70     //*********************************************************************
71
// Accessor methods
72

73     // for EL-based attribute
74
public void setName(String JavaDoc name_) {
75         this.name_ = name_;
76     }
77
78     public void setValue(String JavaDoc value_) {
79         this.value_ = value_;
80     }
81
82
83     //*********************************************************************
84
// Private (utility) methods
85

86     // (re)initializes state (during release() or construction)
87
private void init() {
88         // null implies "no expression"
89
name_ = value_ = null;
90     }
91
92     /* Evaluates expressions as necessary */
93     private void evaluateExpressions() throws JspException JavaDoc {
94         /*
95          * Note: we don't check for type mismatches here; we assume
96          * the expression evaluator will return the expected type
97          * (by virtue of knowledge we give it about what that type is).
98          * A ClassCastException here is truly unexpected, so we let it
99          * propagate up.
100          */

101
102     name = (String JavaDoc) ExpressionUtil.evalNotNull(
103         "param", "name", name_, String JavaDoc.class, this, pageContext);
104     value = ExpressionUtil.evalNotNull(
105         "param", "value", value_, Object JavaDoc.class, this, pageContext);
106     }
107 }
108
Popular Tags