/*
 * Created on Jun 17, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.biomoby.shared.schema;

import java.util.Vector;

/**
 * @author Eddie
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class MElement {
	// enumeration of types
	/**
	 * A moby:String primitive type
	 */
	public static String STRING = "String";
	/**
	 * A moby:Integer primitive type
	 */
	public static String INTEGER = "Integer";
	/**
	 * A moby:Float primitive type
	 */
	public static String FLOAT = "Float";
	/**
	 * A moby:DateTime primitive type
	 */
	public static String DATA_TIME = "DataTime";
	
	/**
	 * A moby data type that is not a primitive.
	 */
	public static String NON_PRIMITIVE = "NonPrimitiveType";
	
	private String name = "";
	private String articleName = "";
	private Vector hasaMElements = new Vector();
	private Vector hasMElements = new Vector();;
	private String description = "";
	private String type = "";
	
	/**
	 * Default constructor. Name, etc need to be set.
	 */
	public MElement() {
	}
	
	public MElement(String name) {
		this.name = name;
	}
	
	public MElement(String name, String articleName) {
		this.name = name;
		this.articleName = articleName;
	}
	
	public String getArticleName()
	{
		return this.articleName;
	}	
	public MElement(String name, String articleName, String description) {
		this.name = name;
		this.articleName = articleName;
		this.description = description;
	}
	
	
	/**
	 * @return Returns the description.
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * @param description The description to set.
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * @return Returns the name.
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name The name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return Returns the type.
	 */
	public String getType() {
		return type;
	}
	/**
	 * @param type The type to set.
	 */
	public void setType(String type) {
		this.type = type;
	}
	/**
	 * @return Returns the hasaMElements.
	 */
	public Vector getHasaMElements() {
		return hasaMElements;
	}
	/**
	 * @return Returns the hasMElements.
	 */
	public Vector getHasMElements() {
		return hasMElements;
	}
	
	public boolean addHasMElement(MElement element) {
		return hasMElements.add(element);
	}
	
	public boolean addHasaMElement(MElement element) {
		return hasaMElements.add(element);
	}
	
	public static boolean isPrimitive(String object) {
		if (object.equals(MElement.STRING))
			return true;
		if (object.equals(MElement.INTEGER))
			return true;
		if (object.equals(MElement.FLOAT))
			return true;
		if (object.equals(MElement.DATA_TIME))
			return true;
		return false;
	}

	/**override the hashCode() and equals() method of Object; In MElementHashtable class, we will use a hashtable to
	/*store MElement and articleNames;*/
	public int hashCode()
	{
		return this.name.hashCode();
	}

	

	public boolean equals(Object obj)
	{
		if(obj==null)
		{
			return false;
		}

		if(obj instanceof MElement)
		{
			MElement mk=(MElement)obj;

			return (this.name).equalsIgnoreCase(mk.name);
		}
		return false;
	}

		
	public String toString() {
		return "\nBegin element**************************\n"+"Name: " + name +"\nArticleName: " + articleName + "\nDescription: " + description + "\nType: " + type+"\nHASA's:\n" + hasaMElements + "\nHAS's:\n" + hasMElements+"\nend the element++++++++\n\n";
}
}

