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