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 StringBinder { 021 022 /** 023 * Convert a String to the given target class 024 * @param output The target class to convert the object to 025 * @param object The String to be converted 026 * @param <T> The type of the target class 027 * @return An instance of the target class 028 */ 029 <T> T convertFromString(Class<T> output, String object); 030 031 /** 032 * Convert a String to the given target class 033 * @param output The target class to convert the object to 034 * @param object The String to be converted 035 * @param qualifier The qualifier for which the binding must be registered 036 * @param <T> The type of the target class 037 * @return An instance of the target class 038 */ 039 <T> T convertFromString(Class<T> output, String object, Class<? extends Annotation> qualifier); 040 041 /** 042 * Convert an object to String 043 * This method infers the source type for the conversion from the runtime type of object. 044 * @param object The object to be converted 045 * @return A String 046 */ 047 String convertToString(Object object); 048 049 /** 050 * Convert an object to String 051 * This method infers the source type for the conversion from the runtime type of object. 052 * @param object The object to be converted 053 * @param qualifier The qualifier for which the binding must be registered 054 * @return A String 055 */ 056 String convertToString(Object object, Class<? extends Annotation> qualifier); 057 058 /** 059 * Convert an object which is an instance of source class to String 060 * @param input The class of the object to be converted 061 * @param object The object to be converted 062 * @param <S> The type of the input class 063 * @return A String 064 */ 065 <S> String convertToString(Class<S> input, Object object); 066 067 /** 068 * Convert an object which is an instance of source class to String 069 * @param input The class of the object to be converted 070 * @param object The object to be converted 071 * @param qualifier Match the converter with the given qualifier 072 * @param <S> The type of the input class 073 * @return A String 074 */ 075 <S> String convertToString(Class<S> input, Object object, Class<? extends Annotation> qualifier); 076}