WebLogicServerTransactionManagerFactoryBean.java
Upload User: jiancairen
Upload Date: 2007-08-27
Package Size: 26458k
Code Size: 3k
Category:

Java Develop

Development Platform:

Java

  1. /*
  2.  * Copyright 2002-2004 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. package org.springframework.transaction.jta;
  17. import java.lang.reflect.Method;
  18. import javax.transaction.TransactionManager;
  19. import org.apache.commons.logging.Log;
  20. import org.apache.commons.logging.LogFactory;
  21. import org.springframework.beans.factory.FactoryBean;
  22. import org.springframework.transaction.TransactionSystemException;
  23. /**
  24.  * FactoryBean that retrieves the JTA TransactionManager for BEA's
  25.  * WebLogic application server version 7.0.  
  26.  * 
  27.  * <p>This class doesn't need be used with version 8.1 since for this version 
  28.  * the regular JNDI lookup returns a ClientTransactionManagerImpl that can 
  29.  * handle the necessary transaction management tasks. 
  30.  *
  31.  * <p>Uses WebLogic TxHelper's static access methods to obtain the JTA
  32.  * TransactionManager.
  33.  *
  34.  * @author Thomas Risberg
  35.  * @since 1.1
  36.  * @see JtaTransactionManager#setTransactionManager
  37.  * @see weblogic.transaction.TxHelper#getTransactionManager
  38.  */
  39. public class WebLogicServerTransactionManagerFactoryBean implements FactoryBean {
  40. private static final String FACTORY_CLASS = "weblogic.transaction.TxHelper";
  41. protected final Log logger = LogFactory.getLog(getClass());
  42. private final TransactionManager transactionManager;
  43. /**
  44.  * This constructor retrieves the WebLogic TransactionManager factory class,
  45.  * so we can get access to the JTA TransactionManager.
  46.  */
  47. public WebLogicServerTransactionManagerFactoryBean() throws TransactionSystemException {
  48. Class clazz;
  49. try {
  50. logger.debug("Trying Weblogic: " + FACTORY_CLASS);
  51. clazz = Class.forName(FACTORY_CLASS);
  52. logger.info("Found WebLogic: " + FACTORY_CLASS);
  53. }
  54. catch (ClassNotFoundException ex) {
  55. logger.debug("Could not find WebLogic TransactionManager factory class", ex);
  56. throw new TransactionSystemException(
  57. "Couldn't find the WebLogic TransactionManager factory class");
  58. }
  59. try {
  60. Method method = clazz.getMethod("getTransactionManager", null);
  61. this.transactionManager = (TransactionManager) method.invoke(null, null);
  62. }
  63. catch (Exception ex) {
  64. throw new TransactionSystemException(
  65. "Found WebLogic TransactionManager factory class [" + clazz.getName() +
  66. "], but couldn't invoke its static 'getTransactionManager' method", ex);
  67. }
  68. }
  69. public Object getObject() {
  70. return this.transactionManager;
  71. }
  72. public Class getObjectType() {
  73. return this.transactionManager.getClass();
  74. }
  75. public boolean isSingleton() {
  76. return true;
  77. }
  78. }