1 16 17 package org.springframework.transaction.jta; 18 19 import java.lang.reflect.InvocationTargetException ; 20 import java.lang.reflect.Method ; 21 22 import javax.transaction.TransactionManager ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 import org.springframework.beans.factory.FactoryBean; 28 import org.springframework.transaction.TransactionSystemException; 29 30 60 public class WebSphereTransactionManagerFactoryBean implements FactoryBean { 61 62 private static final String FACTORY_CLASS_5_1 = "com.ibm.ws.Transaction.TransactionManagerFactory"; 63 64 private static final String FACTORY_CLASS_5_0 = "com.ibm.ejs.jts.jta.TransactionManagerFactory"; 65 66 private static final String FACTORY_CLASS_4 = "com.ibm.ejs.jts.jta.JTSXA"; 67 68 69 protected final Log logger = LogFactory.getLog(getClass()); 70 71 private final TransactionManager transactionManager; 72 73 74 78 public WebSphereTransactionManagerFactoryBean() throws TransactionSystemException { 79 Class clazz; 80 try { 81 logger.debug("Trying WebSphere 5.1+: " + FACTORY_CLASS_5_1); 82 clazz = Class.forName(FACTORY_CLASS_5_1); 83 logger.info("Found WebSphere 5.1+: " + FACTORY_CLASS_5_1); 84 } 85 catch (ClassNotFoundException ex) { 86 logger.debug("Could not find WebSphere 5.1/6.0 TransactionManager factory class", ex); 87 try { 88 logger.debug("Trying WebSphere 5.0: " + FACTORY_CLASS_5_0); 89 clazz = Class.forName(FACTORY_CLASS_5_0); 90 logger.info("Found WebSphere 5.0: " + FACTORY_CLASS_5_0); 91 } 92 catch (ClassNotFoundException ex2) { 93 logger.debug("Could not find WebSphere 5.0 TransactionManager factory class", ex2); 94 try { 95 logger.debug("Trying WebSphere 4: " + FACTORY_CLASS_4); 96 clazz = Class.forName(FACTORY_CLASS_4); 97 logger.info("Found WebSphere 4: " + FACTORY_CLASS_4); 98 } 99 catch (ClassNotFoundException ex3) { 100 logger.debug("Could not find WebSphere 4 TransactionManager factory class", ex3); 101 throw new TransactionSystemException( 102 "Could not find any WebSphere TransactionManager factory class, " + 103 "neither for WebSphere version 5.1+ nor 5.0 nor 4"); 104 } 105 } 106 } 107 108 try { 109 Method method = clazz.getMethod("getTransactionManager", (Class []) null); 110 this.transactionManager = (TransactionManager ) method.invoke(null, (Object []) null); 111 } 112 catch (InvocationTargetException ex) { 113 throw new TransactionSystemException( 114 "WebSphere's TransactionManagerFactory.getTransactionManager method failed", ex.getTargetException()); 115 } 116 catch (Exception ex) { 117 throw new TransactionSystemException( 118 "Could not access WebSphere's TransactionManagerFactory.getTransactionManager method", ex); 119 } 120 } 121 122 123 public Object getObject() { 124 return this.transactionManager; 125 } 126 127 public Class getObjectType() { 128 return this.transactionManager.getClass(); 129 } 130 131 public boolean isSingleton() { 132 return true; 133 } 134 135 } 136 | Popular Tags |