package com.mobirent.datacollector;

import com.mobirent.abstracttags.DataClassable;
import com.mobirent.messageprocessor.MessageToObject;
import com.mobirent.messageprocessor.XmlNode;
import java.util.Vector;

/**
 *
 * @author Budai Attila
 */
public class Order implements DataClassable {

    private Vector orderedDvdList;
    private String orderID;

    public Order(Vector orderedDvdList, String orderID) {

        this.orderedDvdList = orderedDvdList;
        this.orderID = orderID;
    }

    public Order(XmlNode xmlNode) {

        XmlNode test;
        xmlNode = xmlNode.getNextNode();

        for (int i = 0; i < xmlNode.getSubNodes().size(); i++) {
            test = (XmlNode) xmlNode.getSubNodes().elementAt(i);
            if (test.getNodeName().equals("<orid>")) {
                orderID = test.getValue();
            } else if (test.getNodeName().equals("<odvd>")) {
                test = MessageToObject.keres(test, "<d>");
                for (; test.hasMoreNodes();) {
                    Dvd dvd = new Dvd(test);
                    if (this.orderedDvdList == null) {
                        this.orderedDvdList = new Vector();
                    }
                    this.orderedDvdList.addElement(dvd);
                    test.getNextNode();
                }
            }
        }
    }

    public Vector getOrderedDvdList() {
        return orderedDvdList;
    }

    public void setOrderedDvdList(Vector val) {
        this.orderedDvdList = val;
    }

    public String getOrderID() {
        return orderID;
    }

    public void setOrderID(String orderID) {
        this.orderID = orderID;
    }

    public String reportIt() {
        //throw new UnsupportedOperationException("Not supported yet.");
        return "report it";
    }

    public String toString() {
        StringBuffer strBuff = new StringBuffer();
        for (int i = 0; i < this.orderedDvdList.size(); i++) {
            strBuff.append(((Dvd) this.orderedDvdList.elementAt(i)).toString());

        }
        return strBuff.toString();
    }
}

