1 16 17 package org.springframework.jms.core.support; 18 19 import javax.jms.ConnectionFactory ; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 import org.springframework.beans.factory.BeanInitializationException; 25 import org.springframework.beans.factory.InitializingBean; 26 import org.springframework.jms.core.JmsTemplate; 27 28 43 public abstract class JmsGatewaySupport implements InitializingBean { 44 45 protected final Log logger = LogFactory.getLog(getClass()); 46 47 private JmsTemplate jmsTemplate; 48 49 50 57 public final void setConnectionFactory(ConnectionFactory connectionFactory) { 58 this.jmsTemplate = createJmsTemplate(connectionFactory); 59 } 60 61 71 protected JmsTemplate createJmsTemplate(ConnectionFactory connectionFactory) { 72 return new JmsTemplate(connectionFactory); 73 } 74 75 78 public final ConnectionFactory getConnectionFactory() { 79 return (this.jmsTemplate != null ? this.jmsTemplate.getConnectionFactory() : null); 80 } 81 82 87 public final void setJmsTemplate(JmsTemplate jmsTemplate) { 88 this.jmsTemplate = jmsTemplate; 89 } 90 91 94 public final JmsTemplate getJmsTemplate() { 95 return jmsTemplate; 96 } 97 98 public final void afterPropertiesSet() throws IllegalArgumentException , BeanInitializationException { 99 if (this.jmsTemplate == null) { 100 throw new IllegalArgumentException ("connectionFactory or jmsTemplate is required"); 101 } 102 try { 103 initGateway(); 104 } 105 catch (Exception ex) { 106 throw new BeanInitializationException("Initialization of JMS gateway failed: " + ex.getMessage(), ex); 107 } 108 } 109 110 115 protected void initGateway() throws Exception { 116 } 117 118 } 119 | Popular Tags |