/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.csu.sdmx.validation.model.dsds;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 *
 * @author themi
 */
public class DsdUtility extends Dsd {
    
    private String keyElementName;

    public DsdUtility(Document doc) {
        super(doc);
    }

    @Override
    protected void extractDimensions(Document doc) {
        Element sub;
        
        sub = getSubElement(doc, "utility:DataSet");
        if (sub != null) {
            datasetElementName = sub.getAttribute("name");
        }
        
        sub = getSubElement(doc, "utility:Group");
        if (sub != null) {
            groupElementName = sub.getAttribute("name");
            groupDimensions = extractDimensions(doc, sub.getAttribute("type"));
        }
        
        sub = getSubElement(doc, "utility:Series");
        if (sub != null) {
            seriesElementName = sub.getAttribute("name");
            seriesDimensions = extractDimensions(doc, sub.getAttribute("type"));
        }
        
        sub = getSubElement(doc, "utility:Key");
        if (sub != null) {
            keyElementName = sub.getAttribute("name");
            seriesDimensions.addAll(extractDimensions(doc, sub.getAttribute("type"), "element"));
        }
        
        sub = getSubElement(doc, "utility:Obs");
        if (sub != null) {
            obsElementName = sub.getAttribute("name");
            obsDimensions = extractDimensions(doc, sub.getAttribute("type"));
            obsDimensions.addAll(extractDimensions(doc, sub.getAttribute("type"), "element"));
        }
    
    }
    
    @Override
    public String getType() {
        return Dsd.UTILITY;
    }

    public String getKeyElementName() {
        return keyElementName;
    }
}
