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