// MobyRelationship.java
//    A container for a ontology relationship definition.
//
//    senger@ebi.ac.uk
//    September 2004
//

package org.biomoby.shared;



/**
 * A container representing a name of a BioMoby data type and its
 * relationship to another BioMoby data type. <p>
 *
 * @author <A HREF="mailto:senger@ebi.ac.uk">Martin Senger</A>
 * @version $Id: MobyRelationship.java,v 1.5 2006/07/07 04:12:40 gordonp Exp $
 */

public class MobyRelationship {

    protected String name;   // articleName
    protected String dataTypeName;
    protected int relationshipType = Central.iHASA;

    /**************************************************************************
     * Default constructor. <p>
     *************************************************************************/
    public MobyRelationship() {
	this ("_dummy_", "Object", Central.iISA);
    }

    /**************************************************************************
     * Normal constructor. <p>
     *
     * @param name is a name how this relationship is known (an
     * "article name" in the BioMoby speak), e.g. 'length'. Because of
     * the backward compatibility it accepts also a null or empty
     * string here - but according to the BioMoby API (0.8) this name
     * should be always given.
     * @param dataTypeName is a name of a data type that is defined by
     * this relationship, e.g. 'Integer'.
     * @param relationshipType is either {@link Central#iHASA HASA} or {@link
     * Central#iHAS HAS}. If it is something else it is silently changed to {@link
     * Central#iHASA HASA}.
     *************************************************************************/
    public MobyRelationship (String name, String dataTypeName, int relationshipType) {
	this.name = name;
	this.dataTypeName = dataTypeName;
	if (relationshipType != Central.iHASA && relationshipType != Central.iHAS)
	    relationshipType = Central.iHASA;
	this.relationshipType = relationshipType;
    }

    /**
     * Return name of this relationship (an "article name").
     */
    public String getName() {
	return name;
    }
    public void setName (String value) {
	name = value;
    }

    /**
     * Return a name of a data type that is linked by this
     * relationship.
     */
    public String getDataTypeName() {
	return dataTypeName;
    }
    public void setDataTypeName (String value) {
	dataTypeName = value;
    }

    /**
     * Return type of this relationship. It is either {@link Central#iHASA HASA} or
     * {@link Central#iHAS HAS}.
     */
    public int getRelationshipType() {
	return relationshipType;
    }
    public void setRelationshipType (int value) {
	relationshipType = value;
    }

    /**
     * A static method converting a relationship type to its string
     * representation. <p>
     *
     * @return a reasonable string, or "unknown"
     */
    public static String type2str (int relationshipType) {
	switch (relationshipType) {
	case Central.iHASA: return Central.HASA;
	case Central.iHAS: return Central.HAS;
	case Central.iISA: return Central.ISA;
	default: return "unknown";
	}
    }

    public String toString() {
	StringBuffer buf = new StringBuffer();
	buf.append (name);
	buf.append (" (");
	buf.append (type2str (relationshipType));
	buf.append (") => ");
	buf.append (dataTypeName);
	return new String (buf);
    }
}
