1 10 11 package org.mule.impl; 12 13 import org.mule.MuleRuntimeException; 14 import org.mule.config.i18n.Message; 15 import org.mule.config.i18n.Messages; 16 import org.mule.providers.DefaultMessageAdapter; 17 import org.mule.umo.UMOExceptionPayload; 18 import org.mule.umo.UMOMessage; 19 import org.mule.umo.provider.UMOMessageAdapter; 20 21 import javax.activation.DataHandler ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 import java.util.Set ; 25 26 33 34 public class MuleMessage implements UMOMessage 35 { 36 39 private static final long serialVersionUID = 1541720810851984842L; 40 41 private UMOMessageAdapter adapter; 42 43 protected UMOExceptionPayload exceptionPayload; 44 45 public MuleMessage(Object message) 46 { 47 this(message, (Map )null); 48 } 49 50 public MuleMessage(Object message, Map properties) 51 { 52 if (message instanceof UMOMessageAdapter) 53 { 54 adapter = (UMOMessageAdapter)message; 55 } 56 else 57 { 58 adapter = new DefaultMessageAdapter(message); 59 } 60 addProperties(properties); 61 } 62 63 public MuleMessage(Object message, UMOMessageAdapter previous) 64 { 65 if (message instanceof UMOMessageAdapter) 66 { 67 adapter = (UMOMessageAdapter)message; 68 } 69 else 70 { 71 adapter = new DefaultMessageAdapter(message, previous); 72 } 73 if (previous.getExceptionPayload() != null) 74 { 75 setExceptionPayload(previous.getExceptionPayload()); 76 } 77 setEncoding(previous.getEncoding()); 78 if (previous.getAttachmentNames().size() > 0) 79 { 80 Set attNames = adapter.getAttachmentNames(); 81 synchronized (attNames) 82 { 83 for (Iterator iterator = attNames.iterator(); iterator.hasNext();) 84 { 85 String s = (String )iterator.next(); 86 try 87 { 88 addAttachment(s, adapter.getAttachment(s)); 89 } 90 catch (Exception e) 91 { 92 throw new MuleRuntimeException(new Message(Messages.FAILED_TO_READ_ATTACHMENT_X, s), 93 e); 94 } 95 } 96 } 97 } 98 } 99 100 public UMOMessageAdapter getAdapter() 101 { 102 return adapter; 103 } 104 105 111 public Object getProperty(String key) 112 { 113 return adapter.getProperty(key); 114 } 115 116 public Object removeProperty(String key) 117 { 118 return adapter.removeProperty(key); 119 } 120 121 127 public void setProperty(String key, Object value) 128 { 129 adapter.setProperty(key, value); 130 } 131 132 138 public String getPayloadAsString() throws Exception 139 { 140 return adapter.getPayloadAsString(); 141 } 142 143 151 public String getPayloadAsString(String encoding) throws Exception 152 { 153 if (encoding == null) 154 { 155 return adapter.getPayloadAsString(); 156 } 157 else 158 { 159 return adapter.getPayloadAsString(encoding); 160 } 161 } 162 163 166 public Set getPropertyNames() 167 { 168 return adapter.getPropertyNames(); 169 } 170 171 177 public byte[] getPayloadAsBytes() throws Exception 178 { 179 return adapter.getPayloadAsBytes(); 180 } 181 182 185 public Object getPayload() 186 { 187 return adapter.getPayload(); 188 } 189 190 public void addProperties(Map properties) 191 { 192 adapter.addProperties(properties); 193 } 194 195 public void clearProperties() 196 { 197 adapter.clearProperties(); 198 } 199 200 207 public double getDoubleProperty(String name, double defaultValue) 208 { 209 return adapter.getDoubleProperty(name, defaultValue); 210 } 211 212 218 public void setDoubleProperty(String name, double value) 219 { 220 adapter.setDoubleProperty(name, value); 221 } 222 223 public String getUniqueId() 224 { 225 return adapter.getUniqueId(); 226 } 227 228 public Object getProperty(String name, Object defaultValue) 229 { 230 return adapter.getProperty(name, defaultValue); 231 } 232 233 public int getIntProperty(String name, int defaultValue) 234 { 235 return adapter.getIntProperty(name, defaultValue); 236 } 237 238 public long getLongProperty(String name, long defaultValue) 239 { 240 return adapter.getLongProperty(name, defaultValue); 241 } 242 243 public boolean getBooleanProperty(String name, boolean defaultValue) 244 { 245 return adapter.getBooleanProperty(name, defaultValue); 246 } 247 248 public void setBooleanProperty(String name, boolean value) 249 { 250 adapter.setBooleanProperty(name, value); 251 } 252 253 public void setIntProperty(String name, int value) 254 { 255 adapter.setIntProperty(name, value); 256 } 257 258 public void setLongProperty(String name, long value) 259 { 260 adapter.setLongProperty(name, value); 261 } 262 263 274 public void setCorrelationId(String id) 275 { 276 adapter.setCorrelationId(id); 277 } 278 279 291 public String getCorrelationId() 292 { 293 return adapter.getCorrelationId(); 294 } 295 296 304 public void setReplyTo(Object replyTo) 305 { 306 adapter.setReplyTo(replyTo); 307 } 308 309 317 public Object getReplyTo() 318 { 319 return adapter.getReplyTo(); 320 } 321 322 328 public int getCorrelationSequence() 329 { 330 return adapter.getCorrelationSequence(); 331 } 332 333 339 public void setCorrelationSequence(int sequence) 340 { 341 adapter.setCorrelationSequence(sequence); 342 } 343 344 349 public int getCorrelationGroupSize() 350 { 351 return adapter.getCorrelationGroupSize(); 352 } 353 354 359 public void setCorrelationGroupSize(int size) 360 { 361 adapter.setCorrelationGroupSize(size); 362 } 363 364 public UMOExceptionPayload getExceptionPayload() 365 { 366 return exceptionPayload; 367 } 368 369 public void setExceptionPayload(UMOExceptionPayload exceptionPayload) 370 { 371 this.exceptionPayload = exceptionPayload; 372 } 373 374 public String toString() 375 { 376 return adapter.toString(); 377 } 378 379 public void addAttachment(String name, DataHandler dataHandler) throws Exception 380 { 381 adapter.addAttachment(name, dataHandler); 382 } 383 384 public void removeAttachment(String name) throws Exception 385 { 386 adapter.removeAttachment(name); 387 } 388 389 public DataHandler getAttachment(String name) 390 { 391 return adapter.getAttachment(name); 392 } 393 394 public Set getAttachmentNames() 395 { 396 return adapter.getAttachmentNames(); 397 } 398 399 407 public String getEncoding() 408 { 409 return adapter.getEncoding(); 410 } 411 412 417 public void setEncoding(String encoding) 418 { 419 adapter.setEncoding(encoding); 420 } 421 422 429 public String getStringProperty(String name, String defaultValue) 430 { 431 return adapter.getStringProperty(name, defaultValue); 432 } 433 434 440 public void setStringProperty(String name, String value) 441 { 442 adapter.setStringProperty(name, value); 443 } 444 } 445 | Popular Tags |