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 public class InboundAttachmentsMap implements Map<String, DataHandler>
26 {
27 private MuleMessage message;
28
29 public InboundAttachmentsMap(MuleMessage message)
30 {
31 this.message = message;
32 }
33
34 public int size()
35 {
36 return message.getInboundAttachmentNames().size();
37 }
38
39 public boolean isEmpty()
40 {
41 return message.getInboundAttachmentNames().size() == 0;
42 }
43
44 public boolean containsKey(Object key)
45 {
46 return message.getInboundAttachmentNames().contains(key.toString());
47 }
48
49 public boolean containsValue(Object value)
50 {
51 return values().contains(value);
52 }
53
54 public DataHandler get(Object key)
55 {
56 return message.getInboundAttachment(key.toString());
57 }
58
59 public DataHandler put(String key, DataHandler value)
60 {
61 throw new UnsupportedOperationException("put(): Inbound attachments are read-only");
62 }
63
64
65 public DataHandler remove(Object key)
66 {
67 throw new UnsupportedOperationException("remove(): Inbound attachments are read-only");
68 }
69
70
71 public void putAll(Map<? extends String, ? extends DataHandler> map)
72 {
73 for (Entry<? extends String, ? extends DataHandler> entry : map.entrySet())
74 {
75 put(entry.getKey(), entry.getValue());
76 }
77 }
78
79 public void clear()
80 {
81 throw new UnsupportedOperationException("clear");
82 }
83
84 public Set<String> keySet()
85 {
86 return message.getInboundAttachmentNames();
87 }
88
89 public Collection<DataHandler> values()
90 {
91 return getAttachments().values();
92 }
93
94 public Set<Entry<String, DataHandler>> entrySet()
95 {
96 return getAttachments().entrySet();
97 }
98
99
100 private Map<String, DataHandler> getAttachments()
101 {
102 Map<String, DataHandler> props = new HashMap<String, DataHandler>();
103 for (String s : message.getInboundAttachmentNames())
104 {
105 props.put(s, message.getInboundAttachment(s));
106 }
107 return props;
108 }
109 }