1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.expression; |
11 | |
|
12 | |
import org.mule.api.MuleMessage; |
13 | |
|
14 | |
import java.util.Collection; |
15 | |
import java.util.HashMap; |
16 | |
import java.util.Map; |
17 | |
import java.util.Set; |
18 | |
|
19 | |
import javax.activation.DataHandler; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | 0 | public class OutboundAttachmentsMap implements Map<String, DataHandler> |
26 | |
{ |
27 | |
private MuleMessage message; |
28 | |
|
29 | |
public OutboundAttachmentsMap(MuleMessage message) |
30 | 0 | { |
31 | 0 | this.message = message; |
32 | 0 | } |
33 | |
|
34 | |
public int size() |
35 | |
{ |
36 | 0 | return message.getOutboundAttachmentNames().size(); |
37 | |
} |
38 | |
|
39 | |
public boolean isEmpty() |
40 | |
{ |
41 | 0 | return message.getOutboundAttachmentNames().size() == 0; |
42 | |
} |
43 | |
|
44 | |
public boolean containsKey(Object key) |
45 | |
{ |
46 | 0 | return message.getOutboundAttachmentNames().contains(key.toString()); |
47 | |
} |
48 | |
|
49 | |
public boolean containsValue(Object value) |
50 | |
{ |
51 | 0 | return values().contains(value); |
52 | |
} |
53 | |
|
54 | |
public DataHandler get(Object key) |
55 | |
{ |
56 | 0 | return message.getOutboundAttachment(key.toString()); |
57 | |
} |
58 | |
|
59 | |
public DataHandler put(String key, DataHandler value) |
60 | |
{ |
61 | |
try |
62 | |
{ |
63 | 0 | message.addOutboundAttachment(key, value); |
64 | 0 | return value; |
65 | |
} |
66 | 0 | catch (Exception e) |
67 | |
{ |
68 | |
|
69 | 0 | throw new RuntimeException(e); |
70 | |
} |
71 | |
} |
72 | |
|
73 | |
public DataHandler put(String key, Object value, String contentType) |
74 | |
{ |
75 | |
try |
76 | |
{ |
77 | 0 | message.addOutboundAttachment(key, value, contentType); |
78 | 0 | return get(key); |
79 | |
} |
80 | 0 | catch (Exception e) |
81 | |
{ |
82 | |
|
83 | 0 | throw new RuntimeException(e); |
84 | |
} |
85 | |
} |
86 | |
|
87 | |
|
88 | |
public DataHandler remove(Object key) |
89 | |
{ |
90 | 0 | DataHandler attachment = message.getOutboundAttachment(key.toString()); |
91 | |
try |
92 | |
{ |
93 | 0 | message.removeOutboundAttachment(key.toString()); |
94 | |
} |
95 | 0 | catch (Exception e) |
96 | |
{ |
97 | |
|
98 | 0 | } |
99 | 0 | return attachment; |
100 | |
} |
101 | |
|
102 | |
|
103 | |
public void putAll(Map<? extends String, ? extends DataHandler> map) |
104 | |
{ |
105 | 0 | for (Entry<? extends String, ? extends DataHandler> entry : map.entrySet()) |
106 | |
{ |
107 | 0 | put(entry.getKey(), entry.getValue()); |
108 | |
} |
109 | 0 | } |
110 | |
|
111 | |
public void clear() |
112 | |
{ |
113 | 0 | throw new UnsupportedOperationException("clear"); |
114 | |
} |
115 | |
|
116 | |
public Set<String> keySet() |
117 | |
{ |
118 | 0 | return message.getOutboundAttachmentNames(); |
119 | |
} |
120 | |
|
121 | |
public Collection<DataHandler> values() |
122 | |
{ |
123 | 0 | return getAttachments().values(); |
124 | |
} |
125 | |
|
126 | |
public Set<Entry<String, DataHandler>> entrySet() |
127 | |
{ |
128 | 0 | return getAttachments().entrySet(); |
129 | |
} |
130 | |
|
131 | |
|
132 | |
private Map<String, DataHandler> getAttachments() |
133 | |
{ |
134 | 0 | Map<String, DataHandler> props = new HashMap<String, DataHandler>(); |
135 | 0 | for (String s : message.getOutboundAttachmentNames()) |
136 | |
{ |
137 | 0 | props.put(s, message.getOutboundAttachment(s)); |
138 | |
} |
139 | 0 | return props; |
140 | |
} |
141 | |
} |