1 10 11 package org.mule.providers.oracle.jms; 12 13 import java.util.Map ; 14 15 import javax.jms.Connection ; 16 import javax.jms.ConnectionFactory ; 17 import javax.jms.Destination ; 18 import javax.jms.JMSException ; 19 import javax.jms.MessageConsumer ; 20 import javax.jms.Queue ; 21 import javax.jms.QueueSession ; 22 import javax.jms.Session ; 23 import javax.jms.Topic ; 24 import javax.jms.TopicSession ; 25 import javax.naming.Context ; 26 27 import oracle.jms.AQjmsSession; 28 29 import org.mule.providers.jms.Jms102bSupport; 30 import org.mule.providers.jms.JmsConnector; 31 32 46 public class OracleJmsSupport extends Jms102bSupport 47 { 48 49 54 private Map endpointProperties; 55 56 public OracleJmsSupport(JmsConnector connector, 57 Context context, 58 boolean jndiDestinations, 59 boolean forceJndiDestinations) 60 { 61 super(connector, context, jndiDestinations, forceJndiDestinations); 62 } 63 64 70 public Connection createConnection(ConnectionFactory connectionFactory) throws JMSException 71 { 72 return createConnection(connectionFactory, null, null); 73 } 74 75 81 public javax.jms.Connection createConnection(ConnectionFactory connectionFactory, 82 String username, 83 String password) throws JMSException 84 { 85 return new OracleJmsConnection((OracleJmsConnector) connector); 86 } 87 88 95 public MessageConsumer createConsumer(Session session, 96 Destination destination, 97 String messageSelector, 98 boolean noLocal, 99 String durableName, 100 boolean topic) throws JMSException 101 { 102 103 Object payloadFactory = getPayloadFactory(); 104 if (payloadFactory == null) 105 { 106 return super.createConsumer(session, destination, messageSelector, noLocal, durableName, topic); 107 } 108 else 109 { 110 if (topic && session instanceof TopicSession ) 111 { 112 if (durableName == null) 113 { 114 return ((AQjmsSession) session).createSubscriber((Topic ) destination, messageSelector, 115 noLocal); 116 } 117 else 118 { 119 return ((AQjmsSession) session).createDurableSubscriber((Topic ) destination, 120 durableName, messageSelector, noLocal, payloadFactory); 121 } 122 } 123 else if (session instanceof QueueSession ) 124 { 125 if (messageSelector != null) 126 { 127 return ((AQjmsSession) session).createReceiver((Queue ) destination, messageSelector, 128 payloadFactory); 129 } 130 else 131 { 132 return ((AQjmsSession) session).createReceiver((Queue ) destination, payloadFactory); 133 } 134 } 135 else 136 { 137 throw new IllegalArgumentException ("Session and domain type do not match"); 138 } 139 } 140 } 141 142 152 public Destination createDestination(Session session, String name, boolean topic) throws JMSException 153 { 154 Destination dest = super.createDestination(session, name, topic); 155 if (dest != null) 156 { 157 return dest; 158 } 159 else 160 { 161 throw new JMSException ( 162 "Oracle JMS was unable to bind to the " 163 + (topic ? "topic" : "queue") 164 + ": " 165 + name 166 + " but gives no exception nor error message to explain why (that's what you get for using proprietary software...)"); 167 } 168 } 169 170 180 public Destination createTemporaryDestination(Session session, boolean topic) throws JMSException 181 { 182 Destination dest = super.createTemporaryDestination(session, topic); 183 if (dest != null) 184 { 185 return dest; 186 } 187 else 188 { 189 throw new JMSException ("Unable to create temporary " + (topic ? "topic" : "queue")); 190 } 191 } 192 193 199 public Object getPayloadFactory() throws JMSException 200 { 201 202 String payloadFactoryClass = ((OracleJmsConnector) connector).getPayloadFactory(); 204 205 if ((endpointProperties != null) 208 && (endpointProperties.get(OracleJmsConnector.PAYLOADFACTORY_PROPERTY) != null)) 209 { 210 payloadFactoryClass = (String ) endpointProperties.get(OracleJmsConnector.PAYLOADFACTORY_PROPERTY); 211 } 212 213 Object payloadFactory = null; 214 if (payloadFactoryClass != null) 215 { 216 Throwable ex = null; 217 try 218 { 219 payloadFactory = Class.forName(payloadFactoryClass).newInstance(); 221 } 222 catch (ClassNotFoundException e) 223 { 224 ex = e; 225 } 226 catch (IllegalAccessException e) 227 { 228 ex = e; 229 } 230 catch (InstantiationException e) 231 { 232 ex = e; 233 } 234 if (ex != null) 235 { 236 throw new JMSException ("Unable to instantiate payload factory class " + payloadFactoryClass 237 + ": " + ex.getMessage()); 238 } 239 } 240 return payloadFactory; 241 } 242 243 public Map getEndpointProperties() 244 { 245 return endpointProperties; 246 } 247 248 public void setEndpointProperties(Map endpointProperties) 249 { 250 this.endpointProperties = endpointProperties; 251 } 252 253 } 254 | Popular Tags |