1 7 package org.ejtools.jndi.browser.model.jms; 8 9 import java.beans.beancontext.BeanContextServiceRevokedEvent ; 10 import java.beans.beancontext.BeanContextServices ; 11 12 import javax.jms.QueueConnectionFactory ; 13 import javax.jms.TopicConnectionFactory ; 14 import javax.naming.Context ; 15 import javax.rmi.PortableRemoteObject ; 16 17 import org.apache.log4j.Logger; 18 import org.ejtools.jndi.browser.model.JNDIEntry; 19 import org.ejtools.jndi.browser.model.service.JMSConnectionService; 20 21 50 public class ConnectionFactoryProxy extends JNDIEntry 51 { 52 53 protected boolean isDefault = false; 54 55 protected boolean isQueueConnectionFactory = false; 56 57 protected boolean isTopicConnectionFactory = false; 58 59 protected QueueConnectionFactory queueConnectionFactory = null; 60 61 protected TopicConnectionFactory topicConnectionFactory = null; 62 63 private static Logger logger = Logger.getLogger(ConnectionFactoryProxy.class); 64 65 66 73 public ConnectionFactoryProxy(Context context, String jndiName) 74 throws Exception 75 { 76 Object o = context.lookup(jndiName); 78 79 setName(jndiName); 80 setClassName(o.getClass().getName()); 81 82 if (o instanceof QueueConnectionFactory ) 83 { 84 this.queueConnectionFactory = (QueueConnectionFactory ) PortableRemoteObject.narrow(o, QueueConnectionFactory .class); 85 this.isQueueConnectionFactory = true; 86 } 87 if (o instanceof TopicConnectionFactory ) 88 { 89 this.topicConnectionFactory = (TopicConnectionFactory ) PortableRemoteObject.narrow(o, TopicConnectionFactory .class); 90 this.isTopicConnectionFactory = true; 91 } 92 if (!(this.isQueueConnectionFactory || this.isTopicConnectionFactory)) 93 { 94 throw new Exception ("Not Available"); 95 } 96 } 97 98 99 104 public QueueConnectionFactory getQueueConnectionFactory() 105 { 106 return this.queueConnectionFactory; 107 } 108 109 110 115 public TopicConnectionFactory getTopicConnectionFactory() 116 { 117 return this.topicConnectionFactory; 118 } 119 120 121 126 public boolean isQueueConnectionFactory() 127 { 128 return this.isQueueConnectionFactory; 129 } 130 131 132 137 public boolean isTopicConnectionFactory() 138 { 139 return this.isTopicConnectionFactory; 140 } 141 142 143 148 public void serviceRevoked(BeanContextServiceRevokedEvent bcsre) 149 { 150 try 151 { 152 BeanContextServices context = (BeanContextServices ) getBeanContext(); 153 context.releaseService(this, this, JMSConnectionService.class); 154 } 155 catch (Exception e) 156 { 157 logger.error("Error during release of service ConnectionService (" + e.getMessage() + ")"); 158 } 159 } 160 161 162 167 public String toString() 168 { 169 return name == null ? "Undefined" : name; 170 } 171 172 173 174 protected void initializeBeanContextResources() 175 { 176 BeanContextServices context = (BeanContextServices ) getBeanContext(); 177 if (context.hasService(JMSConnectionService.class)) 178 { 179 try 180 { 181 JMSConnectionService service = (JMSConnectionService) context.getService(this, this, JMSConnectionService.class, this, this); 182 } 183 catch (Exception e) 184 { 185 logger.error("Error during utilisation of service ConnectionService (" + e.getMessage() + ")"); 186 } 187 } 188 } 189 } 190 191 | Popular Tags |