KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > strutsel > taglib > bean > ELSizeTag


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

18
19 package org.apache.strutsel.taglib.bean;
20
21 import org.apache.struts.taglib.bean.SizeTag;
22 import javax.servlet.jsp.JspException JavaDoc;
23 import org.apache.strutsel.taglib.utils.EvalHelper;
24
25 /**
26  * Define a scripting variable that will contain the number of elements
27  * found in a specified array, Collection, or Map.
28  *<p>
29  * This class is a subclass of the class
30  * <code>org.apache.struts.taglib.bean.SizeTag</code> which provides most of
31  * the described functionality. This subclass allows all attribute values to
32  * be specified as expressions utilizing the JavaServer Pages Standard Library
33  * expression language.
34  *
35  * @version $Rev: 54933 $
36  */

37 public class ELSizeTag extends SizeTag {
38
39     /**
40      * Instance variable mapped to "collection" tag attribute.
41      * (Mapping set in associated BeanInfo class.)
42      */

43     private String JavaDoc collectionExpr;
44     /**
45      * Instance variable mapped to "id" tag attribute.
46      * (Mapping set in associated BeanInfo class.)
47      */

48     private String JavaDoc idExpr;
49     /**
50      * Instance variable mapped to "name" tag attribute.
51      * (Mapping set in associated BeanInfo class.)
52      */

53     private String JavaDoc nameExpr;
54     /**
55      * Instance variable mapped to "property" tag attribute.
56      * (Mapping set in associated BeanInfo class.)
57      */

58     private String JavaDoc propertyExpr;
59     /**
60      * Instance variable mapped to "scope" tag attribute.
61      * (Mapping set in associated BeanInfo class.)
62      */

63     private String JavaDoc scopeExpr;
64
65     /**
66      * Getter method for "collection" tag attribute.
67      * (Mapping set in associated BeanInfo class.)
68      */

69     public String JavaDoc getCollectionExpr() { return (collectionExpr); }
70     /**
71      * Getter method for "id" tag attribute.
72      * (Mapping set in associated BeanInfo class.)
73      */

74     public String JavaDoc getIdExpr() { return (idExpr); }
75     /**
76      * Getter method for "name" tag attribute.
77      * (Mapping set in associated BeanInfo class.)
78      */

79     public String JavaDoc getNameExpr() { return (nameExpr); }
80     /**
81      * Getter method for "property" tag attribute.
82      * (Mapping set in associated BeanInfo class.)
83      */

84     public String JavaDoc getPropertyExpr() { return (propertyExpr); }
85     /**
86      * Getter method for "scope" tag attribute.
87      * (Mapping set in associated BeanInfo class.)
88      */

89     public String JavaDoc getScopeExpr() { return (scopeExpr); }
90
91     /**
92      * Setter method for "collection" tag attribute.
93      * (Mapping set in associated BeanInfo class.)
94      */

95     public void setCollectionExpr(String JavaDoc collectionExpr) { this.collectionExpr = collectionExpr; }
96     /**
97      * Setter method for "id" tag attribute.
98      * (Mapping set in associated BeanInfo class.)
99      */

100     public void setIdExpr(String JavaDoc idExpr) { this.idExpr = idExpr; }
101     /**
102      * Setter method for "name" tag attribute.
103      * (Mapping set in associated BeanInfo class.)
104      */

105     public void setNameExpr(String JavaDoc nameExpr) { this.nameExpr = nameExpr; }
106     /**
107      * Setter method for "property" tag attribute.
108      * (Mapping set in associated BeanInfo class.)
109      */

110     public void setPropertyExpr(String JavaDoc propertyExpr) { this.propertyExpr = propertyExpr; }
111     /**
112      * Setter method for "scope" tag attribute.
113      * (Mapping set in associated BeanInfo class.)
114      */

115     public void setScopeExpr(String JavaDoc scopeExpr) { this.scopeExpr = scopeExpr; }
116
117     /**
118      * Releases state of custom tag so this instance can be reused.
119      */

120     public void release()
121     {
122         super.release();
123         setCollectionExpr(null);
124         setIdExpr(null);
125         setNameExpr(null);
126         setPropertyExpr(null);
127         setScopeExpr(null);
128     }
129     
130     /**
131      * Process the start tag.
132      *
133      * @exception JspException if a JSP exception has occurred
134      */

135     public int doStartTag() throws JspException JavaDoc {
136         evaluateExpressions();
137         return (super.doStartTag());
138     }
139
140     /**
141      * Processes all attribute values which use the JSTL expression evaluation
142      * engine to determine their values.
143      *
144      * @exception JspException if a JSP exception has occurred
145      */

146     private void evaluateExpressions() throws JspException JavaDoc {
147         String JavaDoc string = null;
148         Object JavaDoc object = null;
149
150         if ((object = EvalHelper.eval("collection", getCollectionExpr(),
151                                       this, pageContext)) != null)
152             setCollection(object);
153
154         if ((string = EvalHelper.evalString("id", getIdExpr(),
155                                             this, pageContext)) != null)
156             setId(string);
157
158         if ((string = EvalHelper.evalString("name", getNameExpr(),
159                                             this, pageContext)) != null)
160             setName(string);
161
162         if ((string = EvalHelper.evalString("property", getPropertyExpr(),
163                                             this, pageContext)) != null)
164             setProperty(string);
165
166         if ((string = EvalHelper.evalString("scope", getScopeExpr(),
167                                             this, pageContext)) != null)
168             setScope(string);
169     }
170 }
171
Popular Tags