View Javadoc

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.impl;
17  
18  import org.apache.commons.fileupload.FileItem;
19  import org.seasar.cubby.converter.ConversionHelper;
20  
21  /**
22   * {@link FileItem}を他の型のオブジェクトに変換するクラスの抽象クラスです。
23   * 
24   * @author baba
25   * @since 1.1.0
26   */
27  public abstract class AbstractFileItemConverter extends AbstractConverter {
28  
29  	/**
30  	 * {@inheritDoc}
31  	 */
32  	@Override
33  	public boolean canConvert(Class<?> parameterType, Class<?> objectType) {
34  		if (parameterType == null) {
35  			return false;
36  		}
37  		if (!FileItem.class.isAssignableFrom(parameterType)) {
38  			return false;
39  		}
40  		return super.canConvert(parameterType, objectType);
41  	}
42  
43  	/**
44  	 * {@inheritDoc}
45  	 */
46  	public Object convertToObject(final Object value, final Class<?> objectType, ConversionHelper helper) {
47  		if (value == null) {
48  			return null;
49  		}
50  		final FileItem fileItem = (FileItem) value;
51  		return convert(fileItem);
52  	}
53  
54  	/**
55  	 * {@inheritDoc}
56  	 */
57  	public String convertToString(final Object value, ConversionHelper helper) {
58  		return null;
59  	}
60  
61  	/**
62  	 * {@link FileItem} を特定の型に変換します。
63  	 * 
64  	 * @param fileItem
65  	 *            変換元のインスタンス
66  	 * @return <code>fileItem</code>を変換したインスタンス
67  	 */
68  	protected abstract Object convert(final FileItem fileItem);
69  
70  }