1 25 26 package org.objectweb.petals.jbi.messaging; 27 28 import java.net.URI ; 29 import java.util.Set ; 30 31 import javax.jbi.messaging.ExchangeStatus; 32 import javax.jbi.messaging.Fault; 33 import javax.jbi.messaging.MessageExchange; 34 import javax.jbi.messaging.MessagingException; 35 import javax.jbi.messaging.NormalizedMessage; 36 import javax.jbi.servicedesc.ServiceEndpoint; 37 import javax.xml.namespace.QName ; 38 39 56 public class MessageExchangeDecorator implements MessageExchange { 57 58 protected MessageExchangeImpl messageExchange; 59 60 64 protected Role observerRole; 65 66 73 protected boolean waitingOnSynchronousSend; 74 75 82 public MessageExchangeDecorator(MessageExchangeImpl me, Role observerRole) { 83 this.messageExchange = me; 84 85 this.observerRole = observerRole; 86 } 87 88 91 public Fault createFault() throws MessagingException { 92 checkComponentOwnsExchange(); 93 94 return messageExchange.createFault(); 95 } 96 97 100 public NormalizedMessage createMessage() throws MessagingException { 101 checkComponentOwnsExchange(); 102 103 return messageExchange.createMessage(); 104 } 105 106 109 public ServiceEndpoint getEndpoint() { 110 checkComponentOwnsExchange(); 111 112 return messageExchange.getEndpoint(); 113 } 114 115 118 public Exception getError() { 119 checkComponentOwnsExchange(); 120 121 return messageExchange.getError(); 122 } 123 124 127 public String getExchangeId() { 128 checkComponentOwnsExchange(); 129 130 return messageExchange.getExchangeId(); 131 } 132 133 136 public Fault getFault() { 137 checkComponentOwnsExchange(); 138 139 return messageExchange.getFault(); 140 } 141 142 145 public QName getInterfaceName() { 146 checkComponentOwnsExchange(); 147 148 return messageExchange.getInterfaceName(); 149 } 150 151 154 public NormalizedMessage getMessage(String name) { 155 checkComponentOwnsExchange(); 156 157 return messageExchange.getMessage(name); 158 } 159 160 165 public MessageExchangeImpl getMessageExchange() { 166 return messageExchange; 167 } 168 169 175 public Role getObserverRole() { 176 return observerRole; 177 } 178 179 182 public QName getOperation() { 183 checkComponentOwnsExchange(); 184 185 return messageExchange.getOperation(); 186 } 187 188 191 public URI getPattern() { 192 checkComponentOwnsExchange(); 193 194 return messageExchange.getPattern(); 195 } 196 197 200 public Object getProperty(String name) { 201 checkComponentOwnsExchange(); 202 203 return messageExchange.getProperty(name); 204 } 205 206 209 public Set getPropertyNames() { 210 checkComponentOwnsExchange(); 211 212 return messageExchange.getPropertyNames(); 213 } 214 215 218 public Role getRole() { 219 checkComponentOwnsExchange(); 220 221 return messageExchange.getRole(); 222 } 223 224 227 public QName getService() { 228 checkComponentOwnsExchange(); 229 230 return messageExchange.getService(); 231 } 232 233 236 public javax.jbi.messaging.ExchangeStatus getStatus() { 237 return messageExchange.getStatus(); 238 } 239 240 246 public boolean hasOwnership() { 247 return messageExchange.getRole().equals(observerRole); 248 } 249 250 253 public boolean isTransacted() { 254 checkComponentOwnsExchange(); 255 256 return messageExchange.isTransacted(); 257 } 258 259 public boolean isWaitingOnSynchronousSend() { 260 return waitingOnSynchronousSend; 261 } 262 263 266 public void setEndpoint(ServiceEndpoint endpoint) { 267 checkComponentOwnsExchange(); 268 269 messageExchange.setEndpoint(endpoint); 270 } 271 272 275 public void setError(Exception error) { 276 checkComponentOwnsExchange(); 277 278 messageExchange.setError(error); 279 } 280 281 284 public void setFault(Fault fault) throws MessagingException { 285 checkComponentOwnsExchange(); 286 287 messageExchange.setFault(fault); 288 } 289 290 public void setInterfaceName(QName interfaceName) { 291 checkComponentOwnsExchange(); 292 293 messageExchange.setInterfaceName(interfaceName); 294 } 295 296 300 public void setMessage(NormalizedMessage msg, String name) 301 throws MessagingException { 302 checkComponentOwnsExchange(); 303 304 messageExchange.setMessage(msg, name); 305 } 306 307 311 314 public void setOperation(QName name) { 315 checkComponentOwnsExchange(); 316 317 messageExchange.setOperation(name); 318 } 319 320 324 public void setProperty(String name, Object obj) { 325 checkComponentOwnsExchange(); 326 327 messageExchange.setProperty(name, obj); 328 } 329 330 333 public void setService(QName service) { 334 checkComponentOwnsExchange(); 335 336 messageExchange.setService(service); 337 } 338 339 342 public void setStatus(ExchangeStatus status) throws MessagingException { 343 checkComponentOwnsExchange(); 344 345 messageExchange.setStatus(status); 346 } 347 348 public void setWaitingOnSynchronousSend(boolean waitingOnSynchronousSend) { 349 this.waitingOnSynchronousSend = waitingOnSynchronousSend; 350 } 351 352 353 public void setMessageExchange(MessageExchangeImpl messageExchange) { 354 this.messageExchange = messageExchange; 355 } 356 357 363 protected void checkComponentOwnsExchange() throws IllegalStateException { 364 if (!hasOwnership()) { 365 throw new IllegalStateException ( 366 "The component does not owns the MessageExchange"); 367 } 368 } 369 370 } 371 | Popular Tags |