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