1 16 17 package org.springframework.jms.support; 18 19 import javax.jms.Connection ; 20 import javax.jms.ConnectionFactory ; 21 import javax.jms.JMSException ; 22 import javax.jms.Session ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 import org.springframework.beans.factory.InitializingBean; 28 import org.springframework.core.Constants; 29 import org.springframework.jms.JmsException; 30 31 46 public abstract class JmsAccessor implements InitializingBean { 47 48 49 private static final Constants sessionConstants = new Constants(Session .class); 50 51 52 53 protected final Log logger = LogFactory.getLog(getClass()); 54 55 private ConnectionFactory connectionFactory; 56 57 private boolean sessionTransacted = false; 58 59 private int sessionAcknowledgeMode = Session.AUTO_ACKNOWLEDGE; 60 61 62 66 public void setConnectionFactory(ConnectionFactory connectionFactory) { 67 this.connectionFactory = connectionFactory; 68 } 69 70 74 public ConnectionFactory getConnectionFactory() { 75 return this.connectionFactory; 76 } 77 78 97 public void setSessionTransacted(boolean sessionTransacted) { 98 this.sessionTransacted = sessionTransacted; 99 } 100 101 107 public boolean isSessionTransacted() { 108 return this.sessionTransacted; 109 } 110 111 122 public void setSessionAcknowledgeModeName(String constantName) { 123 setSessionAcknowledgeMode(sessionConstants.asNumber(constantName).intValue()); 124 } 125 126 142 public void setSessionAcknowledgeMode(int sessionAcknowledgeMode) { 143 this.sessionAcknowledgeMode = sessionAcknowledgeMode; 144 } 145 146 150 public int getSessionAcknowledgeMode() { 151 return this.sessionAcknowledgeMode; 152 } 153 154 public void afterPropertiesSet() { 155 if (getConnectionFactory() == null) { 156 throw new IllegalArgumentException ("Property 'connectionFactory' is required"); 157 } 158 } 159 160 161 171 protected JmsException convertJmsAccessException(JMSException ex) { 172 return JmsUtils.convertJmsAccessException(ex); 173 } 174 175 176 180 187 protected Connection createConnection() throws JMSException { 188 return getConnectionFactory().createConnection(); 189 } 190 191 199 protected Session createSession(Connection con) throws JMSException { 200 return con.createSession(isSessionTransacted(), getSessionAcknowledgeMode()); 201 } 202 203 212 protected boolean isClientAcknowledge(Session session) throws JMSException { 213 return (session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE); 214 } 215 216 } 217 | Popular Tags |