Coverage Report - org.apache.commons.messenger.XACapableAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
XACapableAdapter
0%
0/18
0%
0/6
2
 
 1  
 /*
 2  
  * Copyright (C) The Apache Software Foundation. All rights reserved.
 3  
  *
 4  
  * This software is published under the terms of the Apache Software License
 5  
  * version 1.1, a copy of which has been included with this distribution in
 6  
  * the LICENSE file.
 7  
  * 
 8  
  * $Id: XACapableAdapter.java 155459 2005-02-26 13:24:44Z dirkv $
 9  
  */
 10  
 package org.apache.commons.messenger;
 11  
 
 12  
 import javax.jms.Session;
 13  
 import javax.jms.XASession;
 14  
 import javax.transaction.Transaction;
 15  
 import javax.transaction.xa.XAResource;
 16  
 
 17  
 import org.apache.commons.logging.Log;
 18  
 import org.apache.commons.logging.LogFactory;
 19  
 
 20  
 /** 
 21  
  * <p><code>XACapableAdapter</code> is an adapter that implements
 22  
  * XACapable for a given Messenger 
 23  
  * </p>
 24  
  *
 25  
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 26  
  * @version $Revision: 155459 $
 27  
  */
 28  
 public class XACapableAdapter implements XACapable {
 29  
 
 30  
     /** Logger */
 31  0
     private static final Log log = LogFactory.getLog(XACapableAdapter.class);
 32  
     
 33  
         private Messenger messenger;
 34  
         
 35  0
         public XACapableAdapter(Messenger messenger) {
 36  0
                 this.messenger = messenger;
 37  0
         }
 38  
     
 39  
     // XACapable interface
 40  
     //-------------------------------------------------------------------------
 41  
         
 42  
         public void enlistResources(Transaction transaction) throws Exception {
 43  0
                 XAResource resource = getXAResource();
 44  0
                 if (resource != null) {
 45  0
                         transaction.enlistResource(resource);
 46  
                 }
 47  0
         }
 48  
 
 49  
         public void delistResources(Transaction transaction, int flag) throws Exception {
 50  0
                 XAResource resource = getXAResource();
 51  0
                 if (resource != null) {
 52  0
                         transaction.delistResource(resource, flag);
 53  
                 }
 54  0
         }
 55  
 
 56  
     // Implementation methods
 57  
     //-------------------------------------------------------------------------
 58  
     
 59  
     /**
 60  
      * @return the XAResource associated with this Messenger if one exists
 61  
      */
 62  
         protected XAResource getXAResource() throws Exception {
 63  0
                 Session session = messenger.getSession();
 64  0
                 if (session instanceof XASession) {
 65  0
                         XASession xaSession = (XASession) session;
 66  0
                         return xaSession.getXAResource();
 67  
                 }
 68  
                 else {
 69  0
                         log.warn(
 70  
                                 "Messenger: " + messenger 
 71  
                                 + " cannot take part in an XA transaction as it does not have an XASession."
 72  
                                 + " session: " + session 
 73  
                         );
 74  
                 }
 75  0
                 return null;
 76  
         }
 77  
 }