001    package com.mockrunner.mock.connector.cci;
002    
003    import javax.naming.NamingException;
004    import javax.naming.Reference;
005    import javax.resource.ResourceException;
006    import javax.resource.cci.Connection;
007    import javax.resource.cci.ConnectionFactory;
008    import javax.resource.cci.ConnectionSpec;
009    import javax.resource.cci.RecordFactory;
010    import javax.resource.cci.ResourceAdapterMetaData;
011    
012    /**
013     * Mock implementation of <code>ConnectionFactory</code>
014     */
015    public class MockConnectionFactory implements ConnectionFactory
016    {
017        private Connection connection;
018        private RecordFactory recordFactory;
019        private ResourceAdapterMetaData metaData;
020        private Reference reference;
021    
022        public MockConnectionFactory()
023        {
024            metaData = new MockResourceAdapterMetaData();
025            recordFactory  = new MockRecordFactory();
026        }
027    
028        public void setConnection(Connection connection)
029        {
030            this.connection = connection;
031        }
032    
033        public Connection getConnection() throws ResourceException
034        {
035            return connection;
036        }
037    
038        public MockConnection getMockConnection()
039        {
040            if(connection instanceof MockConnection)
041            {
042                return (MockConnection)connection;
043            }
044            return null;
045        }
046    
047        public Connection getConnection(ConnectionSpec cs) throws ResourceException
048        {
049            return connection;
050        }
051    
052        public RecordFactory getRecordFactory() throws ResourceException
053        {
054            return recordFactory;
055        }
056    
057        public ResourceAdapterMetaData getMetaData() throws ResourceException
058        {
059            return metaData;
060        }
061    
062        public void setReference(Reference reference)
063        {
064            this.reference = reference;
065        }
066    
067        public Reference getReference() throws NamingException
068        {
069            return reference;
070        }
071        
072        /**
073         * Sets the resource adapter meta data. If you do not set an explicit
074         * <code>ResourceAdapterMetaData</code> object, a default {@link MockResourceAdapterMetaData} 
075         * will be created.
076         * @param metaData the <code>ResourceAdapterMetaData</code>
077         */
078        public void setMetaData(ResourceAdapterMetaData metaData)
079        {
080            this.metaData = metaData;
081        }
082        
083        /**
084         * Sets the record factory. If you do not set an explicit
085         * <code>RecordFactory</code>, a default {@link MockRecordFactory} 
086         * will be created.
087         * @param recordFactory the <code>RecordFactory</code>
088         */
089        public void setRecordFactory(RecordFactory recordFactory)
090        {
091            this.recordFactory = recordFactory;
092        }
093    }