View Javadoc

1   /*
2    * Copyright 2006-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.dxo.converter.impl;
17  
18  import org.apache.commons.fileupload.FileItem;
19  import org.seasar.extension.dxo.converter.ConversionContext;
20  import org.seasar.extension.dxo.converter.impl.AbstractConverter;
21  
22  public abstract class AbstractFileItemConverter extends AbstractConverter {
23  
24  	@SuppressWarnings("unchecked")
25  	public Class[] getSourceClasses() {
26  		return new Class[] { FileItem.class, FileItem[].class };
27  	}
28  
29  	@SuppressWarnings("unchecked")
30  	public Object convert(final Object source, final Class destClass,
31  			final ConversionContext context) {
32  		if (source == null) {
33  			return null;
34  		}
35  		if (source instanceof FileItem) {
36  			final FileItem fileItem = (FileItem) source;
37  			return convert(fileItem);
38  		}
39  		if (source instanceof FileItem[]) {
40  			final FileItem[] fileItems = (FileItem[]) source;
41  			return convert(fileItems[0]);
42  		}
43  		return null;
44  	}
45  
46  	protected abstract Object convert(final FileItem fileItem);
47  
48  }