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