1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transaction.lookup; |
12 | |
|
13 | |
import org.mule.umo.manager.UMOTransactionManagerFactory; |
14 | |
import org.mule.util.ClassUtils; |
15 | |
|
16 | |
import java.lang.reflect.Method; |
17 | |
|
18 | |
import javax.transaction.TransactionManager; |
19 | |
|
20 | |
import org.apache.commons.logging.Log; |
21 | |
import org.apache.commons.logging.LogFactory; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public class WebsphereTransactionManagerLookupFactory implements UMOTransactionManagerFactory |
33 | |
{ |
34 | |
private static final String FACTORY_CLASS_5_1_AND_ABOVE = "com.ibm.ws.Transaction.TransactionManagerFactory"; |
35 | |
|
36 | |
private static final String FACTORY_CLASS_5_0 = "com.ibm.ejs.jts.jta.TransactionManagerFactory"; |
37 | |
|
38 | |
private static final String FACTORY_CLASS_4 = "com.ibm.ejs.jts.jta.JTSXA"; |
39 | |
|
40 | 0 | private final Log logger = LogFactory.getLog(getClass()); |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public TransactionManager create() |
47 | |
{ |
48 | |
Class clazz; |
49 | |
TransactionManager transactionManager; |
50 | |
try |
51 | |
{ |
52 | 0 | logger.debug("Trying WebSphere 5.1+: " + FACTORY_CLASS_5_1_AND_ABOVE); |
53 | 0 | clazz = ClassUtils.loadClass(FACTORY_CLASS_5_1_AND_ABOVE, this.getClass()); |
54 | 0 | logger.info("Found WebSphere 5.1+: " + FACTORY_CLASS_5_1_AND_ABOVE); |
55 | |
} |
56 | 0 | catch (ClassNotFoundException ex) |
57 | |
{ |
58 | 0 | logger.debug("Could not find WebSphere 5.1+ TransactionManager factory class", ex); |
59 | |
try |
60 | |
{ |
61 | 0 | logger.debug("Trying WebSphere 5.0: " + FACTORY_CLASS_5_0); |
62 | 0 | clazz = ClassUtils.loadClass(FACTORY_CLASS_5_0, this.getClass()); |
63 | 0 | logger.info("Found WebSphere 5.0: " + FACTORY_CLASS_5_0); |
64 | |
} |
65 | 0 | catch (ClassNotFoundException ex2) |
66 | |
{ |
67 | 0 | logger.debug("Could not find WebSphere 5.0 TransactionManager factory class", ex2); |
68 | |
try |
69 | |
{ |
70 | 0 | logger.debug("Trying WebSphere 4: " + FACTORY_CLASS_4); |
71 | 0 | clazz = ClassUtils.loadClass(FACTORY_CLASS_4, this.getClass()); |
72 | 0 | logger.info("Found WebSphere 4: " + FACTORY_CLASS_4); |
73 | |
} |
74 | 0 | catch (ClassNotFoundException ex3) |
75 | |
{ |
76 | 0 | logger.debug("Could not find WebSphere 4 TransactionManager factory class", ex3); |
77 | 0 | throw new RuntimeException( |
78 | |
"Couldn't find any WebSphere TransactionManager factory class, " |
79 | |
+ "neither for WebSphere version 5.1 nor 5.0 nor 4", |
80 | |
ex); |
81 | 0 | } |
82 | 0 | } |
83 | 0 | } |
84 | |
try |
85 | |
{ |
86 | 0 | Method method = clazz.getMethod("getTransactionManager", null); |
87 | 0 | transactionManager = (TransactionManager) method.invoke(null, null); |
88 | |
} |
89 | 0 | catch (Exception ex) |
90 | |
{ |
91 | 0 | throw new RuntimeException("Found WebSphere TransactionManager factory class [" + clazz.getName() |
92 | |
+ "], but couldn't invoke its static 'getTransactionManager' method", |
93 | |
ex); |
94 | 0 | } |
95 | |
|
96 | 0 | return transactionManager; |
97 | |
} |
98 | |
|
99 | |
} |