/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.xml.impl;

import net.ranides.assira.generic.CompareUtils;
import net.ranides.assira.xml.XMLDocument;
import net.ranides.assira.xml.XMLElement;
import org.w3c.dom.Document;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class W3Document implements XMLDocument {
    
    private final Document doc;

    public W3Document(Document doc) {
        this.doc = doc;
    }

    @Override
    public Document node() {
        return doc;
    }

    @Override
    public XMLElement attr(String name) {
        return new W3Element(doc.createAttribute(name));
    }

    @Override
    public XMLElement cdata(String value) {
        return new W3Element(doc.createCDATASection(value));
    }

    @Override
    public XMLElement comment(String value) {
        return new W3Element(doc.createComment(value));
    }

    @Override
    public XMLElement fragment() {
        return new W3Element(doc.createDocumentFragment());
    }
    
    @Override
    public XMLElement fragment(String xml) {
        return W3CQuery.append(fragment(), xml);
    }
    
    @Override
    public XMLElement tag(String tag) {
        return new W3Element(doc.createElement(tag));
    }

    @Override
    public XMLElement entity(String name) {
        return new W3Element(doc.createEntityReference(name));
    }

    @Override
    public XMLElement processing(String target, String value) {
        return new W3Element(doc.createProcessingInstruction(target, value));
    }

    @Override
    public XMLElement text(String value) {
        return new W3Element(doc.createTextNode(value));
    }

    @Override
    public int hashCode() {
        return doc.hashCode();
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (object instanceof XMLDocument) {
            return CompareUtils.equals(doc, ((XMLDocument)object).node());
        }
        return false;
    }

    
    
    
    
    
    
}
