1 10 11 package org.mule.transaction.lookup; 12 13 import org.apache.commons.lang.StringUtils; 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 import org.mule.config.i18n.Message; 17 import org.mule.config.i18n.Messages; 18 import org.mule.impl.container.JndiContextHelper; 19 import org.mule.umo.lifecycle.InitialisationException; 20 import org.mule.umo.manager.UMOTransactionManagerFactory; 21 22 import javax.naming.Context ; 23 import javax.naming.NamingException ; 24 import javax.transaction.TransactionManager ; 25 26 import java.util.Map ; 27 28 38 public class GenericTransactionManagerLookupFactory implements UMOTransactionManagerFactory 39 { 40 protected final Log logger = LogFactory.getLog(getClass()); 41 42 protected Context context; 43 44 private Map environment; 45 46 private TransactionManager txManager; 47 48 private String jndiName; 49 50 public String getJndiName() 51 { 52 return jndiName; 53 } 54 55 public void setJndiName(final String jndiName) 56 { 57 this.jndiName = jndiName; 58 } 59 60 public TransactionManager getTxManager() 61 { 62 return txManager; 63 } 64 65 public void setTxManager(final TransactionManager txManager) 66 { 67 this.txManager = txManager; 68 } 69 70 public Map getEnvironment() 71 { 72 return environment; 73 } 74 75 public void setEnvironment(final Map environment) 76 { 77 this.environment = environment; 78 } 79 80 public Context getContext() 81 { 82 return context; 83 } 84 85 public void setContext(final Context context) 86 { 87 this.context = context; 88 } 89 90 93 public TransactionManager create() throws Exception 94 { 95 initialise(); 97 if (txManager == null) 98 { 99 txManager = (TransactionManager )context.lookup(jndiName); 100 } 101 102 return txManager; 103 } 104 105 118 public void initialise() throws InitialisationException 119 { 120 if (txManager == null && StringUtils.isEmpty(StringUtils.trim(jndiName))) 121 { 122 throw new InitialisationException(new Message(Messages.PROPERTIES_X_NOT_SET, "jndiName"), this); 123 } 124 125 try 126 { 127 if (context == null) 128 { 129 context = JndiContextHelper.initialise(getEnvironment()); 130 } 131 } 132 catch (NamingException e) 133 { 134 throw new InitialisationException(new Message(Messages.FAILED_TO_CREATE_X, "Jndi context"), e, 135 this); 136 } 137 } 138 } 139 | Popular Tags |