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

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import org.inb.biomoby.shared.registry.AbstractEntity;

/**
 * @author Dmitry Repchevsky
 */

@XmlRootElement(name="central")
public class MobyCentral extends AbstractEntity<MobyCentral> implements Comparable<MobyCentral>
{
    private String endpointURL;
    private String namespace;

    MobyCentral() {}

    public MobyCentral(String endpointURL, String namespace)
    {
        this.endpointURL = endpointURL;
        this.namespace = namespace;
    }

    @XmlAttribute
    public String getEndpointURL()
    {
        return endpointURL;
    }

    void setEndpointURL(String endpointURL)
    {
        this.endpointURL = endpointURL;
    }

    @XmlAttribute
    public String getNamespace()
    {
        return namespace;
    }

    void setNamespace(String namespace)
    {
        this.namespace = namespace;
    }

    @Override
    public int hashCode()
    {
        int hash = 7;
        hash = 71 * hash + (this.endpointURL != null ? this.endpointURL.hashCode() : 0);
        hash = 71 * hash + (this.namespace != null ? this.namespace.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (obj == null)
        {
            return false;
        }
        if (getClass() != obj.getClass())
        {
            return false;
        }
        
        final MobyCentral other = (MobyCentral) obj;
        
        if (this.endpointURL != other.endpointURL && (this.endpointURL == null || !this.endpointURL.equals(other.endpointURL)))
        {
            return false;
        }
        
        if (this.namespace != other.namespace && (this.namespace == null || !this.namespace.equals(other.namespace)))
        {
            return false;
        }
        
        return true;
    }
    
    public int compareTo(MobyCentral central)
    {
        int result;

        if (this == central)
        {
            result = 0;
        }
        else
        {
            result = endpointURL.compareTo(central.endpointURL);

            if (result == 0)
            {
                result = namespace.compareTo(central.namespace);
            }
        }

        return result;
    }
}
