/**
 * 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.registry;

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

/**
 * @author Dmitry Repchevsky
 */

@XmlRootElement(name="simple")
public class Simple implements Serializable, Cloneable
{
    private String articleName;
    private ObjectType objectType;
    private ArrayList<Namespace> namespaces;

    @XmlAttribute(name="article_name")
    public String getArticleName()
    {
        return articleName;
    }

    public void setArticleName(String articleName)
    {
        this.articleName = articleName;
    }

    @XmlElement(name="object_type")
    public ObjectType getObjectType()
    {
        return objectType;
    }

    public void setObjectType(ObjectType objectType)
    {
        this.objectType = objectType;
    }

    public void addNamespace(Namespace namespace)
    {
        getNamespaces().add(namespace);
    }
    
    @XmlElement(name="namespace")
    public List<Namespace> getNamespaces()
    {
        if (namespaces == null)
        {
            namespaces = new ArrayList<Namespace>();
        }
        
        return namespaces;
    }

    @Override
    public Simple clone()
    {
        Simple clone;

        try
        {
            clone = (Simple)super.clone();

            if (objectType != null)
            {
              clone.objectType = objectType.clone();
            }
            
            if (namespaces != null)
            {
                clone.namespaces = (ArrayList<Namespace>)namespaces.clone();
                for (int i = 0, n = clone.namespaces.size(); i < n; i++)
                {
                    Namespace namespace = clone.namespaces.get(i);
                    clone.namespaces.set(i, namespace.clone());
                }
            }
        }
        catch(CloneNotSupportedException ex)
        {
            clone = null;
        }

        return clone;
    }
}
