001/*
002 *  Copyright 2011 Christopher Pheby
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 */
016package org.jadira.bindings.core.binder;
017
018import java.lang.annotation.Annotation;
019
020public interface ConversionBinder {
021
022        /**
023         * Convert an object to the given target class
024         * This method infers the source type for the conversion from the runtime type of object.
025         * @param output The target class to convert the object to
026         * @param object The object to be converted
027         * @param <S> The Source type
028         * @param <T> The Target type
029         * @return The result of the conversion
030         */
031        <S,T> T convertTo(Class<T> output, Object object);
032        
033        /**
034         * Convert an object to the given target class
035         * This method infers the source type for the conversion from the runtime type of object.
036         * @param output The target class to convert the object to
037         * @param object The object to be converted
038         * @param qualifier The qualifier for which the binding must be registered
039         * @param <S> The Source type
040         * @param <T> The Target type
041         * @return The result of the conversion
042         */
043        <S,T> T convertTo(Class<T> output, Object object, Class<? extends Annotation> qualifier);
044        
045        // TODO Add find methods equating to convertTo
046    
047        /**
048         * Convert an object which is an instance of source class to the given target class
049         * @param input The class of the object to be converted
050         * @param output The target class to convert the object to
051         * @param object The object to be converted
052         * @param <S> The Source type
053         * @param <T> The Target type
054         * @return The result of the conversion
055         */
056        <S, T> T convertTo(Class<S> input, Class<T> output, Object object);
057
058        /**
059         * Convert an object which is an instance of source class to the given target class
060         * @param input The class of the object to be converted
061         * @param output The target class to convert the object to
062         * @param object The object to be converted
063         * @param qualifier Match the converter with the given qualifier
064         * @param <S> The Source type
065         * @param <T> The Target type
066         * @return The result of the conversion
067         */
068        <S, T> T convertTo(Class<S> input, Class<T> output, Object object, Class<? extends Annotation> qualifier);
069
070        /**
071         * Convert an object which is an instance of source class to the given target class
072         * @param key The converter key
073         * @param object The object to be converted
074         * @param <S> The Source type
075         * @param <T> The Target type
076         * @return The result of the conversion
077         */
078        <S, T> T convertTo(ConverterKey<S,T> key, Object object);
079}