1 10 11 package org.mule.providers.jms; 12 13 import javax.jms.Connection ; 14 import javax.jms.JMSException ; 15 import javax.jms.Message ; 16 import javax.jms.Session ; 17 18 import org.mule.config.i18n.Messages; 19 import org.mule.transaction.AbstractSingleResourceTransaction; 20 import org.mule.transaction.IllegalTransactionStateException; 21 import org.mule.umo.TransactionException; 22 23 29 public class JmsClientAcknowledgeTransaction extends AbstractSingleResourceTransaction 30 { 31 private Message message; 32 33 38 protected void doBegin() throws TransactionException 39 { 40 } 42 43 48 protected void doCommit() throws TransactionException 49 { 50 try 51 { 52 if (message == null) 53 { 54 throw new IllegalTransactionStateException(new org.mule.config.i18n.Message("jms", 6)); 55 } 56 message.acknowledge(); 57 } 58 catch (JMSException e) 59 { 60 throw new IllegalTransactionStateException(new org.mule.config.i18n.Message( 61 Messages.TX_COMMIT_FAILED), e); 62 } 63 } 64 65 70 protected void doRollback() throws TransactionException 71 { 72 if (message != null) 74 { 75 throw new UnsupportedOperationException ("Jms Client Acknowledge doesn't support rollback"); 76 } 77 } 78 79 85 public void bindResource(Object key, Object resource) throws TransactionException 86 { 87 if (key instanceof Message ) 88 { 89 this.message = (Message )key; 90 return; 91 } 92 if (!(key instanceof Connection ) || !(resource instanceof Session )) 93 { 94 throw new IllegalTransactionStateException(new org.mule.config.i18n.Message( 95 Messages.TX_CAN_ONLY_BIND_TO_X_TYPE_RESOURCES, "javax.jms.Connection/javax.jms.Session")); 96 } 97 98 Session session = (Session )resource; 99 try 100 { 101 if (session.getTransacted()) 102 { 103 throw new IllegalTransactionStateException(new org.mule.config.i18n.Message("jms", 5)); 104 } 105 } 106 catch (JMSException e) 107 { 108 throw new IllegalTransactionStateException(new org.mule.config.i18n.Message( 109 Messages.TX_CANT_READ_STATE), e); 110 } 111 112 super.bindResource(key, resource); 113 } 114 } 115 | Popular Tags |