KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > facelets > tag > jsf > core > AttributeHandler


1 /**
2  * Licensed under the Common Development and Distribution License,
3  * you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.sun.com/cddl/
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11  * implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */

14
15 package com.sun.facelets.tag.jsf.core;
16
17 import java.io.IOException JavaDoc;
18
19 import javax.el.ELException;
20 import javax.faces.FacesException;
21 import javax.faces.component.UIComponent;
22
23 import com.sun.facelets.FaceletContext;
24 import com.sun.facelets.FaceletException;
25 import com.sun.facelets.el.ELAdaptor;
26 import com.sun.facelets.tag.TagAttribute;
27 import com.sun.facelets.tag.TagConfig;
28 import com.sun.facelets.tag.TagException;
29 import com.sun.facelets.tag.TagHandler;
30
31 /**
32  * Sets the specified name and attribute on the parent UIComponent. If the
33  * "value" specified is not a literal, it will instead set the ValueExpression
34  * on the UIComponent.
35  * <p />
36  * See <a target="_new"
37  * HREF="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/tlddocs/f/attribute.html">tag
38  * documentation</a>.
39  *
40  * @see javax.faces.component.UIComponent#getAttributes()
41  * @see javax.faces.component.UIComponent#setValueExpression(java.lang.String,
42  * javax.el.ValueExpression)
43  * @author Jacob Hookom
44  * @version $Id: AttributeHandler.java,v 1.2 2005/08/24 04:38:49 jhook Exp $
45  */

46 public final class AttributeHandler extends TagHandler {
47
48     private final TagAttribute name;
49
50     private final TagAttribute value;
51
52     /**
53      * @param config
54      */

55     public AttributeHandler(TagConfig config) {
56         super(config);
57         this.name = this.getRequiredAttribute("name");
58         this.value = this.getRequiredAttribute("value");
59     }
60
61     /*
62      * (non-Javadoc)
63      *
64      * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
65      * javax.faces.component.UIComponent)
66      */

67     public void apply(FaceletContext ctx, UIComponent parent)
68             throws IOException JavaDoc, FacesException, FaceletException, ELException {
69         if (parent == null) {
70             throw new TagException(this.tag, "Parent UIComponent was null");
71         }
72
73         // only process if the parent is new to the tree
74
if (parent.getParent() == null) {
75             String JavaDoc n = this.name.getValue(ctx);
76             if (!parent.getAttributes().containsKey(n)) {
77                 if (this.value.isLiteral()) {
78                     parent.getAttributes().put(n, this.value.getValue());
79                 } else {
80                     ELAdaptor.setExpression(parent, n, this.value
81                             .getValueExpression(ctx, Object JavaDoc.class));
82                 }
83             }
84         }
85     }
86 }
87
Popular Tags