/*
 * UploadItem.java		Date created: 03.03.2008
 * Last modified by: $Author$
 * $Revision$	$Date$
 */

package org.richfaces.model;

import java.io.File;

/**
 * Class provides object holder for file uploaded.
 * Instance of this type will be returned by UploadEvent after appropriate listener called after uploading has been completed.    
 * @author "Andrey Markavtsov"
 *
 */
public class UploadItem {
    
    /** Users file name */
    private String fileName;
    
    /** java.io.File instance */
    private File file;
    
    /** File byte content */
    private byte [] bytes;
    
    /**
     * Constructor for the UploadItem
     */
    public UploadItem(String fileName, Object file) {
	this.fileName = fileName;
	if (null != file) {
	    if (file.getClass().isAssignableFrom(File.class)) {
		this.file = (File) file;
	    } else if (file.getClass().isAssignableFrom(byte[].class)) {
		this.bytes = (byte[]) file;
	    }
	}
    }
    
    /**
     * Return true if file is holding as java.io.File type.
     * If true getFile method should be invoked to get file uploaded.
     * In another case getData method should be invoked to get file's bytes.
     * @return
     */
    public boolean isFile () {
	return (null != file);
    }

    /**
     * @return the file
     */
    public File getFile() {
        return file;
    }

    /**
     * @return the bytes
     */
    public byte[] getData() {
        return bytes;
    }

    /**
     * @return the fileName
     */
    public String getFileName() {
        return fileName;
    }
}
