1 /* 2 * Copyright 2011 Christopher Pheby 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.jadira.bindings.core.binder; 17 18 import java.lang.annotation.Annotation; 19 20 public interface ConversionBinder { 21 22 /** 23 * Convert an object to the given target class 24 * This method infers the source type for the conversion from the runtime type of object. 25 * @param output The target class to convert the object to 26 * @param object The object to be converted 27 * @param <S> The Source type 28 * @param <T> The Target type 29 * @return The result of the conversion 30 */ 31 <S,T> T convertTo(Class<T> output, Object object); 32 33 /** 34 * Convert an object to the given target class 35 * This method infers the source type for the conversion from the runtime type of object. 36 * @param output The target class to convert the object to 37 * @param object The object to be converted 38 * @param qualifier The qualifier for which the binding must be registered 39 * @param <S> The Source type 40 * @param <T> The Target type 41 * @return The result of the conversion 42 */ 43 <S,T> T convertTo(Class<T> output, Object object, Class<? extends Annotation> qualifier); 44 45 // TODO Add find methods equating to convertTo 46 47 /** 48 * Convert an object which is an instance of source class to the given target class 49 * @param input The class of the object to be converted 50 * @param output The target class to convert the object to 51 * @param object The object to be converted 52 * @param <S> The Source type 53 * @param <T> The Target type 54 * @return The result of the conversion 55 */ 56 <S, T> T convertTo(Class<S> input, Class<T> output, Object object); 57 58 /** 59 * Convert an object which is an instance of source class to the given target class 60 * @param input The class of the object to be converted 61 * @param output The target class to convert the object to 62 * @param object The object to be converted 63 * @param qualifier Match the converter with the given qualifier 64 * @param <S> The Source type 65 * @param <T> The Target type 66 * @return The result of the conversion 67 */ 68 <S, T> T convertTo(Class<S> input, Class<T> output, Object object, Class<? extends Annotation> qualifier); 69 70 /** 71 * Convert an object which is an instance of source class to the given target class 72 * @param key The converter key 73 * @param object The object to be converted 74 * @param <S> The Source type 75 * @param <T> The Target type 76 * @return The result of the conversion 77 */ 78 <S, T> T convertTo(ConverterKey<S,T> key, Object object); 79 }