// JDBCDOMParser.java
package dbxml.dom;

import java.io.IOException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import com.sun.xml.tree.XmlDocumentBuilder;

import dbxml.sax.*;

/**
 * DOM parser that works with a JDBC data source.
 * @author Ramnivas Laddad
 */
public class JDBCDOMParser {
    /**
     * Creates a DOM tree from given JDBC data source
     * The implementation uses XmlDocumentBuilder from Sun's Project X. 
     * An XmlDocumentBuilder is configured with a JDBCSAXParser to get 
     * the DOM tree.
     *
     * @param inputSource a JDBC data source
     * @return a DOM docuemnt corresponding to the given JDBC data source
     * @exception SAXException exception thrown while parsing the input
     * @exception IOException exception thrown while parsing the input
     */
    public static Document createDocument(JDBCInputSource inputSource) 
	throws SAXException, IOException {
	XmlDocumentBuilder documentBuilder = new XmlDocumentBuilder();
	JDBCSAXParser saxParser = new JDBCSAXParser();

	documentBuilder.setParser(saxParser);
	saxParser.parse(inputSource);
	return documentBuilder.getDocument();
    }
}