001: package org.mockejb.jms;
002:
003: import javax.jms.*;
004: import org.mockejb.MethodNotImplementedException;
005:
006: /**
007: * <code>QueueSession</code> implementation.
008: * Supports only queues, which are instances of <code>MockQueue</code>.
009: * @author Dimitar Gospodinov
010: * @see javax.jms.QueueSession
011: */
012: class QueueSessionImpl extends MockSession implements QueueSession {
013:
014: /**
015: * Creates queue session with the specified attributes, for connection <code>connection</code>
016: * @param transacted
017: * @param acknowledgeMode
018: * @param connection
019: */
020: QueueSessionImpl(boolean transacted, int acknowledgeMode,
021: MockConnection connection) {
022:
023: super (transacted, acknowledgeMode, connection);
024: }
025:
026: /**
027: * Not implemented.
028: * @see javax.jms.QueueSession#createQueue(java.lang.String)
029: */
030: public Queue createQueue(String queueName) throws JMSException {
031: throw new MethodNotImplementedException("createQueue",
032: "QueueSessionImpl");
033: }
034:
035: /**
036: * Not implemented.
037: * @see javax.jms.QueueSession#createReceiver(javax.jms.Queue)
038: */
039: public QueueReceiver createReceiver(Queue queue)
040: throws JMSException {
041: checkClosed();
042: return (QueueReceiver) createConsumer(queue);
043: }
044:
045: /**
046: * Not implemented.
047: * @see javax.jms.QueueSession#createReceiver(javax.jms.Queue, java.lang.String)
048: */
049: public QueueReceiver createReceiver(Queue queue,
050: String messageSelector) throws JMSException {
051:
052: throw new MethodNotImplementedException("createReceiver",
053: "QueueSessionImpl");
054: }
055:
056: /**
057: * @see javax.jms.QueueSession#createSender(javax.jms.Queue)
058: */
059: public QueueSender createSender(Queue queue) throws JMSException {
060: checkClosed();
061: return (QueueSender) createProducer(queue);
062: }
063:
064: /**
065: * @see javax.jms.QueueSession#createBrowser(javax.jms.Queue)
066: */
067: public QueueBrowser createBrowser(Queue queue) throws JMSException {
068:
069: checkClosed();
070:
071: if (queue instanceof MockQueue) {
072: return new QueueBrowserImpl((MockQueue) queue);
073: }
074: throw new javax.jms.InvalidDestinationException(
075: "Invalid queue specified!");
076: }
077:
078: /**
079: * Not implemented
080: */
081: public QueueBrowser createBrowser(Queue queue,
082: String messageSelector) throws JMSException {
083:
084: throw new MethodNotImplementedException("createBrowser",
085: "QueueSession");
086: }
087:
088: /**
089: * Not implemented.
090: * @see javax.jms.QueueSession#createTemporaryQueue()
091: */
092: public TemporaryQueue createTemporaryQueue() throws JMSException {
093:
094: throw new MethodNotImplementedException("createTemporaryQueue",
095: "QueueSession");
096: }
097:
098: /**
099: * Throws <code>IllegalStateException</code>
100: */
101: public Topic createTopic(String topicName) throws JMSException {
102: throw new javax.jms.IllegalStateException(
103: "Queue session can not create topic!");
104: }
105:
106: /**
107: * Throws <code>IllegalStateException</code>
108: */
109: public TopicSubscriber createDurableSubscriber(Topic topic,
110: String name) throws JMSException {
111:
112: throw new javax.jms.IllegalStateException(
113: "Queue session can not create subscriber!");
114: }
115:
116: /**
117: * Throws <code>IllegalStateException</code>
118: */
119: public TopicSubscriber createDurableSubscriber(Topic topic,
120: String name, String messageSelector, boolean noLocal)
121: throws JMSException {
122:
123: throw new javax.jms.IllegalStateException(
124: "Queue session can not create subscriber!");
125: }
126:
127: /**
128: * Throws <code>IllegalStateException</code>
129: */
130: public TemporaryTopic createTemporaryTopic() throws JMSException {
131: throw new javax.jms.IllegalStateException(
132: "Queue session can not create temporary topic!");
133: }
134:
135: /**
136: * Throws <code>IllegalStateException</code>
137: */
138: public void unsubscribe(String name) throws JMSException {
139: throw new javax.jms.IllegalStateException(
140: "Queue session can not \"unsubscribe\"!");
141: }
142:
143: // Non-standard methods
144:
145: MockConsumer createMockConsumer(MockDestination destination)
146: throws JMSException {
147: if (destination instanceof MockQueue) {
148: return new QueueReceiverImpl(this , (MockQueue) destination);
149: }
150: throw new InvalidDestinationException(
151: "Invalid queue specified!");
152: }
153:
154: MockProducer createMockProducer(MockDestination destination)
155: throws JMSException {
156: if (destination instanceof MockQueue) {
157: return new QueueSenderImpl((MockQueue) destination);
158: }
159: throw new InvalidDestinationException(
160: "Invalid queue specified!");
161: }
162:
163: }
|