1 10 11 package org.mule.impl; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.mule.MuleManager; 16 import org.mule.transaction.constraints.ConstraintFilter; 17 import org.mule.umo.UMOTransactionConfig; 18 import org.mule.umo.UMOTransactionFactory; 19 20 24 public class MuleTransactionConfig implements UMOTransactionConfig 25 { 26 29 protected static final Log logger = LogFactory.getLog(MuleTransactionConfig.class); 30 31 public static final String ACTION_NONE_STRING = "NONE"; 32 public static final String ACTION_ALWAYS_BEGIN_STRING = "ALWAYS_BEGIN"; 33 public static final String ACTION_BEGIN_OR_JOIN_STRING = "BEGIN_OR_JOIN"; 34 public static final String ACTION_ALWAYS_JOIN_STRING = "ALWAYS_JOIN"; 35 public static final String ACTION_JOIN_IF_POSSIBLE_STRING = "JOIN_IF_POSSIBLE"; 36 37 private UMOTransactionFactory factory; 38 39 private byte action = ACTION_NONE; 40 41 private ConstraintFilter constraint = null; 42 43 private int timeout; 44 45 public MuleTransactionConfig() 46 { 47 timeout = MuleManager.getConfiguration().getTransactionTimeout(); 48 } 49 50 55 public UMOTransactionFactory getFactory() 56 { 57 return factory; 58 } 59 60 65 public void setFactory(UMOTransactionFactory factory) 66 { 67 if (factory == null) 68 { 69 throw new IllegalArgumentException ("Transaction Factory cannot be null"); 70 } 71 this.factory = factory; 72 } 73 74 79 public byte getAction() 80 { 81 return action; 82 } 83 84 89 public void setAction(byte action) 90 { 91 this.action = action; 92 93 } 94 95 public void setActionAsString(String action) 96 { 97 if (ACTION_ALWAYS_BEGIN_STRING.equals(action)) 98 { 99 this.action = ACTION_ALWAYS_BEGIN; 100 } 101 else if (ACTION_BEGIN_OR_JOIN_STRING.equals(action)) 102 { 103 this.action = ACTION_BEGIN_OR_JOIN; 104 } 105 else if (ACTION_ALWAYS_JOIN_STRING.equals(action)) 106 { 107 this.action = ACTION_ALWAYS_JOIN; 108 } 109 else if (ACTION_JOIN_IF_POSSIBLE_STRING.equals(action)) 110 { 111 this.action = ACTION_JOIN_IF_POSSIBLE; 112 } 113 else if (ACTION_NONE_STRING.equals(action)) 114 { 115 this.action = ACTION_NONE; 116 } 117 else 118 { 119 throw new IllegalArgumentException ("Action " + action + " is not recognised as a begin action."); 120 } 121 } 122 123 public String getActionAsString() 124 { 125 switch (action) 126 { 127 case ACTION_ALWAYS_BEGIN : 128 return ACTION_ALWAYS_BEGIN_STRING; 129 case ACTION_ALWAYS_JOIN : 130 return ACTION_ALWAYS_JOIN_STRING; 131 case ACTION_JOIN_IF_POSSIBLE : 132 return ACTION_JOIN_IF_POSSIBLE_STRING; 133 default : 134 return ACTION_NONE_STRING; 135 } 136 } 137 138 public boolean isTransacted() 139 { 140 if (factory != null) 141 { 142 if (!factory.isTransacted()) 143 { 144 return false; 145 } 146 return action != ACTION_NONE; 147 } 148 return false; 149 } 150 151 public ConstraintFilter getConstraint() 152 { 153 if (constraint == null) 154 { 155 return null; 156 } 157 try 158 { 159 return (ConstraintFilter)constraint.clone(); 160 } 161 catch (CloneNotSupportedException e) 162 { 163 logger.fatal("Failed to clone ContraintFilter: " + e.getMessage(), e); 164 return constraint; 165 } 166 } 167 168 public void setConstraint(ConstraintFilter constraint) 169 { 170 this.constraint = constraint; 171 } 172 173 public int getTimeout() 174 { 175 return timeout; 176 } 177 178 public void setTimeout(int timeout) 179 { 180 this.timeout = timeout; 181 } 182 183 public String toString() 184 { 185 StringBuffer buf = new StringBuffer (); 186 buf.append("Transaction{factory=") 187 .append(factory) 188 .append(", action=") 189 .append(getActionAsString()) 190 .append(", timeout=") 191 .append(timeout) 192 .append("}"); 193 return buf.toString(); 194 } 195 } 196 | Popular Tags |