1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.jbi;
12
13 import org.mule.impl.ThreadSafeAccess;
14 import org.mule.providers.AbstractMessageAdapter;
15 import org.mule.umo.MessagingException;
16 import org.mule.umo.provider.MessageTypeNotSupportedException;
17
18 import java.util.Iterator;
19 import java.util.Set;
20
21 import javax.activation.DataHandler;
22 import javax.jbi.messaging.NormalizedMessage;
23
24
25
26
27
28
29 public class JbiMessageAdapter extends AbstractMessageAdapter
30 {
31
32
33
34 private static final long serialVersionUID = 642776588124612798L;
35
36 private final NormalizedMessage message;
37
38 public JbiMessageAdapter(Object message) throws MessagingException
39 {
40 if (message instanceof NormalizedMessage)
41 {
42 this.message = (NormalizedMessage)message;
43 for (Iterator iterator = this.message.getPropertyNames().iterator(); iterator.hasNext();)
44 {
45 String key = (String)iterator.next();
46 Object value = this.message.getProperty(key);
47 if (value != null)
48 {
49 setProperty(key, value);
50 }
51 }
52 }
53 else
54 {
55 throw new MessageTypeNotSupportedException(message, getClass());
56 }
57 }
58
59 protected JbiMessageAdapter(JbiMessageAdapter template)
60 {
61 super(template);
62 message = template.message;
63 }
64
65 public void setProperty(Object key, Object value)
66 {
67 message.setProperty(key.toString(), value);
68 }
69
70
71
72
73
74
75
76
77
78 public String getPayloadAsString(String encoding) throws Exception
79 {
80 throw new UnsupportedOperationException("getPayloadAsString");
81 }
82
83
84
85
86
87
88
89 public byte[] getPayloadAsBytes() throws Exception
90 {
91 throw new UnsupportedOperationException("getPayloadAsBytes");
92 }
93
94 public Object getPayload()
95 {
96 return message;
97 }
98
99 public Object getProperty(Object key)
100 {
101 return message.getProperty(key.toString());
102 }
103
104 public void addAttachment(String name, DataHandler dataHandler) throws Exception
105 {
106 message.addAttachment(name, dataHandler);
107 }
108
109 public void removeAttachment(String name) throws Exception
110 {
111 message.removeAttachment(name);
112 }
113
114 public DataHandler getAttachment(String name)
115 {
116 return message.getAttachment(name);
117 }
118
119 public Set getAttachmentNames()
120 {
121 return message.getAttachmentNames();
122 }
123
124 public ThreadSafeAccess newThreadCopy()
125 {
126 return new JbiMessageAdapter(this);
127 }
128
129 }