// JDBCInputSource.java
package dbxml.sax;

import java.sql.*;

import org.xml.sax.InputSource;

/**
 * JDBC data source to work with SAX parser and applications.
 * This class specializes org.xml.sax.InputSource
 * to encapsulate the requried information to access a table
 * in a database.
 *
 * @author Ramnivas Laddad
 */
public class JDBCInputSource extends InputSource {
    private String _connectionURL;
    private String _userName;
    private String _passwd;
    private String _tableName;

    /**
     * Construct a JDBC data source
     *
     * @param connectionURL a JDBC URL of a database
     * @param userName user name for connecting to the database
     * @param passwd password for connecting to the database
     * @param tableName table name to be accessed from SAX parser/applications.
     */
    public JDBCInputSource(String connectionURL, String userName, 
			   String passwd, String tableName) {
	super(connectionURL);
	_connectionURL = connectionURL;
	_userName = userName;
	_passwd = passwd;
	_tableName = tableName;
    }

    /**
     * Get the table name of this JDBC data source.
     *
     * @return table name
     */
    public String getTableName() {
	return _tableName;
    }

    /**
     * Get a Connection object for this source.
     * Obtains and returns connection to the URL given in constructor
     * and returns it.
     *
     * @return a connectrion to the given JDBC URL
     * @exception SQLException exception that occured while getting connection
     *                         from DriverManager
     */
    public Connection getConnection() throws SQLException {
	return DriverManager.getConnection(_connectionURL, _userName, _passwd);
    }
}