KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > jsfext > layout > descriptor > LayoutFacet


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.jsfext.layout.descriptor;
24
25 import java.io.IOException JavaDoc;
26
27 import javax.faces.context.FacesContext;
28 import javax.faces.component.UIComponent;
29
30
31 /**
32  * <p> This class defines the descriptor for LayoutFacet. A LayoutFacet
33  * descriptor provides information needed to attempt to obtain a Facet
34  * from the UIComponent. If the Facet doesn't exist, it also has the
35  * opportunity to provide a "default" in place of the facet.</p>
36  *
37  * @author Ken Paulsen (ken.paulsen@sun.com)
38  */

39 public class LayoutFacet extends LayoutElementBase implements LayoutElement {
40
41     /**
42      * Constructor
43      */

44     public LayoutFacet(LayoutElement parent, String JavaDoc id) {
45     super(parent, id);
46     }
47
48     /**
49      * <p> Returns whether this LayoutFacet should be rendered. When this
50      * component is used to specify an actual facet (i.e. specifies a
51      * <code>UIComponent</code>), it should not be rendred. When it
52      * defines a place holder for a facet, then it should be rendered.</p>
53      *
54      * <p> This property is normally set when the LayoutElement tree is
55      * created (i.e. <code>XMLLayoutDefinitionReader</code>). One way to
56      * know what to do is to see if the is <code>LayoutFacet</code> is
57      * used inside a <code>LayoutComponent</code> or not. If it is, it
58      * can be assumed that it represents an actual facet, not a place
59      * holder.</p>
60      *
61      * @return true if {@link #encodeThis(FacesContext, UIComponent)} should
62      * execute
63      */

64     public boolean isRendered() {
65     return _rendered;
66     }
67
68     /**
69      *
70      */

71     public void setRendered(boolean render) {
72     _rendered = render;
73     }
74
75     /**
76      * <p>This method looks for the facet on the component. If found, it
77      * renders it and returns false (so children will not be rendered). If
78      * not found, it returns true so that children will be rendered.
79      * Children of a LayoutFacet represent the default value for the
80      * Facet.</p>
81      *
82      * @param context The FacesContext
83      * @param parent The parent UIComponent
84      *
85      * @return true if children are to be rendered, false otherwise.
86      */

87     protected boolean encodeThis(FacesContext context, UIComponent component) throws IOException JavaDoc {
88     // Make sure we are supposed to render facets
89
if (!isRendered()) {
90         return false;
91     }
92
93     // Look for Facet
94
component = (UIComponent) component.getFacets().
95         get(getId(context, component));
96     if (component != null) {
97         // Found Facet, Display UIComponent
98
encodeChild(context, component);
99
100         // Return false so the default won't be rendered
101
return false;
102     }
103
104     // Return true so that the default will be rendered
105
return true;
106     }
107
108     private boolean _rendered = true;
109 }
110
Popular Tags