001    package com.mockrunner.mock.jms;
002    
003    import javax.jms.Connection;
004    import javax.jms.JMSException;
005    
006    import com.mockrunner.jms.ConfigurationManager;
007    import com.mockrunner.jms.DestinationManager;
008    
009    /**
010     * Mock implementation of JMS <code>QueueConnectionFactory</code>.
011     */
012    public class MockQueueConnectionFactory extends MockConnectionFactory
013    {
014        public MockQueueConnectionFactory(DestinationManager destinationManager, ConfigurationManager configurationManager)
015        {
016            super(destinationManager, configurationManager);
017        }
018        
019        public Connection createConnection() throws JMSException
020        {
021            return createQueueConnection();
022        }
023    
024        public Connection createConnection(String name, String password) throws JMSException
025        {
026            return createQueueConnection(name, password);
027        }
028        
029        /**
030         * Returns the connection with the specified index
031         * or <code>null</code> if no such connection
032         * exists.
033         * @param index the index
034         * @return the connection
035         */
036        public MockQueueConnection getQueueConnection(int index)
037        {
038            if(connections().size() <= index) return null;
039            return (MockQueueConnection)connections().get(index);
040        }
041        
042        /**
043         * Returns the latest created connection
044         * or <code>null</code> if no such connection
045         * exists.
046         * @return the connection
047         */
048        public MockQueueConnection getLatestQueueConnection()
049        {
050            if(connections().size() == 0) return null;
051            return (MockQueueConnection)connections().get(connections().size() - 1);
052        }
053    }