/*-----------------------------------------------------------------------------
 *
 * Enhydra InstantDB
 * The Initial Developer of the Original Code is Lutris Technologies Inc.
 * Portions created by Lutris are Copyright 1997-2000 Lutris Technologies Inc.
 * All Rights Reserved.
 *
 * The contents of this file are subject to the Enhydra Public License
 * Version 1.1 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 * www.enhydra.org/license/epl.html
 *
 * Software distributed under the License is distributed on an "ASIS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * -----------------------------------------------------------------------------
 * $Id$
 * -----------------------------------------------------------------------------
 */
package org.enhydra.jdbc.oracle;

import java.sql.SQLException;
import java.util.Hashtable;
import javax.sql.*;
import javax.naming.*;
import javax.naming.spi.*;
import org.enhydra.jdbc.standard.*;

/**
 * Data source for creating IdbXAConnections.
 */
public class OracleXADataSource extends StandardXADataSource implements XADataSource {

	/**
	 * Constructor.
	 */
	public OracleXADataSource () {
		// Required by JNDI
		super();
	} // Constructor

	/**
	 * Creates an XA connection using the default username and password.
	 */
	public XAConnection getXAConnection () throws SQLException {
		return getXAConnection (user, password);
	} // method getXAConnection

	/**
	 * Creates an XA connection using the supplied username and password.
	 */
	public XAConnection getXAConnection (String user, String password) throws SQLException {
		OracleXAConnection xac = new OracleXAConnection (this, user, password);
		xac.setTransactionManager(transactionManager);
		connectionCount++;
		return xac;
	} // method getXAConnection

	/**
	 * The factory interface.
	 */
	public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env) throws Exception {
		Reference ref = (Reference)refObj;
		if (ref.getClassName().equals(getClass().getName())) {
			OracleXADataSource dataSource = new OracleXADataSource ();
			dataSource.setDriverName((String)ref.get("driverName").getContent());
			dataSource.setUrl((String)ref.get("url").getContent());
			return dataSource;
		} else {
			return null;
		}
	} // getObjectInstance

} // class IdbXADataSource 
