// DataContainer.java
//
// Created: February 2006
//
// This file is a component of the BioMoby project.
// Copyright Martin Senger (martin.senger@gmail.com).
//

package org.biomoby.service.dashboard.data;

import org.biomoby.shared.MobyException;

import org.tulsoft.shared.FileUtils;
import org.tulsoft.shared.GException;

import java.io.File;
import java.io.IOException;

/**
 * A container for input and output service data. It is mainly used to
 * carry data between the SimpleClientPanel and its executor
 * ServiceCallerModel, and also to carry data to the individual result
 * renderers (class ResultsPanel). <p>
 *
 * The primary data are set either in constructor, or by {@link
 * #setData} or by {@link #setDataFromFile} (and get back by {@link
 * #getData}). <p>
 *
 * @author <A HREF="mailto:martin.senger@gmail.com">Martin Senger</A>
 * @version $Id: DataContainer.java,v 1.3 2006/02/20 05:51:10 senger Exp $
 */

public class DataContainer {

    private Object data;
    private Object metadata;

    /*************************************************************************
     * An empty constructor.
     *************************************************************************/
    public DataContainer() {
    }

    /*************************************************************************
     * A usual constructor, filling his container with the given data.
     *************************************************************************/
    public DataContainer (Object data) {
	setData (data);
    }

    /*************************************************************************
     * A usual constructor, filling his container with the given data.
     *************************************************************************/
    public DataContainer (Object data, Object metadata) {
	setData (data);
	setMetadata (metadata);
    }

    /*************************************************************************
     * Fill this container with data.
     *************************************************************************/
    public void setData (Object data) {
	this.data = data;
    }

    /*************************************************************************
     * Fill this container with metadata.
     *************************************************************************/
    public void setMetadata (Object metadata) {
	this.metadata = metadata;
    }

    /*************************************************************************
     * Get data from this container.
     *************************************************************************/
    public Object getData() {
	return data;
    }

    /*************************************************************************
     * Get metadata from this container.
     *************************************************************************/
    public Object getMetadata() {
	return metadata;
    }

    /*************************************************************************
     * Fill this container by data from the given file. Be aware that
     * this may not work for all kind of data.
     *************************************************************************/
    public void setDataFromFile (File file)
	throws MobyException {
	try {
	    setData (FileUtils.getFile (file.getAbsolutePath(), false));
	} catch (IOException e) {
	    throw new MobyException ("Cannot read file: " + e.toString());
	} catch (GException e) {
	    throw new MobyException (e.getMessage());
	}
    }

}
