/*
 * Created by Ray Plante for the National Virtual Observatory
 * c. 2006
 */
package net.ivoa.registry.search;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.DOMException;

/**
 * a wrapper class that adds an index lookup to a DOM Element
 */
public class IndexedElement implements Element {
    private Element del = null;

    /**
     * wrap a DOM Element
     */
    public IndexedElement(Element el) {
        del = el;
    }

    public String getTagName() { return del.getTagName(); }
    public String getAttribute(String name) { return del.getAttribute(name); }
    public void setAttribute(String name, String value) 
         throws DOMException
    { 
        del.setAttribute(name, value); 
    }
    public void removeAttribute(String name) throws DOMException {
        del.removeAttribute(name);
    }
    public Attr getAttributeNode(String name) { 
        return del.getAttributeNode(name);
    }
    public Attr setAttributeNode(Attr newAttr) throws DOMException {
        return del.setAttributeNode(newAttr);
    }
    public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
        return del.removeAttributeNode(oldAttr);
    }
    public NodeList getElementsByTagName(String name) {
        return new WrappingList(del.getElementsByTagName(name));
    }
    public String getAttributeNS(String namespaceURI, String localName) {
        return del.getAttributeNS(namespaceURI, localName);
    }
    public void setAttributeNS(String namespaceURI, String qualifiedName,
                               String value)
         throws DOMException
    {
        del.setAttributeNS(namespaceURI, qualifiedName, value);
    }
    public void removeAttributeNS(String namespaceURI, String localName)
         throws DOMException
    {
        del.removeAttributeNS(namespaceURI, localName);
    }
    public Attr getAttributeNodeNS(String namespaceURI, String localName) {
        return del.getAttributeNodeNS(namespaceURI, localName);
    }
    public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
        return del.setAttributeNodeNS(newAttr);
    }
    public NodeList getElementsByTagNameNS(String namespaceURI, 
                                           String localName)
    {
        return new WrappingList(del.getElementsByTagNameNS(namespaceURI, 
                                                           localName));
    }
    public boolean hasAttribute(String name) { return del.hasAttribute(name); }
    public boolean hasAttributeNS(String namespaceURI, String localName) {
        return del.hasAttributeNS(namespaceURI, localName);
    }
    public String getNodeName() { return del.getNodeName() }
    public String getNodeValue() throws DOMException { 
        return del.getNodeValue();
    }
    public void setNodeValue(String nodeValue) throws DOMException {
        del.setNodeValue(nodeValue);
    }
    public short getNodeType() { return del.getNodeType(); } 
    public Node getParentNode() { return del.getParentNode(); }
    public NodeList getChildNodes() {
        return new WrappingList(del.getChildNodes()); 
    }
    public Node getFirstChild() {
    }

                               

                         
        

    class WrappingList implements NodeList {
        NodeList nldel = null;
        public WrappingList(NodeList delegate) { nldel = delegate; }
        public Node item(int index) {
            Node out = nldel.item(index);
            if (out.getNodeType() == Node.ELEMENT_TYPE) 
                return new IndexedElement(out);
            else 
                return out;
        }
        public int getLength() { return nldel.getLength(); }
    }
}
