1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.jms;
12
13 import org.mule.config.i18n.CoreMessages;
14 import org.mule.providers.jms.i18n.JmsMessages;
15 import org.mule.transaction.AbstractSingleResourceTransaction;
16 import org.mule.transaction.IllegalTransactionStateException;
17 import org.mule.umo.TransactionException;
18
19 import javax.jms.Connection;
20 import javax.jms.JMSException;
21 import javax.jms.Message;
22 import javax.jms.Session;
23
24
25
26
27
28
29
30 public class JmsClientAcknowledgeTransaction extends AbstractSingleResourceTransaction
31 {
32 private Message message;
33
34 public void setMessage(Message message)
35 {
36 this.message = message;
37 }
38
39
40
41
42
43
44 protected void doBegin() throws TransactionException
45 {
46
47 }
48
49
50
51
52
53
54 protected void doCommit() throws TransactionException
55 {
56 try
57 {
58 if (message == null)
59 {
60 throw new IllegalTransactionStateException(
61 JmsMessages.noMessageBoundForAck());
62 }
63 message.acknowledge();
64 }
65 catch (JMSException e)
66 {
67 throw new IllegalTransactionStateException(CoreMessages.transactionCommitFailed(), e);
68 }
69 }
70
71
72
73
74
75
76 protected void doRollback() throws TransactionException
77 {
78
79 if (message != null)
80 {
81 throw new UnsupportedOperationException("Jms Client Acknowledge doesn't support rollback");
82 }
83 }
84
85
86
87
88
89
90
91 public void bindResource(Object key, Object resource) throws TransactionException
92 {
93 if (key instanceof Message)
94 {
95 this.message = (Message)key;
96 return;
97 }
98 if (!(key instanceof Connection) || !(resource instanceof Session))
99 {
100 throw new IllegalTransactionStateException(
101 CoreMessages.transactionCanOnlyBindToResources("javax.jms.Connection/javax.jms.Session"));
102 }
103
104 Session session = (Session)resource;
105 try
106 {
107 if (session.getTransacted())
108 {
109 throw new IllegalTransactionStateException(JmsMessages.sessionShouldNotBeTransacted());
110 }
111 }
112 catch (JMSException e)
113 {
114 throw new IllegalTransactionStateException(CoreMessages.transactionCannotReadState(), e);
115 }
116
117 super.bindResource(key, resource);
118 }
119 }