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 org.apache.myfaces.test.utils;
20  
21  import java.io.IOException;
22  
23  import javax.faces.FacesException;
24  import javax.faces.component.UIComponent;
25  import javax.faces.context.FacesContext;
26  import javax.faces.render.RenderKit;
27  import javax.faces.render.Renderer;
28  
29  import org.apache.commons.logging.Log;
30  import org.apache.commons.logging.LogFactory;
31  
32  public final class TestUtils
33  {
34      /** Default Logger */
35      private static final Log log = LogFactory.getLog(TestUtils.class);
36  
37      /** utility class, do not instantiate */
38      private TestUtils()
39      {
40          // utility class, disable instantiation
41      }
42  
43      /**
44       * Add all of Tomahawk's renderers.  Currently this is not tied to 
45       * faces-config.xml, so all change to the file MUST also be made here.
46       * 
47       * @param facesContext
48       * @todo Do not add renderer if renderer is already added.
49       */
50      public static void addDefaultRenderers(FacesContext facesContext)
51      {
52          // Standard HTML Renderers
53          addRenderer(facesContext, "javax.faces.Command", "javax.faces.Button",
54                  "org.apache.myfaces.renderkit.html.HtmlButtonRenderer");
55  
56          addRenderer(facesContext, "javax.faces.SelectBoolean",
57                  "javax.faces.Checkbox",
58                  "org.apache.myfaces.renderkit.html.HtmlCheckboxRenderer");
59  
60          addRenderer(facesContext, "javax.faces.SelectMany",
61                  "javax.faces.Checkbox",
62                  "org.apache.myfaces.renderkit.html.HtmlCheckboxRenderer");
63  
64          addRenderer(facesContext, "javax.faces.Form", "javax.faces.Form",
65                  "org.apache.myfaces.renderkit.html.ext.HtmlFormRenderer");
66  
67          addRenderer(facesContext, "javax.faces.Panel", "javax.faces.Grid",
68                  "org.apache.myfaces.renderkit.html.HtmlGridRenderer");
69  
70          addRenderer(facesContext, "javax.faces.Panel", "javax.faces.Group",
71                  "org.apache.myfaces.renderkit.html.HtmlGroupRenderer");
72  
73          addRenderer(facesContext, "javax.faces.Input", "javax.faces.Hidden",
74                  "org.apache.myfaces.renderkit.html.HtmlHiddenRenderer");
75  
76          addRenderer(facesContext, "javax.faces.Input", "org.apache.myfaces.Hidden",
77                  "org.apache.myfaces.renderkit.html.ext.HtmlHiddenRenderer");
78          
79          addRenderer(facesContext, "javax.faces.Graphic", "javax.faces.Image",
80                  "org.apache.myfaces.renderkit.html.HtmlImageRenderer");
81  
82          addRenderer(facesContext, "javax.faces.Output", "javax.faces.Label",
83                  "org.apache.myfaces.renderkit.html.HtmlLabelRenderer");
84  
85          addRenderer(facesContext, "javax.faces.Output", "javax.faces.Link",
86                  "org.apache.myfaces.renderkit.html.HtmlLinkRenderer");
87  
88          addRenderer(facesContext, "javax.faces.Command", "javax.faces.Link",
89                  "org.apache.myfaces.renderkit.html.HtmlLinkRenderer");
90  
91          addRenderer(facesContext, "javax.faces.SelectOne",
92                  "javax.faces.Listbox",
93                  "org.apache.myfaces.renderkit.html.HtmlListboxRenderer");
94  
95          addRenderer(facesContext, "javax.faces.SelectMany",
96                  "javax.faces.Listbox",
97                  "org.apache.myfaces.renderkit.html.HtmlListboxRenderer");
98  
99          addRenderer(facesContext, "javax.faces.SelectOne", "javax.faces.Menu",
100                 "org.apache.myfaces.renderkit.html.HtmlMenuRenderer");
101 
102         addRenderer(facesContext, "javax.faces.SelectMany", "javax.faces.Menu",
103                 "org.apache.myfaces.renderkit.html.HtmlMenuRenderer");
104 
105         addRenderer(facesContext, "javax.faces.Message", "javax.faces.Message",
106                 "org.apache.myfaces.renderkit.html.HtmlMessageRenderer");
107 
108         addRenderer(facesContext, "javax.faces.Output", "javax.faces.Format",
109                 "org.apache.myfaces.renderkit.html.HtmlFormatRenderer");
110 
111         addRenderer(facesContext, "javax.faces.Messages",
112                 "javax.faces.Messages",
113                 "org.apache.myfaces.renderkit.html.HtmlMessagesRenderer");
114 
115         addRenderer(facesContext, "javax.faces.SelectOne", "javax.faces.Radio",
116                 "org.apache.myfaces.renderkit.html.HtmlRadioRenderer");
117 
118         addRenderer(facesContext, "javax.faces.Input", "javax.faces.Secret",
119                 "org.apache.myfaces.renderkit.html.HtmlSecretRenderer");
120 
121         addRenderer(facesContext, "javax.faces.Data", "javax.faces.Table",
122                 "org.apache.myfaces.renderkit.html.HtmlTableRenderer");
123 
124         addRenderer(facesContext, "javax.faces.Input", "javax.faces.Textarea",
125                 "org.apache.myfaces.renderkit.html.HtmlTextareaRenderer");
126 
127         addRenderer(facesContext, "javax.faces.Input", "javax.faces.Text",
128                 "org.apache.myfaces.renderkit.html.HtmlTextRenderer");
129 
130         addRenderer(facesContext, "javax.faces.Output", "javax.faces.Text",
131                 "org.apache.myfaces.renderkit.html.HtmlTextRenderer");
132 
133         // extended standard renderers
134 
135         addRenderer(facesContext, "javax.faces.Command",
136                 "org.apache.myfaces.Button",
137                 "org.apache.myfaces.renderkit.html.ext.HtmlButtonExRenderer");
138 
139         addRenderer(facesContext, "javax.faces.Command",
140                 "org.apache.myfaces.Link",
141                 "org.apache.myfaces.renderkit.html.ext.HtmlLinkRenderer");
142 
143         addRenderer(facesContext, "javax.faces.Data",
144                 "org.apache.myfaces.Table",
145                 "org.apache.myfaces.renderkit.html.ext.HtmlTableRenderer");
146 
147         addRenderer(facesContext, "javax.faces.Panel",
148                 "org.apache.myfaces.Grid",
149                 "org.apache.myfaces.renderkit.html.ext.HtmlGridRenderer");
150 
151         addRenderer(facesContext, "javax.faces.Panel",
152                 "org.apache.myfaces.Group",
153                 "org.apache.myfaces.renderkit.html.ext.HtmlGroupRenderer");
154 
155         addRenderer(facesContext, "javax.faces.Input",
156                 "org.apache.myfaces.Secret",
157                 "org.apache.myfaces.renderkit.html.ext.HtmlSecretRenderer");
158 
159         addRenderer(facesContext, "javax.faces.Graphic",
160                 "org.apache.myfaces.Image",
161                 "org.apache.myfaces.renderkit.html.ext.HtmlImageRenderer");
162 
163         addRenderer(facesContext, "javax.faces.Input",
164                 "org.apache.myfaces.Text",
165                 "org.apache.myfaces.renderkit.html.ext.HtmlTextRenderer");
166 
167         addRenderer(facesContext, "javax.faces.Input",
168                 "org.apache.myfaces.TextHelp",
169                 "org.apache.myfaces.custom.inputTextHelp.HtmlTextHelpRenderer");
170 
171         addRenderer(facesContext, "javax.faces.Input",
172                 "org.apache.myfaces.Textarea",
173                 "org.apache.myfaces.renderkit.html.ext.HtmlTextareaRenderer");
174 
175         addRenderer(facesContext, "javax.faces.Message",
176                 "org.apache.myfaces.Message",
177                 "org.apache.myfaces.renderkit.html.ext.HtmlMessageRenderer");
178 
179         addRenderer(facesContext, "javax.faces.Messages",
180                 "org.apache.myfaces.Messages",
181                 "org.apache.myfaces.renderkit.html.ext.HtmlMessagesRenderer");
182 
183         addRenderer(facesContext, "javax.faces.Output",
184                 "org.apache.myfaces.Text",
185                 "org.apache.myfaces.renderkit.html.ext.HtmlTextRenderer");
186 
187         addRenderer(facesContext, "javax.faces.SelectBoolean",
188                 "org.apache.myfaces.Checkbox",
189                 "org.apache.myfaces.renderkit.html.ext.HtmlCheckboxRenderer");
190 
191         addRenderer(facesContext, "javax.faces.SelectMany",
192                 "org.apache.myfaces.Checkbox",
193                 "org.apache.myfaces.renderkit.html.ext.HtmlCheckboxRenderer");
194 
195         addRenderer(facesContext, "javax.faces.SelectOne",
196                 "org.apache.myfaces.Menu",
197                 "org.apache.myfaces.renderkit.html.ext.HtmlMenuRenderer");
198 
199         addRenderer(facesContext, "javax.faces.SelectMany",
200                 "org.apache.myfaces.Menu",
201                 "org.apache.myfaces.renderkit.html.ext.HtmlMenuRenderer");
202 
203         addRenderer(facesContext, "javax.faces.SelectOne",
204                 "org.apache.myfaces.Listbox",
205                 "org.apache.myfaces.renderkit.html.ext.HtmlListboxRenderer");
206 
207         addRenderer(facesContext, "javax.faces.SelectMany",
208                 "org.apache.myfaces.Listbox",
209                 "org.apache.myfaces.renderkit.html.ext.HtmlListboxRenderer");
210 
211         addRenderer(facesContext, "javax.faces.SelectOne",
212                 "org.apache.myfaces.Radio",
213                 "org.apache.myfaces.renderkit.html.ext.HtmlRadioRenderer");
214 
215         //  custom component renderers
216 
217         addRenderer(facesContext, "javax.faces.Data",
218                 "org.apache.myfaces.Buffer",
219                 "org.apache.myfaces.custom.buffer.BufferRenderer");
220 
221         addRenderer(facesContext, "javax.faces.Data",
222                 "org.apache.myfaces.Document",
223                 "org.apache.myfaces.custom.document.DocumentRenderer");
224 
225         addRenderer(facesContext, "javax.faces.Data",
226                 "org.apache.myfaces.DocumentHead",
227                 "org.apache.myfaces.custom.document.DocumentHeadRenderer");
228 
229         addRenderer(facesContext, "javax.faces.Data",
230                 "org.apache.myfaces.DocumentBody",
231                 "org.apache.myfaces.custom.document.DocumentBodyRenderer");
232 
233         addRenderer(facesContext, "org.apache.myfaces.Checkbox",
234                 "org.apache.myfaces.Checkbox",
235                 "org.apache.myfaces.renderkit.html.ext.HtmlCheckboxRenderer");
236 
237         addRenderer(facesContext, "javax.faces.Panel",
238                 "org.apache.myfaces.DataScroller",
239                 "org.apache.myfaces.custom.datascroller.HtmlDataScrollerRenderer");
240 
241         addRenderer(facesContext, "javax.faces.Input",
242                 "org.apache.myfaces.Calendar",
243                 "org.apache.myfaces.custom.calendar.HtmlCalendarRenderer");
244 
245         addRenderer(facesContext, "javax.faces.Input",
246                 "org.apache.myfaces.Date",
247                 "org.apache.myfaces.custom.date.HtmlDateRenderer");
248 
249         addRenderer(facesContext, "javax.faces.Input",
250                 "org.apache.myfaces.FileUpload",
251                 "org.apache.myfaces.custom.fileupload.HtmlFileUploadRenderer");
252 
253         addRenderer(facesContext, "javax.faces.Input",
254                 "org.apache.myfaces.InputHtml",
255                 "org.apache.myfaces.custom.inputHtml.InputHtmlRenderer");
256 
257         addRenderer(facesContext, "javax.faces.Panel",
258                 "org.apache.myfaces.Popup",
259                 "org.apache.myfaces.custom.popup.HtmlPopupRenderer");
260 
261         addRenderer(facesContext, "javax.faces.Panel",
262                 "org.apache.myfaces.Layout",
263                 "org.apache.myfaces.custom.layout.HtmlLayoutRenderer");
264 
265         addRenderer(facesContext, "javax.faces.Panel",
266                 "org.apache.myfaces.Navigation",
267                 "org.apache.myfaces.custom.navigation.HtmlNavigationRenderer");
268 
269         addRenderer(facesContext, "javax.faces.Panel",
270                 "org.apache.myfaces.NavigationMenu",
271                 "org.apache.myfaces.custom.navmenu.htmlnavmenu.HtmlNavigationMenuRenderer");
272 
273         addRenderer(facesContext, "javax.faces.Command",
274                 "org.apache.myfaces.Navigation",
275                 "org.apache.myfaces.custom.navigation.HtmlNavigationRenderer");
276 
277         addRenderer(facesContext, "javax.faces.Command",
278                 "org.apache.myfaces.NavigationMenu",
279                 "org.apache.myfaces.custom.navmenu.htmlnavmenu.HtmlNavigationMenuRenderer");
280 
281         addRenderer(facesContext, "javax.faces.Command",
282                 "org.apache.myfaces.JSCookMenu",
283                 "org.apache.myfaces.custom.navmenu.jscookmenu.HtmlJSCookMenuRenderer");
284 
285         addRenderer(facesContext, "javax.faces.Command",
286                 "org.apache.myfaces.SortHeader",
287                 "org.apache.myfaces.custom.sortheader.HtmlSortHeaderRenderer");
288 
289         addRenderer(facesContext, "javax.faces.Panel",
290                 "org.apache.myfaces.TabbedPane",
291                 "org.apache.myfaces.custom.tabbedpane.HtmlTabbedPaneRenderer");
292 
293         addRenderer(facesContext, "javax.faces.Panel",
294                 "org.apache.myfaces.CollapsiblePanel",
295                 "org.apache.myfaces.custom.collapsiblepanel.HtmlCollapsiblePanelRenderer");
296 
297         addRenderer(facesContext, "javax.faces.Data",
298                 "org.apache.myfaces.List",
299                 "org.apache.myfaces.custom.datalist.HtmlListRenderer");
300 
301         addRenderer(facesContext, "javax.faces.Data",
302                 "org.apache.myfaces.HtmlNewspaperTable",
303                 "org.apache.myfaces.custom.newspaper.HtmlNewspaperTableRenderer");
304 
305         addRenderer(facesContext, "javax.faces.Output",
306                 "org.apache.myfaces.JsValueSet",
307                 "org.apache.myfaces.custom.jsvalueset.HtmlJsValueSetRenderer");
308 
309         addRenderer(facesContext, "javax.faces.Output",
310                 "org.apache.myfaces.JsValueChangeListener",
311                 "org.apache.myfaces.custom.jslistener.JsValueChangeListenerRenderer");
312 
313         addRenderer(facesContext, "org.apache.myfaces.Radio",
314                 "org.apache.myfaces.Radio",
315                 "org.apache.myfaces.renderkit.html.ext.HtmlRadioRenderer");
316 
317         addRenderer(facesContext, "javax.faces.SelectOne",
318                 "org.apache.myfaces.SelectOneCountryRenderer",
319                 "org.apache.myfaces.custom.selectOneCountry.SelectOneCountryRenderer");
320 
321         addRenderer(facesContext, "javax.faces.SelectOne",
322                 "org.apache.myfaces.SelectOneLanguageRenderer",
323                 "org.apache.myfaces.custom.selectOneLanguage.SelectOneLanguageRenderer");
324 
325         addRenderer(facesContext, "javax.faces.Output",
326                 "org.apache.myfaces.Stylesheet",
327                 "org.apache.myfaces.custom.stylesheet.StylesheetRenderer");
328 
329         addRenderer(facesContext, "javax.faces.Output",
330                 "org.apache.myfaces.HtmlTagRenderer",
331                 "org.apache.myfaces.custom.htmlTag.HtmlTagRenderer");
332 
333         addRenderer(facesContext, "javax.faces.Output",
334                 "org.apache.myfaces.DojoInitializerRenderer",
335                 "org.apache.myfaces.custom.dojo.DojoInitializerRenderer");
336 
337         addRenderer(facesContext, "org.apache.myfaces.HtmlTree2",
338                 "org.apache.myfaces.HtmlTree2",
339                 "org.apache.myfaces.custom.tree2.HtmlTreeRenderer");
340 
341         addRenderer(facesContext, "org.apache.myfaces.HtmlTree",
342                 "org.apache.myfaces.HtmlTree",
343                 "org.apache.myfaces.custom.tree.renderkit.html.HtmlTreeRenderer");
344 
345         addRenderer(
346                 facesContext,
347                 "org.apache.myfaces.HtmlTree",
348                 "org.apache.myfaces.HtmlTreeImageCommandLink",
349                 "org.apache.myfaces.custom.tree.renderkit.html.HtmlTreeImageCommandLinkRenderer");
350 
351         addRenderer(facesContext, "org.apache.myfaces.HtmlTreeCheckbox",
352                 "org.apache.myfaces.HtmlTreeCheckbox",
353                 "org.apache.myfaces.custom.tree.renderkit.html.HtmlTreeCheckboxRenderer");
354 
355         addRenderer(facesContext, "javax.faces.Command",
356                 "org.apache.myfaces.HtmlTreeNode",
357                 "org.apache.myfaces.custom.tree.renderkit.html.HtmlTreeNodeRenderer");
358 
359         addRenderer(facesContext, "javax.faces.Panel",
360                 "org.apache.myfaces.PanelStack",
361                 "org.apache.myfaces.custom.panelstack.HtmlPanelStackRenderer");
362 
363         addRenderer(facesContext, "javax.faces.Graphic",
364                 "org.apache.myfaces.SwapImage",
365                 "org.apache.myfaces.custom.swapimage.HtmlSwapImageRenderer");
366 
367         addRenderer(facesContext, "javax.faces.Panel",
368                 "org.apache.myfaces.Schedule",
369                 "org.apache.myfaces.custom.schedule.ScheduleDelegatingRenderer");
370 
371         addRenderer(facesContext, "javax.faces.Data",
372                 "org.apache.myfaces.Table",
373                 "org.apache.myfaces.renderkit.html.ext.HtmlTableRenderer");
374         
375         addRenderer(facesContext, "org.apache.myfaces.CAPTCHA",
376                 "org.apache.myfaces.CAPTCHA",
377                 "org.apache.myfaces.custom.captcha.CAPTCHARenderer");
378         
379         addRenderer(facesContext, "javax.faces.Output",
380                 "org.apache.myfaces.DivRenderer",
381                 "org.apache.myfaces.custom.div.DivRenderer");
382         
383         addRenderer(facesContext, "javax.faces.SelectMany",
384                 "org.apache.myfaces.PicklistRenderer",
385                 "org.apache.myfaces.custom.picklist.HtmlPicklistRenderer");
386         
387         addRenderer(facesContext, "org.apache.myfaces.SelectOneRow",
388                 "org.apache.myfaces.SelectOneRow",
389                 "org.apache.myfaces.custom.selectOneRow.SelectOneRowRenderer");
390         
391         addRenderer(facesContext, "org.apache.myfaces.HtmlTree",
392                 "javax.faces.Group",
393                 "org.apache.myfaces.custom.tree.renderkit.html.HtmlTreeRenderer");
394         
395         addRenderer(facesContext, "javax.faces.Panel",
396                 "org.apache.myfaces.AccordionPanel",
397                 "org.apache.myfaces.custom.accordion.HtmlAccordionPanelRenderer");
398         
399         addRenderer(facesContext, "javax.faces.SelectOne",
400                 "org.apache.myfaces.AjaxChildComboBox",
401                 "org.apache.myfaces.custom.ajaxchildcombobox.HtmlAjaxChildComboBoxRenderer");
402         
403         addRenderer(facesContext, "javax.faces.Data",
404                 "org.apache.myfaces.AutoUpdateDataTable",
405                 "org.apache.myfaces.custom.autoupdatedatatable.AutoUpdateDataTableRenderer");
406         
407         addRenderer(facesContext, "javax.faces.Output",
408                 "org.apache.myfaces.FieldsetRenderer",
409                 "org.apache.myfaces.custom.fieldset.FieldsetRenderer");
410         
411         addRenderer(facesContext, "javax.faces.Form",
412                 "org.apache.myfaces.Form",
413                 "org.apache.myfaces.custom.form.HtmlFormRenderer");
414         
415         addRenderer(facesContext, "javax.faces.Graphic",
416                 "org.apache.myfaces.GraphicImageDynamicRenderer",
417                 "org.apache.myfaces.custom.graphicimagedynamic.GraphicImageDynamicRenderer");        
418 
419         addRenderer(facesContext, "javax.faces.Command",
420                 "org.apache.myfaces.CommandButtonAjax",
421                 "org.apache.myfaces.custom.inputAjax.HtmlCommandButtonAjaxRenderer");
422         
423         addRenderer(facesContext, "javax.faces.Input",
424                 "org.apache.myfaces.InputTextAjax",
425                 "org.apache.myfaces.custom.inputAjax.HtmlInputTextAjaxRenderer");
426         
427         addRenderer(facesContext, "javax.faces.SelectBoolean",
428                 "org.apache.myfaces.CheckboxAjax",
429                 "org.apache.myfaces.custom.inputAjax.HtmlSelectBooleanCheckboxAjaxRenderer");
430         
431         addRenderer(facesContext, "javax.faces.SelectMany",
432                 "org.apache.myfaces.CheckboxAjax",
433                 "org.apache.myfaces.custom.inputAjax.HtmlSelectManyCheckboxAjaxRenderer");
434         
435         addRenderer(facesContext, "javax.faces.SelectOne",
436                 "org.apache.myfaces.SelectOneRadioAjax",
437                 "org.apache.myfaces.custom.inputAjax.HtmlSelectOneRadioAjaxRenderer");
438         
439         addRenderer(facesContext, "javax.faces.Output",
440                 "org.apache.myfaces.OutputLinkDynamicRenderer",
441                 "org.apache.myfaces.custom.outputlinkdynamic.OutputLinkDynamicRenderer");
442         
443         addRenderer(facesContext, "org.apache.myfaces.PasswordStrength",
444                 "org.apache.myfaces.PasswordStrength",
445                 "org.apache.myfaces.custom.passwordStrength.PasswordStrengthRenderer");
446         
447         addRenderer(facesContext, "org.apache.myfaces.PPRPanelGroup",
448                 "org.apache.myfaces.PPRPanelGroup",
449                 "org.apache.myfaces.custom.ppr.PPRPanelGroupRenderer");
450         
451         addRenderer(facesContext, "javax.faces.Output",
452                 "org.apache.myfaces.HtmlRoundedDiv",
453                 "org.apache.myfaces.custom.roundeddiv.HtmlRoundedDivRenderer");
454         
455         addRenderer(facesContext, "javax.faces.Input",
456                 "org.apache.myfaces.InputSuggest",
457                 "org.apache.myfaces.custom.suggest.InputSuggestRenderer");
458         
459         addRenderer(facesContext, "javax.faces.Input",
460                 "org.apache.myfaces.InputSuggestAjax",
461                 "org.apache.myfaces.custom.suggestajax.SuggestAjaxRenderer");
462         
463         addRenderer(facesContext, "javax.faces.Panel",
464                 "org.apache.myfaces.ToggleGroup",
465                 "org.apache.myfaces.custom.toggle.ToggleGroupRenderer");
466         
467         addRenderer(facesContext, "javax.faces.Output",
468                 "org.apache.myfaces.ToggleLink",
469                 "org.apache.myfaces.custom.toggle.ToggleLinkRenderer");
470         
471         addRenderer(facesContext, "javax.faces.Panel",
472                 "org.apache.myfaces.TogglePanel",
473                 "org.apache.myfaces.custom.toggle.TogglePanelRenderer");
474     }
475 
476     /**
477      * Add a renderer to the FacesContext.
478      * 
479      * @param facesContext Faces Context
480      * @param family Componenet Family
481      * @param rendererType Component Type
482      * @param renderClassName Class Name of Renderer
483      */
484     public static void addRenderer(FacesContext facesContext, String family,
485             String rendererType, String renderClassName)
486     {
487         Renderer renderer = (javax.faces.render.Renderer) newInstance(renderClassName);
488         RenderKit kit = facesContext.getRenderKit();
489         kit.addRenderer(family, rendererType, renderer);
490     }
491 
492     /**
493      * Tries a Class.loadClass with the context class loader of the current thread first and
494      * automatically falls back to the ClassUtils class loader (i.e. the loader of the
495      * myfaces.jar lib) if necessary.
496      * 
497      * Note: This was copied from org.apache.myfaces.shared.util.ClassUtils
498      *
499      * @param type fully qualified name of a non-primitive non-array class
500      * @return the corresponding Class
501      * @throws NullPointerException if type is null
502      * @throws ClassNotFoundException
503      */
504     private static Class classForName(String type)
505             throws ClassNotFoundException
506     {
507         if (type == null)
508             throw new NullPointerException("type");
509         try
510         {
511             // Try WebApp ClassLoader first
512             return Class.forName(type, false, // do not initialize for faster startup
513                     Thread.currentThread().getContextClassLoader());
514         }
515         catch (ClassNotFoundException ignore)
516         {
517             // fallback: Try ClassLoader for ClassUtils (i.e. the myfaces.jar lib)
518             return Class.forName(type, false, // do not initialize for faster startup
519                     TestUtils.class.getClassLoader());
520         }
521     }
522 
523     /**
524      * Same as {@link #classForName(String)}, but throws a RuntimeException
525      * (FacesException) instead of a ClassNotFoundException.
526      *
527      * Note: This was copied from org.apache.myfaces.shared.util.ClassUtils
528      *
529      * @return the corresponding Class
530      * @throws NullPointerException if type is null
531      * @throws FacesException if class not found
532      */
533     private static Class simpleClassForName(String type)
534     {
535         try
536         {
537             return classForName(type);
538         }
539         catch (ClassNotFoundException e)
540         {
541             log.error("Class " + type + " not found", e);
542             throw new FacesException(e);
543         }
544     }
545 
546     /**
547      * Create an instance of the class with the type of <code>type</code>.
548      * 
549      * Note: This was copied from org.apache.myfaces.shared.util.ClassUtils
550      *
551      * @param type Type of new class.
552      * @return Instance of the class <code>type</code>
553      * @throws FacesException
554      */
555     private static Object newInstance(String type) throws FacesException
556     {
557         if (type == null)
558             return null;
559         return newInstance(simpleClassForName(type));
560     }
561 
562     /**
563      * Create an instance of the class <code>clazz</code>.
564      * 
565      * Note: This was copied from org.apache.myfaces.shared.util.ClassUtils
566      *
567      * @param clazz Class to create an instance of.
568      * @return Instance of the class <code>clazz</code>
569      * @throws FacesException
570      */
571     private static Object newInstance(Class clazz) throws FacesException
572     {
573         try
574         {
575             return clazz.newInstance();
576         }
577         catch (NoClassDefFoundError e)
578         {
579             log.error("Class : " + clazz.getName() + " not found.", e);
580             throw new FacesException(e);
581         }
582         catch (InstantiationException e)
583         {
584             log.error(e.getMessage(), e);
585             throw new FacesException(e);
586         }
587         catch (IllegalAccessException e)
588         {
589             log.error(e.getMessage(), e);
590             throw new FacesException(e);
591         }
592     }
593 
594     /**
595      * Renderered a component, including it's children, then complete the reponse.
596      * 
597      * @param context Faces Context
598      * @param component Component to be rendered.
599      * @throws IOException Thrown while rendering.
600      */
601     public static void renderComponent(FacesContext context,
602             UIComponent component) throws IOException
603     {
604         Renderer renderer = context.getRenderKit().getRenderer(
605                 component.getFamily(), component.getRendererType());
606         renderer.encodeBegin(context, component);
607         renderer.encodeChildren(context, component);
608         renderer.encodeEnd(context, component);
609         context.responseComplete();
610         context.renderResponse();
611     }
612 }