001    /*******************************************************************************
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     * http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     *******************************************************************************/
019    package org.apache.commons.convert;
020    
021    /** Converter interface. Classes implement this interface to convert one
022     * Java object type to another.
023     *
024     * @param <S> The source object type
025     * @param <T> The target object type
026     */
027    public interface Converter<S, T> {
028        /** Returns <code>true</code> if this object can convert
029         * <code>sourceClass</code> to <code>targetClass</code>.
030         * <p>Implementations can accomodate class hierarchy ranges
031         * by converting super classes or interfaces.</p>
032         *
033         * @param sourceClass The source <code>Class</code>
034         * @param targetClass The target <code>Class</code>
035         * @return <code>true</code> if this object can convert
036         * <code>sourceClass</code> to <code>targetClass</code>.
037         */
038        public boolean canConvert(Class<?> sourceClass, Class<?> targetClass);
039    
040        /** Converts <code>obj</code> to <code>T</code>.
041         *
042         * @param obj The source <code>Object</code> to convert
043         * @return The converted <code>Object</code>
044         * @throws ConversionException
045         */
046        public T convert(S obj) throws ConversionException;
047    
048        /** Returns the source <code>Class</code> for this converter.
049         *
050         * @return The source <code>Class</code> for this converter
051         */
052        public Class<?> getSourceClass();
053    
054        /** Returns the target <code>Class</code> for this converter.
055         *
056         * @return The target <code>Class</code> for this converter
057         */
058        public Class<?> getTargetClass();
059    }