View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package javax.faces.render;
20  
21  import java.io.IOException;
22  import java.util.List;
23  
24  import javax.faces.component.UIComponent;
25  import javax.faces.context.FacesContext;
26  import javax.faces.convert.ConverterException;
27  
28  /**
29   * see Javadoc of <a href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/api/index.html">JSF Specification</a>
30   *
31   * @author Manfred Geiler (latest modification by $Author: skitching $)
32   * @version $Revision: 676278 $ $Date: 2008-07-13 03:35:04 -0500 (Sun, 13 Jul 2008) $
33   */
34  public abstract class Renderer
35  {
36      public void decode(FacesContext context,
37                         UIComponent component)
38      {
39          if (context == null) throw new NullPointerException("context");
40          if (component == null) throw new NullPointerException("component");
41      }
42  
43      public void encodeBegin(FacesContext context,
44                              UIComponent component)
45              throws IOException
46      {
47          if (context == null) throw new NullPointerException("context");
48          if (component == null) throw new NullPointerException("component");
49      }
50  
51      /**Render all children if there are any.
52       * 
53       * Note: this will only be called if getRendersChildren()
54       * returns true. A component which has a renderer with
55       * getRendersChildren() set to true will typically contain
56       * the rendering logic for its children in this method.
57       * 
58       * @param context
59       * @param component
60       * @throws IOException
61       */    
62      public void encodeChildren(FacesContext context,
63                                 UIComponent component)
64              throws IOException
65      {
66          if (context == null) throw new NullPointerException("context");
67          if (component == null) throw new NullPointerException("component");
68          
69          List children = component.getChildren();
70          for (int i=0; i<children.size(); i++) 
71          {
72              UIComponent child = (UIComponent) children.get(i);
73              
74              if (!child.isRendered())
75              {
76                  continue;
77              }
78  
79              child.encodeBegin(context);
80              if (child.getRendersChildren())
81              {
82                  child.encodeChildren(context);
83              }
84              else {
85                encodeChildren(context, child);
86              }
87              child.encodeEnd(context);
88          }
89      }
90  
91      
92      public void encodeEnd(FacesContext context,
93                            UIComponent component)
94              throws IOException
95      {
96          if (context == null) throw new NullPointerException("context");
97          if (component == null) throw new NullPointerException("component");
98      }
99  
100     public String convertClientId(FacesContext context,
101                                   String clientId)
102     {
103         if (context == null) throw new NullPointerException("context");
104         if (clientId == null) throw new NullPointerException("clientId");
105         return clientId;
106     }
107 
108     /**Switch for deciding who renders the children.
109      * 
110      * @return <b>true</b> - if the component takes care of rendering its
111      * children. In this case, encodeChildren() ought to be called
112      * by the rendering controller (e.g., the rendering controller
113      * could be the component's JSP-Tag). 
114      * In the method encodeChildren(), the component
115      * should therefore provide all children encode logic.
116      * <br/>
117      * <b>false</b> - if the component does not take care of rendering its
118      * children. In this case, encodeChildren() should not be called
119      * by the rendering controller. Instead, the children-list should
120      * be retrieved and the children should directly be rendered by
121      * the rendering controller one by one.
122      */    
123     public boolean getRendersChildren()
124     {
125         return false;
126     }
127 
128     public Object getConvertedValue(FacesContext context,
129                                     UIComponent component,
130                                     Object submittedValue)
131             throws ConverterException
132     {
133         if (context == null) throw new NullPointerException("context");
134         if (component == null) throw new NullPointerException("component");
135         return submittedValue;
136     }
137 
138 }