001    package com.mockrunner.mock.jms;
002    
003    import java.util.List;
004    
005    import javax.jms.ConnectionConsumer;
006    import javax.jms.JMSException;
007    import javax.jms.ServerSessionPool;
008    import javax.jms.Session;
009    import javax.jms.Topic;
010    import javax.jms.TopicConnection;
011    import javax.jms.TopicSession;
012    
013    import com.mockrunner.jms.ConfigurationManager;
014    import com.mockrunner.jms.DestinationManager;
015    
016    /**
017     * Mock implementation of JMS <code>TopicConnection</code>.
018     * Please note: The interfaces <code>ConnectionConsumer</code>,
019     * <code>ServerSessionPool</code> and <code>ServerSession</code>
020     * are not meant for application use. Mockrunner provides very
021     * simple mock implementations but usually you won't need them.
022     */
023    public class MockTopicConnection extends MockConnection implements TopicConnection
024    {
025        public MockTopicConnection(DestinationManager destinationManager, ConfigurationManager configurationManager)
026        {
027            super(destinationManager, configurationManager);
028        }
029        
030        /**
031         * Returns the list of {@link MockTopicSession} objects that were created 
032         * with {@link #createTopicSession}.
033         * @return the list
034         */
035        public List getTopicSessionList()
036        {
037            return super.getSessionList();
038        }
039    
040        /**
041         * Returns a {@link MockTopicSession} that was created with
042         * {@link #createTopicSession}. If there's no such
043         * {@link MockTopicSession}, <code>null</code> is returned.
044         * @param index the index of the session object
045         * @return the session object
046         */
047        public MockTopicSession getTopicSession(int index)
048        {
049            return (MockTopicSession)super.getSession(index);
050        }
051        
052        public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException
053        {
054            return createTopicSession(transacted, acknowledgeMode);
055        }
056    
057        public TopicSession createTopicSession(boolean transacted, int acknowledgeMode) throws JMSException
058        {
059            throwJMSException();
060            MockTopicSession session = new MockTopicSession(this, transacted, acknowledgeMode);
061            sessions().add(session);
062            return session;
063        }
064    
065        public ConnectionConsumer createConnectionConsumer(Topic topic, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
066        {
067            return super.createConnectionConsumer(topic, messageSelector, sessionPool, maxMessages);
068        }
069    }