package org.texttechnologylab.project.gruppe_05_1.xml.mdb;

import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Institution;
import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils;
import org.texttechnologylab.project.gruppe_05_1.util.Logger;
import org.texttechnologylab.project.gruppe_05_1.xml.XmlOperations;
import org.w3c.dom.Node;

public class Institution_File_Impl extends Institution implements XmlOperations {
    @Override
    public Institution fromXmlNode(Node node) {

        Node current = node.getFirstChild();
        Node child;
        Institution inst = new Institution_File_Impl();
        while (null != current) {
            child = current.getFirstChild();
            switch (current.getNodeName()) {

                case "INSART_LANG":
                    inst.setInsartLang(null == child ? null : child.getNodeValue());
                    break;

                case "INS_LANG":
                    inst.setInsLang(null == child ? null : child.getNodeValue());
                    break;

                case "MDBINS_VON":
                    inst.setMdbinsVon(null == child ? null : GeneralUtils.parseDate(child.getNodeValue()));
                    break;

                case "MDBINS_BIS":
                    inst.setMdbinsBis(null == child ? null : GeneralUtils.parseDate(child.getNodeValue()));
                    break;

                case "FKT_LANG":
                    inst.setFktLang(null == child ? null : child.getNodeValue());
                    break;

                case "FKTINS_VON":
                    inst.setFktinsVon(null == child ? null : GeneralUtils.parseDate(child.getNodeValue()));
                    break;

                case "FKTINS_BIS":
                    inst.setFktinsBis(null == child ? null : GeneralUtils.parseDate(child.getNodeValue()));
                    break;

                case "#text":
                    break;

                default:
                    Logger.error("Node name does not match anything known in Institution: " + current.getNodeName());
            }
            current = current.getNextSibling();
        }

        return inst;
    }
}
