1 /* 2 * Copyright 2004-2008 the Seasar Foundation and the Others. 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, 13 * either express or implied. See the License for the specific language 14 * governing permissions and limitations under the License. 15 */ 16 package org.seasar.cubby.converter; 17 18 /** 19 * 変換元クラスのインスタンスを変換先クラスのインスタンスに変換するコンバータを表します。 20 * 21 * @author baba 22 * @since 1.1.0 23 */ 24 public interface Converter { 25 26 /** 27 * このコンバータがサポートしているクラスを返します。 28 * 29 * @return このコンバータがサポートしているクラス 30 */ 31 Class<?> getObjectType(); 32 33 /** 34 * このコンバータが指定されたリクエストパラメータの型を指定された値の型に変換できるかを示します。 35 * <p> 36 * <code>parameterType</code> に <code>null</code> が指定された場合は 37 * <code>false</code> を返します。 38 * </p> 39 * 40 * @param parameterType 41 * リクエストパラメータの型 42 * @param objectType 43 * 値の型 44 * @return このコンバータが指定されたリクエストパラメータの型を指定された値の型に変換できる場合は <code>true</code>、そうでない場合は 45 * <code>false</code> 46 */ 47 boolean canConvert(Class<?> parameterType, Class<?> objectType); 48 49 /** 50 * <code>value</code>をこのコンバータがサポートしているクラスのインスタンスに変換します。 51 * 52 * @param value 53 * 変換元のオブジェクト 54 * @param objectType 55 * 値の型 56 * @param helper 57 * 変換のヘルパクラス 58 * 59 * @return <code>value</code>を変換したオブジェクト 60 */ 61 Object convertToObject(Object value, Class<?> objectType, 62 ConversionHelper helper); 63 64 /** 65 * このコンバータがサポートしているクラスのインスタンスである<code>value</code>を文字列に変換します。 66 * 67 * @param value 68 * 変換元のオブジェクト 69 * @param helper 70 * 変換のヘルパクラス 71 * 72 * @return <code>value</code>を変換した文字列 73 */ 74 String convertToString(Object value, ConversionHelper helper); 75 76 }