KickJava   Java API By Example, From Geeks To Geeks.

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

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

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

38
39     //*********************************************************************
40
// Constructor
41

42     /**
43      * Constructs a new ParamTag. As with TagSupport, subclasses
44      * should not provide other constructors and are expected to call
45      * the superclass constructor
46      */

47     public ParamTag() {
48         super();
49         init();
50     }
51
52
53     //*********************************************************************
54
// Tag logic
55

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

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

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

105
106     name = (String JavaDoc) ExpressionUtil.evalNotNull(
107         "import", "name", name_, String JavaDoc.class, this, pageContext);
108     value = (String JavaDoc) ExpressionUtil.evalNotNull(
109         "import", "value", value_, String JavaDoc.class, this, pageContext);
110     }
111 }
112
Popular Tags