KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > transaction > lookup > WebsphereTransactionManagerLookupFactory


1 /*
2  * $Id: WebsphereTransactionManagerLookupFactory.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

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 JavaDoc;
18
19 import java.lang.reflect.Method JavaDoc;
20
21 /**
22  * The code borrowed from Spring's
23  * org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean. See
24  * the apache-2.0.license file in Mule's licenses folder for details.
25  *
26  * @see com.ibm.ws.Transaction.TransactionManagerFactory#getTransactionManager
27  * @see com.ibm.ejs.jts.jta.JTSXA#getTransactionManager
28  * @see com.ibm.ejs.jts.jta.TransactionManagerFactory#getTransactionManager
29  */

30 public class WebsphereTransactionManagerLookupFactory implements UMOTransactionManagerFactory
31 {
32     private static final String JavaDoc FACTORY_CLASS_5_1 = "com.ibm.ws.Transaction.TransactionManagerFactory";
33
34     private static final String JavaDoc FACTORY_CLASS_5_0 = "com.ibm.ejs.jts.jta.TransactionManagerFactory";
35
36     private static final String JavaDoc FACTORY_CLASS_4 = "com.ibm.ejs.jts.jta.JTSXA";
37
38     private final Log logger = LogFactory.getLog(getClass());
39
40     /**
41      * This constructor retrieves the WebSphere TransactionManager factory class, so
42      * we can get access to the JTA TransactionManager.
43      */

44     public TransactionManager JavaDoc create()
45     {
46         Class JavaDoc clazz;
47         TransactionManager JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc ex3)
73                 {
74                     logger.debug("Could not find WebSphere 4 TransactionManager factory class", ex3);
75                     throw new RuntimeException JavaDoc(
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 JavaDoc method = clazz.getMethod("getTransactionManager", null);
84             transactionManager = (TransactionManager JavaDoc)method.invoke(null, null);
85         }
86         catch (Exception JavaDoc ex)
87         {
88             throw new RuntimeException JavaDoc("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