1 25 26 package org.objectweb.petals.jbi.messaging; 27 28 import java.net.URI ; 29 30 import javax.jbi.messaging.InOnly; 31 import javax.jbi.messaging.InOptionalOut; 32 import javax.jbi.messaging.InOut; 33 import javax.jbi.messaging.MessageExchange; 34 import javax.jbi.messaging.MessageExchangeFactory; 35 import javax.jbi.messaging.MessagingException; 36 import javax.jbi.messaging.RobustInOnly; 37 import javax.jbi.messaging.MessageExchange.Role; 38 import javax.jbi.servicedesc.ServiceEndpoint; 39 import javax.xml.namespace.QName ; 40 41 import org.objectweb.petals.jbi.messaging.types.InOnlyImpl; 42 import org.objectweb.petals.jbi.messaging.types.InOptionalOutImpl; 43 import org.objectweb.petals.jbi.messaging.types.InOutImpl; 44 import org.objectweb.petals.jbi.messaging.types.RobustInOnlyImpl; 45 import org.objectweb.petals.jbi.registry.ConsumerEndpoint; 46 import org.objectweb.petals.util.LoggingUtil; 47 import org.objectweb.util.monolog.api.Logger; 48 49 53 public class MessageExchangeFactoryImpl implements MessageExchangeFactory { 54 55 protected DeliveryChannelImpl channel; 56 57 protected ConsumerEndpoint consumerEndpoint; 58 59 protected QName defaultInterfaceName; 60 61 protected ServiceEndpoint defaultServiceEndpoint; 62 63 protected QName defaultServiceName; 64 65 68 protected LoggingUtil log; 69 70 public MessageExchangeFactoryImpl(DeliveryChannelImpl dc, 71 ConsumerEndpoint ep, Logger logger) { 72 log = new LoggingUtil(logger); 73 this.channel = dc; 74 this.consumerEndpoint = ep; 75 } 76 77 84 public MessageExchange createExchange(QName serviceName, QName operationName) 85 throws MessagingException { 86 log.call(serviceName + "," + operationName); 87 88 MessageExchangeImpl msg = createExchange(); 89 90 setDefaultMessageExchangeProperties(msg); 91 92 msg.setService(serviceName); 93 94 msg.setOperation(operationName); 95 96 return new MessageExchangeDecorator(msg, Role.CONSUMER); 97 } 98 99 105 public MessageExchange createExchange(URI pattern) 106 throws MessagingException { 107 log.call(pattern); 108 109 if (!MessageExchangeImpl.IN_ONLY_PATTERN.equals(pattern) 110 && !MessageExchangeImpl.ROBUST_IN_ONLY_PATTERN.equals(pattern) 111 && !MessageExchangeImpl.IN_OUT_PATTERN.equals(pattern) 112 && !MessageExchangeImpl.IN_OPTIONAL_OUT_PATTERN.equals(pattern)) { 113 throw new MessagingException( 114 "This Message Exchange Pattern is not recognized by JBI."); 115 } 116 117 return createExchangeDecorator(createExchange(), pattern); 118 } 119 120 129 public MessageExchange createExchangeDecorator( 130 MessageExchangeImpl exchange, URI pattern) throws MessagingException { 131 log.call(pattern); 132 133 if (MessageExchangeImpl.IN_ONLY_PATTERN.equals(pattern)) { 134 return new InOnlyImpl(exchange, exchange.getRole()); 135 } else if (MessageExchangeImpl.ROBUST_IN_ONLY_PATTERN.equals(pattern)) { 136 return new RobustInOnlyImpl(exchange, exchange.getRole()); 137 } else if (MessageExchangeImpl.IN_OUT_PATTERN.equals(pattern)) { 138 return new InOutImpl(exchange, exchange.getRole()); 139 } else if (MessageExchangeImpl.IN_OPTIONAL_OUT_PATTERN.equals(pattern)) { 140 return new InOptionalOutImpl(exchange, exchange.getRole()); 141 } else { 142 return new MessageExchangeDecorator(exchange, exchange.getRole()); 143 } 144 } 145 146 152 public InOnly createInOnlyExchange() throws MessagingException { 153 log.call(); 154 155 MessageExchangeImpl msg = createExchange(); 156 157 return new InOnlyImpl(msg, Role.CONSUMER); 158 } 159 160 166 public InOptionalOut createInOptionalOutExchange() 167 throws MessagingException { 168 log.call(); 169 170 MessageExchangeImpl msg = createExchange(); 171 172 return new InOptionalOutImpl(msg, Role.CONSUMER); 173 } 174 175 181 public InOut createInOutExchange() throws MessagingException { 182 log.call(); 183 184 MessageExchangeImpl msg = createExchange(); 185 186 return new InOutImpl(msg, Role.CONSUMER); 187 } 188 189 195 public RobustInOnly createRobustInOnlyExchange() throws MessagingException { 196 log.call(); 197 198 MessageExchangeImpl msg = createExchange(); 199 200 return new RobustInOnlyImpl(msg, Role.CONSUMER); 201 } 202 203 public void setDefaultInterfaceName(QName defaultInterfaceName) { 204 this.defaultInterfaceName = defaultInterfaceName; 205 } 206 207 public void setDefaultServiceEndpoint(ServiceEndpoint defaultServiceEndpoint) { 208 this.defaultServiceEndpoint = defaultServiceEndpoint; 209 } 210 211 public void setDefaultServiceName(QName defaultServiceName) { 212 this.defaultServiceName = defaultServiceName; 213 } 214 215 222 protected MessageExchangeImpl createExchange() throws MessagingException { 223 log.call(); 224 225 channel.checkDeliveryChannelIsOpened(); 226 227 MessageExchangeImpl msg = new MessageExchangeImpl(consumerEndpoint); 228 229 setDefaultMessageExchangeProperties(msg); 230 231 msg.setExchangeId(createId()); 232 233 return msg; 234 } 235 236 240 247 protected void setDefaultMessageExchangeProperties(MessageExchangeImpl msg) { 248 log.call(); 249 250 if (defaultInterfaceName != null) { 251 msg.setInterfaceName(defaultInterfaceName); 252 } 253 if (defaultServiceName != null) { 254 msg.setService(defaultServiceName); 255 } 256 if (defaultServiceEndpoint != null) { 257 msg.setEndpoint(defaultServiceEndpoint); 258 } 259 260 } 261 262 private String createId() { 263 return "Petals.message.exchange.id." + System.currentTimeMillis(); 264 } 265 } 266 | Popular Tags |