package usda.weru.mcrew;

import org.w3c.dom.*;
import java.util.Hashtable;

/**
 * Its kind of a template object that tells about different methods and
 * generic functionalities on what goes on in the crop and operation
 * obects.
 */
public abstract class DataObject implements Cloneable
{
    /**
     * The name of the data object which could be a crop or operation data
     * object.
     */    
	public String mObjectName;    
        
    /**
     * Stores the Limit values of each parameter name
     */
    Hashtable<String, InputLimits.TableStatus> lim = new Hashtable<String, InputLimits.TableStatus>();
	
    /**
     * A dummy method that basically tells the structure of the crop/operation 
     * data objects. Used for initializing the node element.
     * @param pNode The node object whose data is being initialized
     */    
	public void initialize(Node pNode)
	{
		//System.out.println("Dummy initialize" + " @DataObject:intialize()");
	}
	
    /**
     * The method that fetches the value of the parameter in the column
     * pColName and the in specified units i:e pUnit
     * @param pColName The coulumn where crop/operation dataobject sits.
     * @param pUnit The units in which we expect the value.
     * @return The value of the object in that column
     */    
	public String getValue(String pColName, int pUnit)
	{
		//System.out.println("DataObject: get() called - This is just dummy" + " @DataObject:intialize()");
		return null;
	}
	
    /**
     * The method that sets the parameter whose name is pParamName with the value
     * pNewValue in units pUnit
     * @param pParamName The name of the parameter whose value is being set
     * @param pNewValue The value to be set for the parameter pParamName.
     * @param pUnit The unit in which the new value will be set.
     */    
	public void setValue(String pParamName, String pNewValue, int pUnit)
	{
                //System.out.println("DataObject : setValue() : " + pParamName + " : & :" + pNewValue );
		//System.out.println("DataObject:setValue() called - This is just dummy");
		return;
		
	}
	
    /**
     * This method fetches the object name for the crop or operation data object.
     * we currently are referring to.
     * @return The name assigned to the object.
     */    
	public String getObjectName()
	{
		//System.out.println("Dummy getObjectName()" + " @DataObject:intialize()");
		return null;
	}
	
    /**
     * The method that fetches the first node from the document doc
     * @param doc The document whose node object is requested.
     * @return The first node object from different crop/operation XML files.
     */    
	public Node getNode(Document doc)
	{
		//System.out.println("Dummy getNode()" + " @DataObject:getNode()");
		return null;
	}
	
    /**
     * This method reads the XML crop and operation file to know what way their
     * data would be structured.
     * @param pFileName The XML file that needs to be read. This file tells us the 
     * structure in which to store the various crop or operation data.
     * @return Returns a +ve integer if the file is read successfully, else -ve
     */    
	public int readXMLFile(String pFileName)
	{
		//System.out.println("Dummy readXMLFile()" + " @DataObject:readXMLFile()");
		return 0;
	}

	/**
	 *
	 * @param obj
	 * @return
	 */
	@Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final DataObject other = (DataObject) obj;
        if (this.mObjectName != other.mObjectName && (this.mObjectName == null || !this.mObjectName.equals(other.mObjectName))) {
            return false;
        }
        return true;
    }

	/**
	 *
	 * @return
	 */
	@Override
    public int hashCode() {
        int hash = 7;
        hash = 71 * hash + (this.mObjectName != null ? this.mObjectName.hashCode() : 0);
        return hash;
    }
    
    public abstract InputLimits.TableStatus checkData();
    
    public Hashtable<String, InputLimits.TableStatus> getHash()
    {
        return lim;
    }
	
    /** 
     * This method makes a copy of an object that holds the crop data or operation data.
     * @return The object that holds 
     */    
    @Override
	public Object clone()
	{
		try
		{
			DataObject copy = (DataObject)super.clone();
			copy.mObjectName = mObjectName;
			
			return copy;
		}
		catch(CloneNotSupportedException e)
		{
			//System.err.println("DataObject::clone();" + "Clone Not Supported!");
		}
		return null;
	}
}
