KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.tools.jsfext.event.AfterLoopEvent;
26 import com.sun.enterprise.tools.jsfext.event.BeforeLoopEvent;
27 import com.sun.enterprise.tools.jsfext.el.PermissionChecker;
28
29 import java.io.IOException JavaDoc;
30
31 import javax.faces.context.FacesContext;
32 import javax.faces.component.UIComponent;
33
34
35 /**
36  * <p> This class defines a LayoutWhile {@link LayoutElement}. The
37  * LayoutWhile provides the functionality necessary to iteratively
38  * display a portion of the layout tree. The condition is a boolean
39  * equation and may use "$...{...}" type expressions to substitute
40  * values.</p>
41  *
42  * @see com.sun.enterprise.tools.jsfext.el.VariableResolver
43  * @see com.sun.enterprise.tools.jsfext.el.PermissionChecker
44  *
45  * @author Ken Paulsen (ken.paulsen@sun.com)
46  */

47 public class LayoutWhile extends LayoutIf implements LayoutElement {
48
49     /**
50      * Constructor
51      */

52     public LayoutWhile(LayoutElement parent, String JavaDoc condition) {
53     super(parent, condition);
54     }
55
56
57     /**
58      * <p> This method always returns true. The condition is checked in
59      * {@link #shouldContinue(UIComponent)} instead of here because
60      * the {@link #encode(FacesContext, UIComponent)} method
61      * evaluates the condition and calls the super. Performing the check
62      * here would cause the condition to be evaluated twice.</p>
63      *
64      * @param context The FacesContext
65      * @param component The UIComponent
66      *
67      * @return true
68      */

69     protected boolean encodeThis(FacesContext context, UIComponent component) {
70     return true;
71     }
72
73     /**
74      * <p> This method returns true if the condition of this LayoutWhile is
75      * met, false otherwise. This provides the functionality for
76      * iteratively displaying a portion of the layout tree.</p>
77      *
78      * @param component The UIComponent
79      *
80      * @return true if children are to be rendered, false otherwise.
81      */

82     protected boolean shouldContinue(UIComponent component) {
83     PermissionChecker checker =
84         new PermissionChecker(this, component, getCondition());
85 // return checker.evaluate();
86
return checker.hasPermission();
87     }
88
89     /**
90      * <p> This implementation overrides the parent <code>encode</code>
91      * method. It does this to cause the encode process to loop while
92      * {@link #shouldContinue(UIComponent)} returns
93      * true. Currently there is no infinite loop checking, so be
94      * careful.</p>
95      *
96      * @param context The FacesContext
97      * @param component The UIComponent
98      */

99     public void encode(FacesContext context, UIComponent component) throws IOException JavaDoc {
100     Object JavaDoc result = dispatchHandlers(context, BEFORE_LOOP,
101         new BeforeLoopEvent((UIComponent) component));
102     while (shouldContinue(component)) {
103         super.encode(context, component);
104     }
105     result = dispatchHandlers(context, AFTER_LOOP,
106         new AfterLoopEvent((UIComponent) component));
107     }
108
109     /**
110      * <p> This is the event "type" for
111      * {@link com.sun.enterprise.tools.jsfext.event.handlers.Handler}
112      * elements to be invoked after this LayoutWhile is processed
113      * (outside loop).</p>
114      */

115      public static final String JavaDoc AFTER_LOOP = "afterLoop";
116
117     /**
118      * <p> This is the event "type" for
119      * {@link com.sun.enterprise.tools.jsfext.event.handlers.Handler}
120      * elements to be invoked before this LayoutWhile is processed
121      * (outside loop).</p>
122      */

123      public static final String JavaDoc BEFORE_LOOP = "beforeLoop";
124 }
125
Popular Tags