    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.beanutils;
    018
    019/**
    020 * <p>{@link BeanUtilsBean} implementation that creates a
    021 * {@link ConvertUtilsBean2} and delegates conversion to
    022 * {@link ConvertUtilsBean#convert(Object, Class)}.
    023 * </p>
    024 *
    025 * <p>
    026 * To configure this implementation for the current context ClassLoader invoke
    027 * <code>BeanUtilsBean.setInstance(new BeanUtilsBean2());</code>
    028 * </p>
    029 *
    030 * <p>
    031 * BeanUtils 1.7.0 delegated all conversion to String to the converter
    032 * registered for the <code>String.class</code>. One of the improvements in
    033 * BeanUtils 1.8.0 was to upgrade the {@link Converter} implementations so
    034 * that they could handle conversion to String for their type (for example
    035 * IntegerConverter now handles conversion from an Integer to a String as
    036 * well as String to Integer).
    037 * </p>
    038 *
    039 * <p>
    040 * In order to take advantage of these improvements BeanUtils needs to change
    041 * how it gets the appropriate {@link Converter}. This functionality has been
    042 * implemented in the new {@link ConvertUtilsBean#lookup(Class, Class)} and
    043 * {@link ConvertUtilsBean#convert(Object, Class)} methods. However changing
    044 * {@link BeanUtilsBean} to use these methods could create compatibility
    045 * issues for existing users. In order to avoid that, this new
    046 * {@link BeanUtilsBean} implementation has been created (and the associated
    047 * {@link ConvertUtilsBean2}).
    048 * </p>
    049 *
    050 * @see ConvertUtilsBean2
    051 * @since 1.8.0
    052 */
    053public class BeanUtilsBean2 extends BeanUtilsBean {
    054
    055    /**
    056     * <p>Constructs an instance using new property
    057     * and conversion instances.</p>
    058     */
    059    public BeanUtilsBean2() {
    060        super(new ConvertUtilsBean2());
    061    }
    062
    063    /**
    064     * <p>Convert the value to an object of the specified class (if
    065     * possible).</p>
    066     *
    067     * @param value Value to be converted (may be null)
    068     * @param type Class of the value to be converted to
    069     * @return The converted value
    070     */
    071    @Override
    072    protected Object convert(final Object value, final Class<?> type) {
    073        return getConvertUtils().convert(value, type);
    074    }
    075}