package org.xbib.io.webdav.common;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xbib.io.webdav.api.DavConstants;

/**
 * The <code>SupportedMethodSetProperty</code>
 */
public class SupportedMethodSetProperty extends AbstractDavProperty<String[]> {

    private final String[] methods;

    /**
     * Create a new <code>SupportedMethodSetProperty</code> property.
     *
     * @param methods that are supported by the resource having this property.
     */
    public SupportedMethodSetProperty(String[] methods) {
        super(DavPropertyName.create("supported-method-set", DavConstants.NAMESPACE), true);
        this.methods = methods;
    }

    public String[] getValue() {
        return methods;
    }

    @Override
    public Element toXml(Document document) {
        Element elem = getName().toXml(document);
        for (String method : methods) {
            Element methodElem = DomUtil.addChildElement(elem, "supported-method", DavConstants.NAMESPACE);
            DomUtil.setAttribute(methodElem, "name", DavConstants.NAMESPACE, method);
        }
        return elem;
    }

}
