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