1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.jms; |
12 | |
|
13 | |
import javax.jms.Connection; |
14 | |
import javax.jms.ConnectionFactory; |
15 | |
import javax.jms.DeliveryMode; |
16 | |
import javax.jms.Destination; |
17 | |
import javax.jms.JMSException; |
18 | |
import javax.jms.Message; |
19 | |
import javax.jms.MessageConsumer; |
20 | |
import javax.jms.MessageProducer; |
21 | |
import javax.jms.Queue; |
22 | |
import javax.jms.QueueConnection; |
23 | |
import javax.jms.QueueConnectionFactory; |
24 | |
import javax.jms.QueueSender; |
25 | |
import javax.jms.QueueSession; |
26 | |
import javax.jms.Session; |
27 | |
import javax.jms.Topic; |
28 | |
import javax.jms.TopicConnection; |
29 | |
import javax.jms.TopicConnectionFactory; |
30 | |
import javax.jms.TopicPublisher; |
31 | |
import javax.jms.TopicSession; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public class Jms102bSupport extends Jms11Support |
40 | |
{ |
41 | |
public Jms102bSupport(JmsConnector connector) |
42 | |
{ |
43 | 126 | super(connector); |
44 | 126 | } |
45 | |
|
46 | |
public Connection createConnection(ConnectionFactory connectionFactory, String username, String password) |
47 | |
throws JMSException |
48 | |
{ |
49 | 0 | if (connectionFactory == null) |
50 | |
{ |
51 | 0 | throw new IllegalArgumentException("connectionFactory cannot be null"); |
52 | |
} |
53 | 0 | if (connectionFactory instanceof QueueConnectionFactory) |
54 | |
{ |
55 | 0 | return ((QueueConnectionFactory) connectionFactory).createQueueConnection(username, password); |
56 | |
} |
57 | 0 | else if (connectionFactory instanceof TopicConnectionFactory) |
58 | |
{ |
59 | 0 | return ((TopicConnectionFactory) connectionFactory).createTopicConnection(username, password); |
60 | |
} |
61 | |
else |
62 | |
{ |
63 | 0 | throw new IllegalArgumentException("Unsupported ConnectionFactory type: " |
64 | |
+ connectionFactory.getClass().getName()); |
65 | |
} |
66 | |
} |
67 | |
|
68 | |
public Connection createConnection(ConnectionFactory connectionFactory) throws JMSException |
69 | |
{ |
70 | 126 | if (connectionFactory == null) |
71 | |
{ |
72 | 0 | throw new IllegalArgumentException("connectionFactory cannot be null"); |
73 | |
} |
74 | 126 | if (connectionFactory instanceof QueueConnectionFactory) |
75 | |
{ |
76 | 126 | return ((QueueConnectionFactory) connectionFactory).createQueueConnection(); |
77 | |
} |
78 | 0 | else if (connectionFactory instanceof TopicConnectionFactory) |
79 | |
{ |
80 | 0 | return ((TopicConnectionFactory) connectionFactory).createTopicConnection(); |
81 | |
} |
82 | |
else |
83 | |
{ |
84 | 0 | throw new IllegalArgumentException("Unsupported ConnectionFactory type: " |
85 | |
+ connectionFactory.getClass().getName()); |
86 | |
} |
87 | |
} |
88 | |
|
89 | |
public Session createSession(Connection connection, boolean topic, boolean transacted, int ackMode, boolean noLocal) |
90 | |
throws JMSException |
91 | |
{ |
92 | 530 | if (topic && connection instanceof TopicConnection) |
93 | |
{ |
94 | 14 | return ((TopicConnection) connection).createTopicSession(noLocal, ackMode); |
95 | |
} |
96 | 516 | else if (connection instanceof QueueConnection) |
97 | |
{ |
98 | |
|
99 | |
|
100 | |
|
101 | 516 | return ((QueueConnection) connection).createQueueSession( |
102 | |
transacted, (transacted ? Session.SESSION_TRANSACTED : ackMode)); |
103 | |
} |
104 | |
else |
105 | |
{ |
106 | 0 | throw new IllegalArgumentException("Connection and domain type do not match"); |
107 | |
} |
108 | |
} |
109 | |
|
110 | |
public MessageConsumer createConsumer(Session session, |
111 | |
Destination destination, |
112 | |
String messageSelector, |
113 | |
boolean noLocal, |
114 | |
String durableName, |
115 | |
boolean topic) throws JMSException |
116 | |
{ |
117 | 302 | if (topic && session instanceof TopicSession) |
118 | |
{ |
119 | 8 | if (durableName == null) |
120 | |
{ |
121 | 8 | return ((TopicSession) session).createSubscriber((Topic) destination, messageSelector, noLocal); |
122 | |
} |
123 | |
else |
124 | |
{ |
125 | |
|
126 | 0 | return ((TopicSession) session).createDurableSubscriber((Topic) destination, durableName, messageSelector, noLocal); |
127 | |
} |
128 | |
} |
129 | 294 | else if (session instanceof QueueSession) |
130 | |
{ |
131 | 294 | if (messageSelector != null) |
132 | |
{ |
133 | 0 | return ((QueueSession) session).createReceiver((Queue) destination, messageSelector); |
134 | |
} |
135 | |
else |
136 | |
{ |
137 | 294 | return ((QueueSession) session).createReceiver((Queue) destination); |
138 | |
} |
139 | |
} |
140 | |
else |
141 | |
{ |
142 | 0 | throw new IllegalArgumentException("MuleSession and domain type do not match"); |
143 | |
} |
144 | |
} |
145 | |
|
146 | |
public MessageProducer createProducer(Session session, Destination dest, boolean topic) throws JMSException |
147 | |
{ |
148 | 124 | if (topic && session instanceof TopicSession) |
149 | |
{ |
150 | 6 | return ((TopicSession) session).createPublisher((Topic) dest); |
151 | |
} |
152 | 118 | else if (session instanceof QueueSession) |
153 | |
{ |
154 | 118 | return ((QueueSession) session).createSender((Queue) dest); |
155 | |
} |
156 | |
else |
157 | |
{ |
158 | 0 | throw new IllegalArgumentException("MuleSession and domain type do not match"); |
159 | |
} |
160 | |
} |
161 | |
|
162 | |
public Destination createDestination(Session session, String name, boolean topic) throws JMSException |
163 | |
{ |
164 | 422 | if (session == null) |
165 | |
{ |
166 | 0 | throw new IllegalArgumentException("MuleSession cannot be null when creating a destination"); |
167 | |
} |
168 | 422 | if (name == null) |
169 | |
{ |
170 | 0 | throw new IllegalArgumentException("Destination name cannot be null when creating a destination"); |
171 | |
} |
172 | |
|
173 | 422 | if (topic) |
174 | |
{ |
175 | |
|
176 | 14 | return ((TopicSession) session).createTopic(name); |
177 | |
} |
178 | |
else |
179 | |
{ |
180 | |
|
181 | 408 | return ((QueueSession) session).createQueue(name); |
182 | |
} |
183 | |
} |
184 | |
|
185 | |
public Destination createTemporaryDestination(Session session, boolean topic) throws JMSException |
186 | |
{ |
187 | 2 | if (session == null) |
188 | |
{ |
189 | 0 | throw new IllegalArgumentException("MuleSession cannot be null when creating a destination"); |
190 | |
} |
191 | |
|
192 | 2 | if (topic) |
193 | |
{ |
194 | |
|
195 | 0 | return ((TopicSession) session).createTemporaryTopic(); |
196 | |
} |
197 | |
else |
198 | |
{ |
199 | |
|
200 | 2 | return ((QueueSession) session).createTemporaryQueue(); |
201 | |
} |
202 | |
} |
203 | |
|
204 | |
public void send(MessageProducer producer, Message message, boolean persistent, int priority, long ttl, boolean topic) |
205 | |
throws JMSException |
206 | |
{ |
207 | 123 | if (topic && producer instanceof TopicPublisher) |
208 | |
{ |
209 | 6 | ((TopicPublisher) producer).publish( |
210 | |
message, |
211 | |
(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT), |
212 | |
priority, |
213 | |
ttl); |
214 | |
} |
215 | 118 | else if (producer instanceof QueueSender) |
216 | |
{ |
217 | |
|
218 | 118 | ((QueueSender) producer).send( |
219 | |
message, |
220 | |
(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT), |
221 | |
priority, |
222 | |
ttl); |
223 | |
} |
224 | |
else |
225 | |
{ |
226 | 0 | throw new IllegalArgumentException("Producer and domain type do not match"); |
227 | |
} |
228 | 124 | } |
229 | |
|
230 | |
public void send(MessageProducer producer, |
231 | |
Message message, |
232 | |
Destination dest, |
233 | |
boolean persistent, |
234 | |
int priority, |
235 | |
long ttl, |
236 | |
boolean topic) throws JMSException |
237 | |
{ |
238 | 0 | if (topic && producer instanceof TopicPublisher) |
239 | |
{ |
240 | 0 | ((TopicPublisher) producer).publish( |
241 | |
(Topic) dest, |
242 | |
message, |
243 | |
(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT), |
244 | |
priority, |
245 | |
ttl); |
246 | |
} |
247 | 0 | else if (producer instanceof QueueSender) |
248 | |
{ |
249 | 0 | ((QueueSender) producer).send( |
250 | |
(Queue) dest, |
251 | |
message, |
252 | |
(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT), |
253 | |
priority, |
254 | |
ttl); |
255 | |
} |
256 | |
else |
257 | |
{ |
258 | 0 | throw new IllegalArgumentException("Producer and domain type do not match"); |
259 | |
} |
260 | 0 | } |
261 | |
} |