/*
 This file is part of the software framework JStatCom, 
 a library for building applications for data based analysis.

 Copyright (C) 2000-2005  Markus Kraetzig

 This library is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as
 published by the Free Software Foundation; either version 2.1 of the
 License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 USA
 */

package com.jstatcom.project;

import java.util.Date;

import javolution37.javolution.xml.XmlElement;
import javolution37.javolution.xml.XmlFormat;

import com.jstatcom.component.CompSettings;

/**
 * Holds data that is represented by an element in the OutputList.
 * 
 * @author Markus Kraetzig 
 */
public final class OutputData {

    /**
     * String holding the output.
     */
    public final String output;

    /**
     * Date on instantiation of this OutputData object.
     */
    public final Date date;

    /**
     * Identifier for underlying output, typically the name of the
     * PCall object.
     */
    public final String name;

    /**
     * The selected property, used by OutputList to set selection
     * after sorting the elements.
     */
    public boolean selected = false;

    /**
     * XML format field for (de)serialization.
     */
    public static final XmlFormat OutputData_XML = new XmlFormat(
            OutputData.class) {
        public void format(OutputData data, XmlElement xml) {
            xml.setAttribute("name", data.name);
            xml.setAttribute("date", data.date.getTime());
            xml.setAttribute("output", data.output);

        }

        public OutputData parse(XmlElement xml) {
            String nam = xml.getAttribute("name") + "";
            long dateMillis = Long.parseLong(xml.getAttribute("date") + "");
            String output = xml.getAttribute("output") + "";
            return new OutputData(nam, output, new Date(dateMillis));
        }
    };

    /**
     * Represents an output entry with a name and a string holding the actual
     * output from a computation.
     * 
     * @param name
     *            identifier for the corresponding output
     * @param output
     *            holds text information
     * @throws IllegalArgumentException
     *             if (name == null || name.length() == 0)
     */
    public OutputData(String name, String output) {
        if (name == null || name.length() == 0)
            throw new IllegalArgumentException("Argument was null.");
        this.name = name;
        this.output = output;
        this.date = new Date();
    }

    /**
     * Private constructor used for deserialization.
     * 
     * @param name
     *            identifier for the corresponding output
     * @param output
     *            holds text information
     * @param date
     *            original creation date
     */
    private OutputData(String name, String output, Date date) {
        this.name = name;
        this.output = output;
        this.date = date;
    }

    public String toString() {
        return name + " <" + CompSettings.getDefaultDateFormat().format(date)
                + ">";
    }

}
 

Ads help maintain this website.