Coverage Report - org.mule.impl.MuleTransactionConfig
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleTransactionConfig
0%
0/47
0%
0/8
2.538
 
 1  
 /*
 2  
  * $Id: MuleTransactionConfig.java 7976 2007-08-21 14:26:13Z 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.impl;
 12  
 
 13  
 import org.mule.MuleManager;
 14  
 import org.mule.transaction.constraints.ConstraintFilter;
 15  
 import org.mule.umo.UMOTransactionConfig;
 16  
 import org.mule.umo.UMOTransactionFactory;
 17  
 
 18  
 import org.apache.commons.logging.Log;
 19  
 import org.apache.commons.logging.LogFactory;
 20  
 
 21  
 /**
 22  
  * <p/> <code>MuleTransactionConfig</code> defines transaction configuration for a
 23  
  * transactional endpoint.
 24  
  */
 25  
 public class MuleTransactionConfig implements UMOTransactionConfig
 26  
 {
 27  
     /**
 28  
      * logger used by this class
 29  
      */
 30  0
     protected static final Log logger = LogFactory.getLog(MuleTransactionConfig.class);
 31  
 
 32  
     public static final String ACTION_NONE_STRING = "NONE";
 33  
     public static final String ACTION_ALWAYS_BEGIN_STRING = "ALWAYS_BEGIN";
 34  
     public static final String ACTION_BEGIN_OR_JOIN_STRING = "BEGIN_OR_JOIN";
 35  
     public static final String ACTION_ALWAYS_JOIN_STRING = "ALWAYS_JOIN";
 36  
     public static final String ACTION_JOIN_IF_POSSIBLE_STRING = "JOIN_IF_POSSIBLE";
 37  
 
 38  
     private UMOTransactionFactory factory;
 39  
 
 40  0
     private byte action = ACTION_NONE;
 41  
 
 42  0
     private ConstraintFilter constraint = null;
 43  
 
 44  
     private int timeout;
 45  
 
 46  
     public MuleTransactionConfig()
 47  0
     {
 48  0
         timeout = MuleManager.getConfiguration().getTransactionTimeout();
 49  0
     }
 50  
 
 51  
     /*
 52  
      * (non-Javadoc)
 53  
      * 
 54  
      * @see org.mule.umo.UMOTransactionConfig#getFactory()
 55  
      */
 56  
     public UMOTransactionFactory getFactory()
 57  
     {
 58  0
         return factory;
 59  
     }
 60  
 
 61  
     /*
 62  
      * (non-Javadoc)
 63  
      * 
 64  
      * @see org.mule.umo.UMOTransactionConfig#setFactory(org.mule.umo.UMOTransactionFactory)
 65  
      */
 66  
     public void setFactory(UMOTransactionFactory factory)
 67  
     {
 68  0
         if (factory == null)
 69  
         {
 70  0
             throw new IllegalArgumentException("Transaction Factory cannot be null");
 71  
         }
 72  0
         this.factory = factory;
 73  0
     }
 74  
 
 75  
     /*
 76  
      * (non-Javadoc)
 77  
      * 
 78  
      * @see org.mule.umo.UMOTransactionConfig#getAction()
 79  
      */
 80  
     public byte getAction()
 81  
     {
 82  0
         return action;
 83  
     }
 84  
 
 85  
     /*
 86  
      * (non-Javadoc)
 87  
      * 
 88  
      * @see org.mule.umo.UMOTransactionConfig#setAction(byte)
 89  
      */
 90  
     public void setAction(byte action)
 91  
     {
 92  0
         this.action = action;
 93  
 
 94  0
     }
 95  
 
 96  
     public void setActionAsString(String action)
 97  
     {
 98  0
         if (ACTION_ALWAYS_BEGIN_STRING.equals(action))
 99  
         {
 100  0
             this.action = ACTION_ALWAYS_BEGIN;
 101  
         }
 102  0
         else if (ACTION_BEGIN_OR_JOIN_STRING.equals(action))
 103  
         {
 104  0
             this.action = ACTION_BEGIN_OR_JOIN;
 105  
         }
 106  0
         else if (ACTION_ALWAYS_JOIN_STRING.equals(action))
 107  
         {
 108  0
             this.action = ACTION_ALWAYS_JOIN;
 109  
         }
 110  0
         else if (ACTION_JOIN_IF_POSSIBLE_STRING.equals(action))
 111  
         {
 112  0
             this.action = ACTION_JOIN_IF_POSSIBLE;
 113  
         }
 114  0
         else if (ACTION_NONE_STRING.equals(action))
 115  
         {
 116  0
             this.action = ACTION_NONE;
 117  
         }
 118  
         else
 119  
         {
 120  0
             throw new IllegalArgumentException("Action " + action + " is not recognised as a begin action.");
 121  
         }
 122  0
     }
 123  
 
 124  
     public String getActionAsString()
 125  
     {
 126  0
         switch (action)
 127  
         {
 128  
             case ACTION_ALWAYS_BEGIN :
 129  0
                 return ACTION_ALWAYS_BEGIN_STRING;
 130  
             case ACTION_BEGIN_OR_JOIN :
 131  0
                 return ACTION_BEGIN_OR_JOIN_STRING; 
 132  
             case ACTION_ALWAYS_JOIN :
 133  0
                 return ACTION_ALWAYS_JOIN_STRING;
 134  
             case ACTION_JOIN_IF_POSSIBLE :
 135  0
                 return ACTION_JOIN_IF_POSSIBLE_STRING;
 136  
             default :
 137  0
                 return ACTION_NONE_STRING;
 138  
         }
 139  
     }
 140  
 
 141  
     public boolean isTransacted()
 142  
     {
 143  0
         return factory != null && factory.isTransacted() && action != ACTION_NONE;
 144  
     }
 145  
 
 146  
     public ConstraintFilter getConstraint()
 147  
     {
 148  0
         if (constraint == null)
 149  
         {
 150  0
             return null;
 151  
         }
 152  
         try
 153  
         {
 154  0
             return (ConstraintFilter) constraint.clone();
 155  
         }
 156  0
         catch (CloneNotSupportedException e)
 157  
         {
 158  0
             logger.fatal("Failed to clone ContraintFilter: " + e.getMessage(), e);
 159  0
             return constraint;
 160  
         }
 161  
     }
 162  
 
 163  
     public void setConstraint(ConstraintFilter constraint)
 164  
     {
 165  0
         this.constraint = constraint;
 166  0
     }
 167  
 
 168  
     public int getTimeout()
 169  
     {
 170  0
         return timeout;
 171  
     }
 172  
 
 173  
     public void setTimeout(int timeout)
 174  
     {
 175  0
         this.timeout = timeout;
 176  0
     }
 177  
 
 178  
     public String toString()
 179  
     {
 180  0
         StringBuffer buf = new StringBuffer();
 181  0
         buf.append("Transaction{factory=")
 182  
             .append(factory)
 183  
             .append(", action=")
 184  
             .append(getActionAsString())
 185  
             .append(", timeout=")
 186  
             .append(timeout)
 187  
             .append("}");
 188  0
         return buf.toString();
 189  
     }
 190  
 }