1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.providers.jms.xa; |
11 | |
|
12 | |
import org.mule.transaction.XaTransaction; |
13 | |
|
14 | |
import java.lang.reflect.InvocationHandler; |
15 | |
import java.lang.reflect.Method; |
16 | |
import java.lang.reflect.Proxy; |
17 | |
|
18 | |
import javax.jms.QueueSession; |
19 | |
import javax.jms.Session; |
20 | |
import javax.jms.TopicSession; |
21 | |
import javax.jms.XAConnection; |
22 | |
import javax.jms.XAQueueConnection; |
23 | |
import javax.jms.XAQueueSession; |
24 | |
import javax.jms.XASession; |
25 | |
import javax.jms.XATopicConnection; |
26 | |
import javax.jms.XATopicSession; |
27 | |
|
28 | |
public class ConnectionInvocationHandler implements InvocationHandler |
29 | |
{ |
30 | |
|
31 | |
private Object xaConnection; |
32 | |
|
33 | |
public ConnectionInvocationHandler(Object xac) |
34 | 12 | { |
35 | 12 | this.xaConnection = xac; |
36 | 12 | } |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public Object getTargetObject() |
45 | |
{ |
46 | 12 | return xaConnection; |
47 | |
} |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable |
56 | |
{ |
57 | 184 | if (ConnectionFactoryWrapper.logger.isDebugEnabled()) |
58 | |
{ |
59 | 0 | ConnectionFactoryWrapper.logger.debug("Invoking " + method); |
60 | |
} |
61 | 184 | if (method.getName().equals("createSession")) |
62 | |
{ |
63 | 24 | XASession xas = ((XAConnection) xaConnection).createXASession(); |
64 | 34 | return Proxy.newProxyInstance(Session.class.getClassLoader(), new Class[]{Session.class, XaTransaction.MuleXaObject.class}, |
65 | |
new SessionInvocationHandler(xas)); |
66 | |
} |
67 | 160 | else if (method.getName().equals("createQueueSession")) |
68 | |
{ |
69 | 0 | XAQueueSession xaqs = ((XAQueueConnection) xaConnection).createXAQueueSession(); |
70 | 0 | return Proxy.newProxyInstance(Session.class.getClassLoader(), |
71 | |
new Class[]{QueueSession.class, XaTransaction.MuleXaObject.class}, new SessionInvocationHandler(xaqs)); |
72 | |
} |
73 | 160 | else if (method.getName().equals("createTopicSession")) |
74 | |
{ |
75 | 0 | XATopicSession xats = ((XATopicConnection) xaConnection).createXATopicSession(); |
76 | 0 | return Proxy.newProxyInstance(Session.class.getClassLoader(), |
77 | |
new Class[]{TopicSession.class, XaTransaction.MuleXaObject.class}, new SessionInvocationHandler(xats)); |
78 | |
} |
79 | |
else |
80 | |
{ |
81 | 160 | return method.invoke(xaConnection, args); |
82 | |
} |
83 | |
} |
84 | |
|
85 | |
} |