/*
 * $Id: DOMAttrImpl.java,v 1.1 2005/11/03 09:41:47 sugimotokenichi Exp $
 * Copyright (C) 2005 SUGIMOTO Ken-ichi
 * 作成日: 2005/10/30
 */
package feat.v1.impl.template;

import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;

import feat.v1.template.HTMLElement;
import feat.v1.template.HTMLNode;
import feat.v1.template.NodeNotFoundException;

/**
 * DOM APIのAttrの実装。
 * @author SUGIMOTO Ken-ichi
 */
public class DOMAttrImpl extends DOMNodeImpl implements Attr {

    DOMAttrImpl(HTMLValuedAttribute htmlNode) {
        super(htmlNode);
    }

    private HTMLValuedAttribute getHTMLAttribute() {
        return (HTMLValuedAttribute)convertHTML();
    }

    public short getNodeType() {
        return ATTRIBUTE_NODE;
    }

    public boolean hasAttributes() {
        return false;
    }

    public String getLocalName() {
        return this.getName();
    }

    public String getNodeName() {
        return this.getName();
    }

    public String getNodeValue() throws DOMException {
        return this.getValue();
    }

    public void setNodeValue(String nodeValue) throws DOMException {
        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
    }

    public NamedNodeMap getAttributes() {
        return new HTMLNodeMapImpl();
    }

    public NodeList getChildNodes() {
        return new HTMLNodeListImpl();
    }

    // Attrの実装

    public String getName() {
        return getHTMLAttribute().getName();
    }

    public Element getOwnerElement() {
        try {
            HTMLNode parent = getHTMLAttribute().getParent();
            if ( parent instanceof HTMLElement ) {
                return (Element)TemplateUtil.toDomNode(parent);
            }
        }
        catch (NodeNotFoundException ex) {
        }
        return null;
    }

    public boolean getSpecified() {
        return false;
    }

    public String getValue() {
        return getHTMLAttribute().getValue();
    }

    public void setValue(String value) throws DOMException {
        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
    }

}
