001 package org.apache.myfaces.tobago.renderkit; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with 006 * this work for additional information regarding copyright ownership. 007 * The ASF licenses this file to You under the Apache License, Version 2.0 008 * (the "License"); you may not use this file except in compliance with 009 * the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020 import org.apache.myfaces.tobago.context.ResourceManagerFactory; 021 import org.slf4j.Logger; 022 import org.slf4j.LoggerFactory; 023 024 import javax.faces.component.UIComponent; 025 import javax.faces.component.UIInput; 026 import javax.faces.context.FacesContext; 027 import javax.faces.convert.Converter; 028 import javax.faces.convert.ConverterException; 029 import java.io.IOException; 030 031 public abstract class AbstractRendererBaseWrapper extends RendererBase { 032 033 private static final Logger LOG = LoggerFactory.getLogger(AbstractRendererBaseWrapper.class); 034 035 @Override 036 public final void onComponentCreated(FacesContext facesContext, UIComponent component, UIComponent parent) { 037 getRenderer(facesContext).onComponentCreated(facesContext, component, parent); 038 } 039 040 @Override 041 public final void prepareRender(FacesContext facesContext, UIComponent component) throws IOException { 042 getRenderer(facesContext).prepareRender(facesContext, component); 043 } 044 @Override 045 public final boolean getPrepareRendersChildren() { 046 return getRenderer(FacesContext.getCurrentInstance()).getPrepareRendersChildren(); 047 } 048 @Override 049 public final void prepareRendersChildren(FacesContext context, UIComponent component) { 050 getRenderer(context).prepareRendersChildren(context, component); 051 } 052 053 @Override 054 public final boolean getRendersChildren() { 055 return getRenderer(FacesContext.getCurrentInstance()).getRendersChildren(); 056 } 057 058 @Override 059 public final void decode(FacesContext facesContext, UIComponent component) { 060 getRenderer(facesContext).decode(facesContext, component); 061 } 062 063 @Override 064 protected final Object getCurrentValueAsObject(UIInput input) { 065 return getRenderer(FacesContext.getCurrentInstance()).getCurrentValueAsObject(input); 066 } 067 068 @Override 069 protected final String getCurrentValue(FacesContext facesContext, UIComponent component) { 070 return getRenderer(facesContext).getCurrentValue(facesContext, component); 071 } 072 073 @Override 074 protected final Object getValue(UIComponent component) { 075 return getRenderer(FacesContext.getCurrentInstance()).getValue(component); 076 } 077 078 @Override 079 public final Converter getConverter(FacesContext facesContext, UIComponent component) { 080 return getRenderer(facesContext).getConverter(facesContext, component); 081 } 082 083 @Override 084 public final Object getConvertedValue(FacesContext facesContext, UIComponent component, Object submittedValue) 085 throws ConverterException { 086 return getRenderer(facesContext).getConvertedValue(facesContext, component, submittedValue); 087 } 088 089 @Override 090 public final void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException { 091 getRenderer(facesContext).encodeBegin(facesContext, component); 092 } 093 094 @Override 095 public final void encodeChildren(FacesContext facesContext, UIComponent component) throws IOException { 096 getRenderer(facesContext).encodeChildren(facesContext, component); 097 } 098 099 @Override 100 public final void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException { 101 getRenderer(facesContext).encodeEnd(facesContext, component); 102 } 103 104 @Override 105 public final String convertClientId(FacesContext facesContext, String clientId) { 106 return getRenderer(facesContext).convertClientId(facesContext, clientId); 107 } 108 109 protected final RendererBase getRenderer(FacesContext facesContext) { 110 RendererBase renderer = (RendererBase) ResourceManagerFactory. 111 getResourceManager(facesContext).getRenderer(facesContext.getViewRoot(), getRendererType()); 112 if (renderer == null) { 113 throw new RuntimeException("No renderer found for rendererType='"+ getRendererType() 114 + "' in wrapper class '" + this.getClass().getName() + "'"); 115 } 116 return renderer; 117 } 118 119 protected abstract String getRendererType(); 120 }