KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > transaction > jta > WebLogicServerTransactionManagerFactoryBean


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.transaction.jta;
18
19 import java.lang.reflect.InvocationTargetException JavaDoc;
20 import java.lang.reflect.Method JavaDoc;
21
22 import javax.transaction.TransactionManager JavaDoc;
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 /**
31  * {@link org.springframework.beans.factory.FactoryBean} that retrieves the
32  * internal JTA TransactionManager of BEA's WebLogic version 7.0, which is
33  * required for proper transaction suspension support on that application
34  * server version. <b>This class is not relevant on WebLogic 8.1+!</b>
35  *
36  * <p>Uses WebLogic <code>TxHelper</code>'s static access methods to obtain the
37  * server's internal JTA TransactionManager. This doesn't need be used with
38  * WebLogic 8.1 or higher, since the regular JNDI lookup is sufficient there:
39  * It returns a JTA TransactionManager that can handle all transaction management
40  * tasks properly.
41  *
42  * <p><b>Note that as of Spring 1.2, this class is effectively superseded by
43  * {@link WebLogicJtaTransactionManager}'s autodetection of WebLogic 7.0 or
44  * 8.1+.</b> It is only kept as a way to explicitly expose the
45  * {@link javax.transaction.TransactionManager} on WebLogic 7.0,
46  * for non-Spring code that needs access to this facility.
47  *
48  * <p><b>For typical scenarios, use Spring's {@link WebLogicJtaTransactionManager}
49  * as-is and do not bother with setting up this FactoryBean.</b>
50  *
51  * @author Thomas Risberg
52  * @author Juergen Hoeller
53  * @since 1.1
54  * @see WebLogicJtaTransactionManager
55  * @see JtaTransactionManager#setTransactionManager
56  * @see weblogic.transaction.TxHelper#getTransactionManager
57  */

58 public class WebLogicServerTransactionManagerFactoryBean implements FactoryBean {
59
60     private static final String JavaDoc TX_HELPER_CLASS_NAME = "weblogic.transaction.TxHelper";
61
62
63     protected final Log logger = LogFactory.getLog(getClass());
64
65     private final TransactionManager JavaDoc transactionManager;
66
67
68     /**
69      * This constructor retrieves the WebLogic TransactionManager factory class,
70      * so we can get access to the JTA TransactionManager.
71      */

72     public WebLogicServerTransactionManagerFactoryBean() throws TransactionSystemException {
73         try {
74             Class JavaDoc helperClass = Class.forName(TX_HELPER_CLASS_NAME);
75             logger.debug("Found WebLogic's TxHelper: " + TX_HELPER_CLASS_NAME);
76             Method JavaDoc method = helperClass.getMethod("getTransactionManager", (Class JavaDoc[]) null);
77             this.transactionManager = (TransactionManager JavaDoc) method.invoke(null, (Object JavaDoc[]) null);
78         }
79         catch (ClassNotFoundException JavaDoc ex) {
80             throw new TransactionSystemException("Could not find WebLogic's TxHelper class", ex);
81         }
82         catch (InvocationTargetException JavaDoc ex) {
83             throw new TransactionSystemException(
84                     "WebLogic's TxHelper.getTransactionManager method failed", ex.getTargetException());
85         }
86         catch (Exception JavaDoc ex) {
87             throw new TransactionSystemException(
88                     "Could not access WebLogic's TxHelper.getTransactionManager method", ex);
89         }
90     }
91
92
93     public Object JavaDoc getObject() {
94         return this.transactionManager;
95     }
96
97     public Class JavaDoc getObjectType() {
98         return this.transactionManager.getClass();
99     }
100
101     public boolean isSingleton() {
102         return true;
103     }
104
105 }
106
Popular Tags