View Javadoc

1   /*
2    * Copyright 2004-2010 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  
17  package org.seasar.cubby.converter;
18  
19  /**
20   * 変換元クラスのインスタンスを変換先クラスのインスタンスに変換するコンバータを表します。
21   * 
22   * @author baba
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  	 * @return <code>value</code>を変換したオブジェクト
59  	 * @throws ConversionException
60  	 *             型変換に失敗した場合
61  	 */
62  	Object convertToObject(Object value, Class<?> objectType,
63  			ConversionHelper helper) throws ConversionException;
64  
65  	/**
66  	 * このコンバータがサポートしているクラスのインスタンスである<code>value</code>を文字列に変換します。
67  	 * 
68  	 * @param value
69  	 *            変換元のオブジェクト
70  	 * @param helper
71  	 *            変換のヘルパクラス
72  	 * 
73  	 * @return <code>value</code>を変換した文字列
74  	 */
75  	String convertToString(Object value, ConversionHelper helper);
76  
77  }