001: /*
002: * Copyright 2002-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.transaction.jta;
018:
019: import java.lang.reflect.InvocationTargetException;
020: import java.lang.reflect.Method;
021:
022: import javax.transaction.TransactionManager;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026:
027: import org.springframework.beans.factory.FactoryBean;
028: import org.springframework.transaction.TransactionSystemException;
029:
030: /**
031: * {@link org.springframework.beans.factory.FactoryBean} that retrieves the
032: * internal JTA TransactionManager of BEA's WebLogic version 7.0, which is
033: * required for proper transaction suspension support on that application
034: * server version. <b>This class is not relevant on WebLogic 8.1+!</b>
035: *
036: * <p>Uses WebLogic <code>TxHelper</code>'s static access methods to obtain the
037: * server's internal JTA TransactionManager. This doesn't need be used with
038: * WebLogic 8.1 or higher, since the regular JNDI lookup is sufficient there:
039: * It returns a JTA TransactionManager that can handle all transaction management
040: * tasks properly.
041: *
042: * <p><b>Note that as of Spring 1.2, this class is effectively superseded by
043: * {@link WebLogicJtaTransactionManager}'s autodetection of WebLogic 7.0 or
044: * 8.1+.</b> It is only kept as a way to explicitly expose the
045: * {@link javax.transaction.TransactionManager} on WebLogic 7.0,
046: * for non-Spring code that needs access to this facility.
047: *
048: * <p><b>For typical scenarios, use Spring's {@link WebLogicJtaTransactionManager}
049: * as-is and do not bother with setting up this FactoryBean.</b>
050: *
051: * @author Thomas Risberg
052: * @author Juergen Hoeller
053: * @since 1.1
054: * @see WebLogicJtaTransactionManager
055: * @see JtaTransactionManager#setTransactionManager
056: * @see weblogic.transaction.TxHelper#getTransactionManager
057: */
058: public class WebLogicServerTransactionManagerFactoryBean implements
059: FactoryBean {
060:
061: private static final String TX_HELPER_CLASS_NAME = "weblogic.transaction.TxHelper";
062:
063: protected final Log logger = LogFactory.getLog(getClass());
064:
065: private final TransactionManager transactionManager;
066:
067: /**
068: * This constructor retrieves the WebLogic TransactionManager factory class,
069: * so we can get access to the JTA TransactionManager.
070: */
071: public WebLogicServerTransactionManagerFactoryBean()
072: throws TransactionSystemException {
073: try {
074: Class helperClass = Class.forName(TX_HELPER_CLASS_NAME);
075: logger.debug("Found WebLogic's TxHelper: "
076: + TX_HELPER_CLASS_NAME);
077: Method method = helperClass.getMethod(
078: "getTransactionManager", (Class[]) null);
079: this .transactionManager = (TransactionManager) method
080: .invoke(null, (Object[]) null);
081: } catch (ClassNotFoundException ex) {
082: throw new TransactionSystemException(
083: "Could not find WebLogic's TxHelper class", ex);
084: } catch (InvocationTargetException ex) {
085: throw new TransactionSystemException(
086: "WebLogic's TxHelper.getTransactionManager method failed",
087: ex.getTargetException());
088: } catch (Exception ex) {
089: throw new TransactionSystemException(
090: "Could not access WebLogic's TxHelper.getTransactionManager method",
091: ex);
092: }
093: }
094:
095: public Object getObject() {
096: return this .transactionManager;
097: }
098:
099: public Class getObjectType() {
100: return this .transactionManager.getClass();
101: }
102:
103: public boolean isSingleton() {
104: return true;
105: }
106:
107: }
|