/**
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 *
 * Copyright (C)
 * <a href="http://www.inab.org">Spanish National Institute of Bioinformatics (INB)</a>
 * <a href="http://www.bsc.es">Barcelona Supercomputing Center (BSC)</a>
 * <a href="http://inb.bsc.es">Computational Node 6</a>
 */

package org.inb.biomoby.shared.message;

import java.io.Serializable;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlElement;

/**
 * @author Dmitry Repchevsky
 */

public class MobyContent implements Serializable
{
    private ServiceNotes serviceNotes;
    private ArrayList<MobyData> mobyDataList;
    
    public MobyContent() {}
    
    public MobyContent(MobyData mobyData)
    {
        addMobyData(mobyData);
    }

    public MobyContent(ArrayList<MobyData> mobyDataList)
    {
        this.mobyDataList = mobyDataList;
    }

    @XmlElement
    public ServiceNotes getServiceNotes()
    {
        return serviceNotes;
    }
    
    public void setServiceNotes(ServiceNotes serviceNotes)
    {
        this.serviceNotes = serviceNotes;
    }
    
    public void addMobyData(MobyData mobyData)
    {
        getMobyDataList().add(mobyData);
    }

    @XmlElement(name="mobyData")
    public ArrayList<MobyData> getMobyDataList()
    {
        if (mobyDataList == null)
        {
            mobyDataList = new ArrayList<MobyData>();
        }
        return mobyDataList;
    }

    /**
     * Method adds an exeption to the content
     * It creates a serviceNotes if needed.
     * 
     * @param exception en exception to be added
     */
    public void addException(MobyException exception)
    {
        if (serviceNotes == null)
        {
            serviceNotes = new ServiceNotes();
        }
        
        serviceNotes.addException(exception);
    }
    
    /**
     * Method returns wherever it the content has an exception
     * 
     * @return true if there is an exeption
     */
    public boolean hasExceptions()
    {
        return serviceNotes != null && serviceNotes.hasExceptions();
    }
    
    /**
     * Method returns either a list of exceptions or null
     * 
     * @return a list of exceptions or null
     */
    public MobyExceptions getExceptions()
    {
        if (hasExceptions())
        {
            return serviceNotes.getExceptions();
        }
        
        return null;
    }
}
