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