KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > faces > taglib > AbstractFacesTag


1 /*
2  * Copyright 2002,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.struts.faces.taglib;
18
19
20 import javax.faces.component.UIComponent;
21 import javax.faces.el.ValueBinding;
22 import javax.faces.webapp.UIComponentTag;
23
24
25 /**
26  * <p>Abstract base class for custom component tags for the
27  * <em>Struts-Faces Integration Library</em>.</p>
28  *
29  *
30  * @version $Rev: 54934 $ $Date: 2004-10-16 18:07:50 +0100 (Sat, 16 Oct 2004) $
31  */

32
33 public abstract class AbstractFacesTag extends UIComponentTag {
34
35
36     // ---------------------------------------------------------- Tag Attributes
37

38
39     /**
40      * <p>The servlet context attribute under which our
41      * <code>MessageResources</code> bundle is stored.</p>
42      */

43     protected String JavaDoc bundle = null;
44
45     public void setBundle(String JavaDoc bundle) {
46         this.bundle = bundle;
47     }
48
49
50     /**
51      * <p>The CSS style(s) used to render this component.</p>
52      */

53     protected String JavaDoc style = null;
54
55     public void setStyle(String JavaDoc style) {
56         this.style = style;
57     }
58
59
60     /**
61      * <p>The CSS style class(es) used to render this component.</p>
62      */

63     protected String JavaDoc styleClass = null;
64
65     public void setStyleClass(String JavaDoc styleClass) {
66         this.styleClass = styleClass;
67     }
68
69
70     /**
71      * <p>The literal value to be rendered.</p>
72      */

73     protected String JavaDoc value = null;
74
75     public void setValue(String JavaDoc value) {
76         this.value = value;
77     }
78
79
80     // ---------------------------------------------------------- Public Methods
81

82
83     /**
84      * <p>Return the component type of the component to be created for
85      * this tag.</p>
86      */

87     public abstract String JavaDoc getComponentType();
88
89
90     /**
91      * <p>Return the <code>rendererType</code> to be used for rendering
92      * our component.</p>
93      */

94     public abstract String JavaDoc getRendererType();
95
96
97     /**
98      * <p>Release any variables allocated during use of this tag instance.</p>
99      */

100     public void release() {
101
102         super.release();
103         this.bundle = null;
104         this.style = null;
105         this.styleClass = null;
106         this.value = null;
107
108     }
109
110
111     // -------------------------------------------------- UIComponentTag Methods
112

113
114     /**
115      * <p>Override attributes set on this tag instance.</p>
116      *
117      * @param component Component whose attributes should be overridden
118      */

119     protected void setProperties(UIComponent component) {
120
121         super.setProperties(component);
122         setStringAttribute(component, "bundle", bundle);
123         setStringAttribute(component, "style", style);
124         setStringAttribute(component, "styleClass", styleClass);
125         setStringAttribute(component, "value", value);
126
127     }
128
129
130     // ------------------------------------------------------- Protected Methods
131

132
133     /**
134      * <p>If the specified attribute value is not <code>null</code>
135      * use it to either store a value binding expression for the
136      * specified attribute name, or store it as the literal value
137      * of the attribute.</p>
138      *
139      * @param component <code>UIComponent</code> whose attribute
140      * is to be set
141      * @param name Attribute name
142      * @param value Attribute value (or <code>null</code>)
143      *
144      * @exception NumberFormatException if the value does not
145      * contain a parsable integer
146      * @exception ReferenceSyntaxException if the expression has
147      * invalid syntax
148      */

149     protected void setBooleanAttribute(UIComponent component,
150                                        String JavaDoc name, String JavaDoc value) {
151
152         if (value == null) {
153             return;
154         }
155         if (isValueReference(value)) {
156             ValueBinding vb =
157                 getFacesContext().getApplication().createValueBinding(value);
158             component.setValueBinding(name, vb);
159         } else {
160             component.getAttributes().put(name, Boolean.valueOf(value));
161         }
162
163     }
164
165
166     /**
167      * <p>If the specified attribute value is not <code>null</code>
168      * use it to either store a value binding expression for the
169      * specified attribute name, or store it as the literal value
170      * of the attribute.</p>
171      *
172      * @param component <code>UIComponent</code> whose attribute
173      * is to be set
174      * @param name Attribute name
175      * @param value Attribute value (or <code>null</code>)
176      *
177      * @exception NumberFormatException if the value does not
178      * contain a parsable integer
179      * @exception ReferenceSyntaxException if the expression has
180      * invalid syntax
181      */

182     protected void setIntegerAttribute(UIComponent component,
183                                        String JavaDoc name, String JavaDoc value) {
184
185         if (value == null) {
186             return;
187         }
188         if (isValueReference(value)) {
189             ValueBinding vb =
190                 getFacesContext().getApplication().createValueBinding(value);
191             component.setValueBinding(name, vb);
192         } else {
193             component.getAttributes().put(name, Integer.valueOf(value));
194         }
195
196     }
197
198
199     /**
200      * <p>If the specified attribute value is not <code>null</code>
201      * use it to either store a value binding expression for the
202      * specified attribute name, or store it as the literal value
203      * of the attribute.</p>
204      *
205      * @param component <code>UIComponent</code> whose attribute
206      * is to be set
207      * @param name Attribute name
208      * @param value Attribute value (or <code>null</code>)
209      *
210      * @exception ReferenceSyntaxException if the expression has
211      * invalid syntax
212      */

213     protected void setStringAttribute(UIComponent component,
214                                       String JavaDoc name, String JavaDoc value) {
215
216         if (value == null) {
217             return;
218         }
219         if (isValueReference(value)) {
220             ValueBinding vb =
221                 getFacesContext().getApplication().createValueBinding(value);
222             component.setValueBinding(name, vb);
223         } else {
224             component.getAttributes().put(name, value);
225         }
226
227     }
228 }
229
Popular Tags