001    /*
002     *  Copyright 2003-2004 The Apache Software Foundation
003     *
004     *  Licensed under the Apache License, Version 2.0 (the "License");
005     *  you may not use this file except in compliance with the License.
006     *  You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     *  Unless required by applicable law or agreed to in writing, software
011     *  distributed under the License is distributed on an "AS IS" BASIS,
012     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     *  See the License for the specific language governing permissions and
014     *  limitations under the License.
015     */
016    package org.apache.commons.convert1.string;
017    
018    
019    import org.apache.commons.convert1.ConversionException;
020    import org.apache.commons.convert1.Converter;
021    
022    
023    /**
024     * <p>Standard {@link Converter} implementation that converts an incoming
025     * String into a <code>java.lang.String</code> object, optionally using a
026     * default value or throwing a {@link ConversionException} if a conversion
027     * error occurs.</p>
028     *
029     * @author Craig R. McClanahan
030     * @version $Id: StringConverter.java 155441 2005-02-26 13:19:22Z dirkv $
031     * @since 0.1
032     */
033    
034    ///H/ This class is useless. It turns a String into a String, 
035    ///H/ although the code itself doesn't know it's being given a String.
036    public final class StringConverter implements Converter {
037    
038    
039        // --------------------------------------------------------- Public Methods
040    
041    
042        /**
043         * Convert the specified input object into an output object of the
044         * specified type.
045         *
046         * @param type Data type to which this value should be converted
047         * @param value The input value to be converted
048         *
049         * @exception ConversionException if conversion cannot be performed
050         *  successfully
051         */
052        public Object convert(Class type, Object value) {
053    
054            if (value == null) {
055                return ((String) null);
056            } else {
057                return (value.toString());
058            }
059    
060        }
061    
062    
063    }