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 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 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 logger.debug("Trying WebSphere 5.1+: " + FACTORY_CLASS_5_1_AND_ABOVE);
53 clazz = ClassUtils.loadClass(FACTORY_CLASS_5_1_AND_ABOVE, this.getClass());
54 logger.info("Found WebSphere 5.1+: " + FACTORY_CLASS_5_1_AND_ABOVE);
55 }
56 catch (ClassNotFoundException ex)
57 {
58 logger.debug("Could not find WebSphere 5.1+ TransactionManager factory class", ex);
59 try
60 {
61 logger.debug("Trying WebSphere 5.0: " + FACTORY_CLASS_5_0);
62 clazz = ClassUtils.loadClass(FACTORY_CLASS_5_0, this.getClass());
63 logger.info("Found WebSphere 5.0: " + FACTORY_CLASS_5_0);
64 }
65 catch (ClassNotFoundException ex2)
66 {
67 logger.debug("Could not find WebSphere 5.0 TransactionManager factory class", ex2);
68 try
69 {
70 logger.debug("Trying WebSphere 4: " + FACTORY_CLASS_4);
71 clazz = ClassUtils.loadClass(FACTORY_CLASS_4, this.getClass());
72 logger.info("Found WebSphere 4: " + FACTORY_CLASS_4);
73 }
74 catch (ClassNotFoundException ex3)
75 {
76 logger.debug("Could not find WebSphere 4 TransactionManager factory class", ex3);
77 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 }
82 }
83 }
84 try
85 {
86 Method method = clazz.getMethod("getTransactionManager", null);
87 transactionManager = (TransactionManager) method.invoke(null, null);
88 }
89 catch (Exception ex)
90 {
91 throw new RuntimeException("Found WebSphere TransactionManager factory class [" + clazz.getName()
92 + "], but couldn't invoke its static 'getTransactionManager' method",
93 ex);
94 }
95
96 return transactionManager;
97 }
98
99 }