1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport; |
12 | |
|
13 | |
import org.mule.api.MuleRuntimeException; |
14 | |
import org.mule.api.ThreadSafeAccess; |
15 | |
import org.mule.api.transport.MessageAdapter; |
16 | |
import org.mule.api.transport.MutableMessageAdapter; |
17 | |
import org.mule.config.i18n.CoreMessages; |
18 | |
|
19 | |
import java.util.Iterator; |
20 | |
import java.util.Map; |
21 | |
|
22 | |
import javax.activation.DataHandler; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public final class DefaultMessageAdapter extends AbstractMessageAdapter implements MutableMessageAdapter |
31 | |
{ |
32 | |
|
33 | |
|
34 | |
|
35 | |
private static final long serialVersionUID = 1908152148142575505L; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
protected Object message; |
41 | |
|
42 | |
|
43 | |
protected DefaultMessageAdapter() |
44 | |
{ |
45 | 0 | super(); |
46 | 0 | } |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public DefaultMessageAdapter(Object message) |
56 | 714 | { |
57 | 714 | if (message == null) |
58 | |
{ |
59 | 12 | this.message = NullPayload.getInstance(); |
60 | |
} |
61 | |
else |
62 | |
{ |
63 | 702 | this.message = message; |
64 | |
} |
65 | 714 | } |
66 | |
|
67 | |
public DefaultMessageAdapter(Object message, MessageAdapter previous) |
68 | |
{ |
69 | 318 | super(previous); |
70 | 318 | if (previous != null) |
71 | |
{ |
72 | 318 | if (message == null) |
73 | |
{ |
74 | 0 | this.message = NullPayload.getInstance(); |
75 | |
} |
76 | |
else |
77 | |
{ |
78 | 318 | this.message = message; |
79 | |
} |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | 318 | for (Iterator iterator = previous.getAttachmentNames().iterator(); iterator.hasNext();) |
85 | |
{ |
86 | 0 | String name = (String) iterator.next(); |
87 | |
try |
88 | |
{ |
89 | 0 | DataHandler dh = previous.getAttachment(name); |
90 | 0 | if (null == dh) |
91 | |
{ |
92 | 0 | logger.warn("Detected concurrent access to attachment " + name + " for " + previous); |
93 | |
|
94 | |
} |
95 | |
else |
96 | |
{ |
97 | 0 | addAttachment(name, dh); |
98 | |
} |
99 | |
} |
100 | 0 | catch (Exception e) |
101 | |
{ |
102 | 0 | throw new MuleRuntimeException(CoreMessages.failedToReadPayload(), e); |
103 | 0 | } |
104 | 0 | } |
105 | 318 | for (Iterator iterator = previous.getPropertyNames().iterator(); iterator.hasNext();) |
106 | |
{ |
107 | 102 | String name = (String) iterator.next(); |
108 | |
try |
109 | |
{ |
110 | 102 | Object value = previous.getProperty(name); |
111 | 102 | if (null == value) |
112 | |
{ |
113 | 0 | logger.warn("Detected concurrent access to property " + name + " for " + previous); |
114 | |
|
115 | |
} |
116 | |
else |
117 | |
{ |
118 | 102 | setProperty(name, value); |
119 | |
} |
120 | |
} |
121 | 0 | catch (Exception e) |
122 | |
{ |
123 | 0 | throw new MuleRuntimeException(CoreMessages.failedToReadPayload(), e); |
124 | 102 | } |
125 | 102 | } |
126 | |
} |
127 | |
else |
128 | |
{ |
129 | 0 | throw new IllegalArgumentException("previousAdapter may not be null"); |
130 | |
} |
131 | 318 | } |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
public DefaultMessageAdapter(Object message, Map properties, Map attachments) |
145 | |
{ |
146 | 0 | this(message); |
147 | 0 | if (properties != null) |
148 | |
{ |
149 | 0 | this.properties.addInboundProperties(properties); |
150 | |
} |
151 | 0 | if (attachments != null) |
152 | |
{ |
153 | 0 | this.attachments.putAll(attachments); |
154 | |
} |
155 | 0 | } |
156 | |
|
157 | |
|
158 | |
public Object getPayload() |
159 | |
{ |
160 | 2104 | return message; |
161 | |
} |
162 | |
|
163 | |
|
164 | |
public void setPayload(Object payload) |
165 | |
{ |
166 | 172 | synchronized(message) |
167 | |
{ |
168 | 172 | message = payload; |
169 | 172 | } |
170 | 172 | } |
171 | |
|
172 | |
|
173 | |
public String getUniqueId() |
174 | |
{ |
175 | 434 | return id; |
176 | |
} |
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
public ThreadSafeAccess newThreadCopy() |
182 | |
{ |
183 | 280 | return new DefaultMessageAdapter(getPayload(), this); |
184 | |
} |
185 | |
|
186 | |
} |