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