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