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  
20  package org.apache.myfaces.tobago.renderkit;
21  
22  import org.apache.myfaces.tobago.internal.context.ResourceManagerFactory;
23  
24  import javax.faces.component.UIComponent;
25  import javax.faces.component.UIInput;
26  import javax.faces.context.FacesContext;
27  import javax.faces.convert.Converter;
28  import javax.faces.convert.ConverterException;
29  import java.io.IOException;
30  
31  public abstract class AbstractRendererBaseWrapper extends RendererBase {
32    
33    @Override
34    public final void onComponentCreated(
35        final FacesContext facesContext, final UIComponent component, final UIComponent parent) {
36      getRenderer(facesContext).onComponentCreated(facesContext, component, parent);
37    }
38  
39    @Override
40    public final boolean getRendersChildren() {
41      return getRenderer(FacesContext.getCurrentInstance()).getRendersChildren();
42    }
43  
44    @Override
45    public final void decode(final FacesContext facesContext, final UIComponent component) {
46      getRenderer(facesContext).decode(facesContext, component);
47    }
48    
49    @Override
50    protected final Object getCurrentValueAsObject(final UIInput input) {
51      return getRenderer(FacesContext.getCurrentInstance()).getCurrentValueAsObject(input);
52    }
53  
54    @Override
55    protected final String getCurrentValue(final FacesContext facesContext, final UIComponent component) {
56      return getRenderer(facesContext).getCurrentValue(facesContext, component);
57    }
58  
59    @Override
60    protected final Object getValue(final UIComponent component) {
61      return getRenderer(FacesContext.getCurrentInstance()).getValue(component);
62    }
63  
64    @Override
65    public final Converter getConverter(final FacesContext facesContext, final UIComponent component) {
66      return getRenderer(facesContext).getConverter(facesContext, component);
67    }
68  
69    @Override
70    public final Object getConvertedValue(
71        final FacesContext facesContext, final UIComponent component, final Object submittedValue)
72        throws ConverterException {
73      return getRenderer(facesContext).getConvertedValue(facesContext, component, submittedValue);
74    }
75  
76    @Override
77    public final void encodeBegin(final FacesContext facesContext, final UIComponent component) throws IOException {
78      getRenderer(facesContext).encodeBegin(facesContext, component);
79    }
80  
81    @Override
82    public final void encodeChildren(final FacesContext facesContext, final UIComponent component) throws IOException {
83      getRenderer(facesContext).encodeChildren(facesContext, component);
84    }
85  
86    @Override
87    public final void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {
88      getRenderer(facesContext).encodeEnd(facesContext, component);
89    }
90  
91    @Override
92    public final String convertClientId(final FacesContext facesContext, final String clientId) {
93      return getRenderer(facesContext).convertClientId(facesContext, clientId);
94    }
95  
96    protected final RendererBase getRenderer(final FacesContext facesContext) {
97      final RendererBase renderer = (RendererBase)
98          ResourceManagerFactory.getResourceManager(facesContext).getRenderer(facesContext, getRendererType());
99      if (renderer == null) {
100       throw new RuntimeException("No renderer found for rendererType='"+ getRendererType()
101           + "' in wrapper class '" + this.getClass().getName() + "'");
102     }
103     return renderer;
104   }
105 
106   protected abstract String getRendererType();
107 }