1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.beanutils.converters; 18 19 import org.apache.commons.beanutils.Converter; 20 21 /** 22 * Provides a facade for {@link Converter} implementations 23 * preventing access to any public API in the implementation, 24 * other than that specified by {@link Converter}. 25 * <p /> 26 * This implementation can be used to prevent registered {@link Converter} 27 * implementations that provide configuration options from being 28 * retrieved and modified. 29 * 30 * @version $Id$ 31 * @since 1.8.0 32 */ 33 public final class ConverterFacade implements Converter { 34 35 private final Converter converter; 36 37 /** 38 * Construct a converter which delegates to the specified 39 * {@link Converter} implementation. 40 * 41 * @param converter The converter to delegate to 42 */ 43 public ConverterFacade(final Converter converter) { 44 if (converter == null) { 45 throw new IllegalArgumentException("Converter is missing"); 46 } 47 this.converter = converter; 48 } 49 50 /** 51 * Convert the input object into an output object of the 52 * specified type by delegating to the underlying {@link Converter} 53 * implementation. 54 * 55 * @param <T> The result type of the conversion 56 * @param type Data type to which this value should be converted 57 * @param value The input value to be converted 58 * @return The converted value. 59 */ 60 public <T> T convert(final Class<T> type, final Object value) { 61 return converter.convert(type, value); 62 } 63 64 /** 65 * Provide a String representation of this facade implementation 66 * sand the underlying {@link Converter} it delegates to. 67 * 68 * @return A String representation of this facade implementation 69 * sand the underlying {@link Converter} it delegates to 70 */ 71 @Override 72 public String toString() { 73 return "ConverterFacade[" + converter.toString() + "]"; 74 } 75 76 }