Coverage Report - org.mule.transport.jms.xa.ConnectionInvocationHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
ConnectionInvocationHandler
0%
0/26
0%
0/14
4.25
 
 1  
 /*
 2  
  * $Id: ConnectionInvocationHandler.java 20320 2010-11-24 15:03:31Z dfeist $
 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.transport.jms.xa;
 11  
 
 12  
 import org.mule.api.transaction.Transaction;
 13  
 import org.mule.transaction.TransactionCoordination;
 14  
 import org.mule.transaction.XaTransaction;
 15  
 
 16  
 import java.lang.reflect.Method;
 17  
 import java.lang.reflect.Proxy;
 18  
 
 19  
 import javax.jms.QueueSession;
 20  
 import javax.jms.Session;
 21  
 import javax.jms.TopicSession;
 22  
 import javax.jms.XAConnection;
 23  
 import javax.jms.XAQueueConnection;
 24  
 import javax.jms.XAQueueSession;
 25  
 import javax.jms.XASession;
 26  
 import javax.jms.XATopicConnection;
 27  
 import javax.jms.XATopicSession;
 28  
 
 29  
 public class ConnectionInvocationHandler implements TargetInvocationHandler
 30  
 {
 31  
     private Object xaConnection;
 32  
     private Boolean sameRMOverrideValue;
 33  
 
 34  
     public ConnectionInvocationHandler(Object xac)
 35  
     {
 36  0
         this(xac, null);
 37  0
     }
 38  
 
 39  
     public ConnectionInvocationHandler(Object xac, Boolean sameRMOverrideValue)
 40  0
     {
 41  0
         this.xaConnection = xac;
 42  0
         this.sameRMOverrideValue = sameRMOverrideValue;
 43  0
     }
 44  
 
 45  
     public Object getTargetObject()
 46  
     {
 47  0
         return xaConnection;
 48  
     }
 49  
 
 50  
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
 51  
     {
 52  0
         if (ConnectionFactoryWrapper.logger.isDebugEnabled())
 53  
         {
 54  0
             ConnectionFactoryWrapper.logger.debug("Invoking " + method);
 55  
         }
 56  
         
 57  0
         Transaction tx = TransactionCoordination.getInstance().getTransaction();
 58  
         
 59  0
         if (method.getName().equals("createSession"))
 60  
         {
 61  0
             if (tx != null)
 62  
             {
 63  0
                 XASession xas = ((XAConnection) xaConnection).createXASession();
 64  0
                 return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), 
 65  
                     new Class[]{ Session.class, XaTransaction.MuleXaObject.class },
 66  
                     new SessionInvocationHandler(xas, sameRMOverrideValue));
 67  
             }
 68  
             else
 69  
             {
 70  0
                 return ((XAConnection) xaConnection).createSession(false, Session.AUTO_ACKNOWLEDGE);
 71  
             }
 72  
         }
 73  0
         else if (method.getName().equals("createQueueSession"))
 74  
         {
 75  0
             if (tx != null)
 76  
             {
 77  0
                 XAQueueSession xaqs = ((XAQueueConnection) xaConnection).createXAQueueSession();
 78  0
                 return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
 79  
                     new Class[]{ QueueSession.class, XaTransaction.MuleXaObject.class }, 
 80  
                     new SessionInvocationHandler(xaqs, sameRMOverrideValue));
 81  
             }
 82  
             else
 83  
             {
 84  0
                 return ((XAQueueConnection) xaConnection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
 85  
             }
 86  
         }
 87  0
         else if (method.getName().equals("createTopicSession"))
 88  
         {
 89  0
             if (tx != null)
 90  
             {
 91  0
                 XATopicSession xats = ((XATopicConnection) xaConnection).createXATopicSession();
 92  0
                 return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
 93  
                     new Class[]{ TopicSession.class, XaTransaction.MuleXaObject.class }, 
 94  
                     new SessionInvocationHandler(xats, sameRMOverrideValue));
 95  
             }
 96  
             else
 97  
             {
 98  0
                 return ((XATopicConnection) xaConnection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
 99  
             }
 100  
         }
 101  
         else
 102  
         {
 103  0
             return method.invoke(xaConnection, args);
 104  
         }
 105  
     }
 106  
 }