Coverage Report - org.mule.transaction.lookup.GenericTransactionManagerLookupFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
GenericTransactionManagerLookupFactory
0%
0/26
0%
0/8
1.6
 
 1  
 /*
 2  
  * $Id: GenericTransactionManagerLookupFactory.java 11517 2008-03-31 21:34:19Z dirk.olmes $
 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 CPAL v1.0
 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.mule.api.lifecycle.Initialisable;
 14  
 import org.mule.api.lifecycle.InitialisationException;
 15  
 import org.mule.api.transaction.TransactionManagerFactory;
 16  
 import org.mule.config.i18n.CoreMessages;
 17  
 import org.mule.util.JndiContextHelper;
 18  
 import org.mule.util.StringUtils;
 19  
 
 20  
 import java.util.Map;
 21  
 
 22  
 import javax.naming.Context;
 23  
 import javax.naming.NamingException;
 24  
 import javax.transaction.TransactionManager;
 25  
 
 26  
 import org.apache.commons.logging.Log;
 27  
 import org.apache.commons.logging.LogFactory;
 28  
 
 29  
 /**
 30  
  * A factory performing a JNDI lookup for TransactionManager. <p/> NOTE: Java EE 1.4
 31  
  * specification does not mandate application server vendors to expose a
 32  
  * TransactionManager for direct use, nor does it name the standard way to locate it.
 33  
  * For some servers the TransactionManager is not even available in the global JNDI
 34  
  * namespace, so your only bet is to run Mule in the same JVM as the application
 35  
  * server.
 36  
  */
 37  0
 public class GenericTransactionManagerLookupFactory implements TransactionManagerFactory, Initialisable
 38  
 {
 39  0
     protected final Log logger = LogFactory.getLog(getClass());
 40  
 
 41  
     protected Context context;
 42  
 
 43  
     private Map environment;
 44  
 
 45  
     private TransactionManager txManager;
 46  
 
 47  
     private String jndiName;
 48  
 
 49  
     public String getJndiName()
 50  
     {
 51  0
         return jndiName;
 52  
     }
 53  
 
 54  
     public void setJndiName(final String jndiName)
 55  
     {
 56  0
         this.jndiName = jndiName;
 57  0
     }
 58  
 
 59  
     public TransactionManager getTxManager()
 60  
     {
 61  0
         return txManager;
 62  
     }
 63  
 
 64  
     public void setTxManager(final TransactionManager txManager)
 65  
     {
 66  0
         this.txManager = txManager;
 67  0
     }
 68  
 
 69  
     public Map getEnvironment()
 70  
     {
 71  0
         return environment;
 72  
     }
 73  
 
 74  
     public void setEnvironment(final Map environment)
 75  
     {
 76  0
         this.environment = environment;
 77  0
     }
 78  
 
 79  
     public Context getContext()
 80  
     {
 81  0
         return context;
 82  
     }
 83  
 
 84  
     public void setContext(final Context context)
 85  
     {
 86  0
         this.context = context;
 87  0
     }
 88  
 
 89  
     /** @see org.mule.api.transaction.TransactionManagerFactory#create() */
 90  
     public TransactionManager create() throws Exception
 91  
     {
 92  
         // implementing the Initilisable interface does not call it??
 93  0
         initialise();
 94  0
         if (txManager == null)
 95  
         {
 96  0
             txManager = (TransactionManager) context.lookup(jndiName);
 97  
         }
 98  
 
 99  0
         return txManager;
 100  
     }
 101  
 
 102  
     /**
 103  
      * Method used to perform any initialisation work. If a fatal error occurs during
 104  
      * initialisation an <code>InitialisationException</code> should be thrown,
 105  
      * causing the Mule instance to shutdown. If the error is recoverable, say by
 106  
      * retrying to connect, a <code>RecoverableException</code> should be thrown.
 107  
      * There is no guarantee that by throwing a Recoverable exception that the Mule
 108  
      * instance will not shut down.
 109  
      *
 110  
      * @throws org.mule.api.lifecycle.InitialisationException
 111  
      *          if a fatal error occurs
 112  
      *          causing the Mule instance to shutdown
 113  
      */
 114  
     public void initialise() throws InitialisationException
 115  
     {
 116  0
         if (txManager == null && StringUtils.isEmpty(StringUtils.trim(jndiName)))
 117  
         {
 118  0
             throw new InitialisationException(CoreMessages.propertiesNotSet("jndiName"), this);
 119  
         }
 120  
 
 121  
         try
 122  
         {
 123  0
             if (context == null)
 124  
             {
 125  0
                 context = JndiContextHelper.initialise(getEnvironment());
 126  
             }
 127  
         }
 128  0
         catch (NamingException e)
 129  
         {
 130  0
             throw new InitialisationException(CoreMessages.failedToCreate("Jndi context"),
 131  
                     e, this);
 132  0
         }
 133  0
     }
 134  
 }