View Javadoc

1   /*
2    * $Id: MuleTransactionManagerFactoryBean.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.config.spring.factories;
11  
12  import org.mule.api.MuleContext;
13  import org.mule.api.context.MuleContextAware;
14  
15  import javax.transaction.TransactionManager;
16  
17  import org.springframework.beans.factory.BeanCreationException;
18  import org.springframework.beans.factory.config.AbstractFactoryBean;
19  
20  /**
21   * Creates a reference to the TransactionManager configured on the MuleContext.  This is useful when you need to inject
22   * the TransactionManager into other objects such as XA data Sources.
23   *
24   * In order to use this factory bean you must have a transaction manager configured in the context i.e.
25   * <code><jbossts:transaction-manager/></code>
26   */
27  public class MuleTransactionManagerFactoryBean extends AbstractFactoryBean implements MuleContextAware
28  {
29      private MuleContext muleContext;
30  
31      public void setMuleContext(MuleContext context)
32      {
33          muleContext = context;
34      }
35  
36      public Class getObjectType()
37      {
38          return TransactionManager.class;
39      }
40  
41      protected Object createInstance() throws Exception
42      {
43          if(muleContext.getTransactionManager()==null)
44          {
45              throw new BeanCreationException("you must have a transaction manager configured inside the context when using " + getClass().getName());
46          }
47          return muleContext.getTransactionManager();
48      }
49  }