1 10 11 package org.mule.providers.jbi; 12 13 import org.mule.providers.AbstractMessageAdapter; 14 import org.mule.umo.MessagingException; 15 import org.mule.umo.provider.MessageTypeNotSupportedException; 16 17 import javax.activation.DataHandler ; 18 import javax.jbi.messaging.NormalizedMessage; 19 20 import java.util.Iterator ; 21 import java.util.Set ; 22 23 30 31 public class JbiMessageAdapter extends AbstractMessageAdapter 32 { 33 36 private static final long serialVersionUID = 642776588124612798L; 37 38 private final NormalizedMessage message; 39 40 public JbiMessageAdapter(Object message) throws MessagingException 41 { 42 if (message instanceof NormalizedMessage) 43 { 44 this.message = (NormalizedMessage)message; 45 for (Iterator iterator = this.message.getPropertyNames().iterator(); iterator.hasNext();) 46 { 47 String key = (String )iterator.next(); 48 Object value = this.message.getProperty(key); 49 if (value != null) 50 { 51 setProperty(key, value); 52 } 53 } 54 } 55 else 56 { 57 throw new MessageTypeNotSupportedException(message, getClass()); 58 } 59 } 60 61 public void setProperty(Object key, Object value) 62 { 63 message.setProperty(key.toString(), value); 64 } 65 66 74 public String getPayloadAsString(String encoding) throws Exception 75 { 76 throw new UnsupportedOperationException ("getPayloadAsString"); 77 } 78 79 85 public byte[] getPayloadAsBytes() throws Exception 86 { 87 throw new UnsupportedOperationException ("getPayloadAsBytes"); 88 } 89 90 public Object getPayload() 91 { 92 return message; 93 } 94 95 public Object getProperty(Object key) 96 { 97 return message.getProperty(key.toString()); 98 } 99 100 public void addAttachment(String name, DataHandler dataHandler) throws Exception 101 { 102 message.addAttachment(name, dataHandler); 103 } 104 105 public void removeAttachment(String name) throws Exception 106 { 107 message.removeAttachment(name); 108 } 109 110 public DataHandler getAttachment(String name) 111 { 112 return message.getAttachment(name); 113 } 114 115 public Set getAttachmentNames() 116 { 117 return message.getAttachmentNames(); 118 } 119 120 } 121 | Popular Tags |