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