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