// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package jcademo.raoutbound.multcp;

import javax.naming.NamingException;
import javax.naming.Reference;
import javax.resource.ResourceException;
import javax.resource.cci.ConnectionSpec;
import javax.resource.cci.RecordFactory;
import javax.resource.cci.ResourceAdapterMetaData;
import javax.resource.spi.ConnectionManager;

public class TestConnectionFactoryImpl implements TestConnectionFactory {
	private static final long serialVersionUID = 1L;
	private MulTCPManagedConnectionFactory mcf;
	private ConnectionManager cm;
	// instantiate
	public TestConnectionFactoryImpl() {
		this(null, null);
	}
	public TestConnectionFactoryImpl(MulTCPManagedConnectionFactory mcf, ConnectionManager cm) {
		this.mcf = mcf;
		this.cm = cm;
	}
	// get connection from connection manager
	@Override
	public TestConnection getConnection() throws ResourceException {
		return (TestConnection)cm.allocateConnection(mcf, null);
	}
	@Override
	public TestConnection getConnection(ConnectionSpec cs) throws ResourceException {
		return (TestConnection)cm.allocateConnection(mcf, null);
	}
	// CCI support
	@Override
	public RecordFactory getRecordFactory() throws ResourceException {
		throw new ResourceException("CCI not supported");
	}
	// reference
	private Reference ref;
	@Override
	public Reference getReference() throws NamingException {
		return ref;
	}
	@Override
	public void setReference(Reference ref) {
		this.ref = ref;
	}
	// meta data support
	@Override
	public ResourceAdapterMetaData getMetaData() throws ResourceException {
		throw new ResourceException("Meta data not supported");
	}
}
