1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.jms.xa; |
12 | |
|
13 | |
import java.lang.reflect.Proxy; |
14 | |
|
15 | |
import javax.jms.Connection; |
16 | |
import javax.jms.ConnectionFactory; |
17 | |
import javax.jms.JMSException; |
18 | |
import javax.jms.QueueConnection; |
19 | |
import javax.jms.QueueConnectionFactory; |
20 | |
import javax.jms.TopicConnection; |
21 | |
import javax.jms.TopicConnectionFactory; |
22 | |
import javax.jms.XAConnection; |
23 | |
import javax.jms.XAConnectionFactory; |
24 | |
import javax.jms.XAQueueConnection; |
25 | |
import javax.jms.XAQueueConnectionFactory; |
26 | |
import javax.jms.XATopicConnection; |
27 | |
import javax.jms.XATopicConnectionFactory; |
28 | |
|
29 | |
import org.apache.commons.logging.Log; |
30 | |
import org.apache.commons.logging.LogFactory; |
31 | |
|
32 | |
public class ConnectionFactoryWrapper |
33 | |
implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory |
34 | |
{ |
35 | |
|
36 | |
|
37 | |
|
38 | 0 | protected static final transient Log logger = LogFactory.getLog(ConnectionFactoryWrapper.class); |
39 | |
|
40 | |
protected final Object factory; |
41 | |
private Boolean sameRMOverrideValue; |
42 | |
|
43 | |
public ConnectionFactoryWrapper(Object factory) |
44 | |
{ |
45 | 0 | this(factory, null); |
46 | 0 | } |
47 | |
|
48 | |
public ConnectionFactoryWrapper(Object factory, Boolean sameRMOverrideValue) |
49 | 0 | { |
50 | 0 | this.factory = factory; |
51 | 0 | this.sameRMOverrideValue = sameRMOverrideValue; |
52 | 0 | } |
53 | |
|
54 | |
public Connection createConnection() throws JMSException |
55 | |
{ |
56 | 0 | XAConnection xac = ((XAConnectionFactory) factory).createXAConnection(); |
57 | 0 | Connection proxy = (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(), |
58 | |
new Class[]{Connection.class}, |
59 | |
new ConnectionInvocationHandler(xac, sameRMOverrideValue)); |
60 | 0 | return proxy; |
61 | |
} |
62 | |
|
63 | |
public Connection createConnection(String username, String password) throws JMSException |
64 | |
{ |
65 | 0 | XAConnection xac = ((XAConnectionFactory) factory).createXAConnection(username, password); |
66 | 0 | Connection proxy = (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(), |
67 | |
new Class[]{Connection.class}, |
68 | |
new ConnectionInvocationHandler(xac, sameRMOverrideValue)); |
69 | 0 | return proxy; |
70 | |
} |
71 | |
|
72 | |
public QueueConnection createQueueConnection() throws JMSException |
73 | |
{ |
74 | 0 | XAQueueConnection xaqc = ((XAQueueConnectionFactory) factory).createXAQueueConnection(); |
75 | 0 | QueueConnection proxy = (QueueConnection) Proxy.newProxyInstance(Connection.class.getClassLoader(), |
76 | |
new Class[]{QueueConnection.class}, |
77 | |
new ConnectionInvocationHandler(xaqc, sameRMOverrideValue)); |
78 | 0 | return proxy; |
79 | |
} |
80 | |
|
81 | |
public QueueConnection createQueueConnection(String username, String password) throws JMSException |
82 | |
{ |
83 | 0 | XAQueueConnection xaqc = ((XAQueueConnectionFactory) factory).createXAQueueConnection(username, |
84 | |
password); |
85 | 0 | QueueConnection proxy = (QueueConnection) Proxy.newProxyInstance(Connection.class.getClassLoader(), |
86 | |
new Class[]{QueueConnection.class}, |
87 | |
new ConnectionInvocationHandler(xaqc, sameRMOverrideValue)); |
88 | 0 | return proxy; |
89 | |
} |
90 | |
|
91 | |
public TopicConnection createTopicConnection() throws JMSException |
92 | |
{ |
93 | 0 | XATopicConnection xatc = ((XATopicConnectionFactory) factory).createXATopicConnection(); |
94 | 0 | TopicConnection proxy = (TopicConnection) Proxy.newProxyInstance(Connection.class.getClassLoader(), |
95 | |
new Class[]{TopicConnection.class}, |
96 | |
new ConnectionInvocationHandler(xatc, sameRMOverrideValue)); |
97 | 0 | return proxy; |
98 | |
} |
99 | |
|
100 | |
public TopicConnection createTopicConnection(String username, String password) throws JMSException |
101 | |
{ |
102 | 0 | XATopicConnection xatc = ((XATopicConnectionFactory) factory).createXATopicConnection(username, |
103 | |
password); |
104 | 0 | TopicConnection proxy = (TopicConnection) Proxy.newProxyInstance(Connection.class.getClassLoader(), |
105 | |
new Class[]{TopicConnection.class}, |
106 | |
new ConnectionInvocationHandler(xatc, sameRMOverrideValue)); |
107 | 0 | return proxy; |
108 | |
} |
109 | |
|
110 | |
} |