1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.expression; |
8 | |
|
9 | |
import org.mule.api.MuleMessage; |
10 | |
import org.mule.api.expression.ExpressionEvaluator; |
11 | |
import org.mule.api.transport.PropertyScope; |
12 | |
|
13 | |
import java.util.Collection; |
14 | |
import java.util.HashMap; |
15 | |
import java.util.Map; |
16 | |
import java.util.Set; |
17 | |
|
18 | |
import org.apache.commons.logging.Log; |
19 | |
import org.apache.commons.logging.LogFactory; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | 0 | public class OutboundHeadersExpressionEvaluator implements ExpressionEvaluator |
26 | |
{ |
27 | |
public static final String NAME = "outboundHeaders"; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | protected transient final Log logger = LogFactory.getLog(OutboundHeadersExpressionEvaluator.class); |
33 | |
|
34 | |
|
35 | |
public Object evaluate(String expression, MuleMessage message) |
36 | |
{ |
37 | 0 | if (message == null) |
38 | |
{ |
39 | 0 | return null; |
40 | |
} |
41 | 0 | return new SendHeadersMap(message); |
42 | |
} |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public String getName() |
48 | |
{ |
49 | 0 | return NAME; |
50 | |
} |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public void setName(String name) |
56 | |
{ |
57 | 0 | throw new UnsupportedOperationException("name"); |
58 | |
} |
59 | |
|
60 | |
|
61 | 0 | public static class SendHeadersMap implements Map<String, Object> |
62 | |
{ |
63 | |
private MuleMessage message; |
64 | |
|
65 | |
public SendHeadersMap(MuleMessage message) |
66 | 0 | { |
67 | 0 | this.message = message; |
68 | 0 | } |
69 | |
|
70 | |
public int size() |
71 | |
{ |
72 | 0 | return message.getOutboundPropertyNames().size(); |
73 | |
} |
74 | |
|
75 | |
public boolean isEmpty() |
76 | |
{ |
77 | 0 | return message.getOutboundPropertyNames().size() == 0; |
78 | |
} |
79 | |
|
80 | |
public boolean containsKey(Object key) |
81 | |
{ |
82 | 0 | return message.getOutboundPropertyNames().contains(key.toString()); |
83 | |
} |
84 | |
|
85 | |
public boolean containsValue(Object value) |
86 | |
{ |
87 | 0 | return values().contains(value); |
88 | |
} |
89 | |
|
90 | |
public Object get(Object key) |
91 | |
{ |
92 | 0 | return message.getOutboundProperty(key.toString()); |
93 | |
} |
94 | |
|
95 | |
public Object put(String key, Object value) |
96 | |
{ |
97 | 0 | message.setOutboundProperty(key, value); |
98 | 0 | return value; |
99 | |
} |
100 | |
|
101 | |
|
102 | |
public Object remove(Object key) |
103 | |
{ |
104 | 0 | return message.removeProperty(key.toString(), PropertyScope.OUTBOUND); |
105 | |
} |
106 | |
|
107 | |
|
108 | |
public void putAll(Map<? extends String, ?> t) |
109 | |
{ |
110 | 0 | for (Entry<? extends String, ?> entry : t.entrySet()) |
111 | |
{ |
112 | 0 | put(entry.getKey(), entry.getValue()); |
113 | |
} |
114 | 0 | } |
115 | |
|
116 | |
public void clear() |
117 | |
{ |
118 | 0 | message.clearProperties(PropertyScope.OUTBOUND); |
119 | 0 | } |
120 | |
|
121 | |
public Set<String> keySet() |
122 | |
{ |
123 | 0 | return message.getOutboundPropertyNames(); |
124 | |
} |
125 | |
|
126 | |
public Collection<Object> values() |
127 | |
{ |
128 | 0 | return getPropertiesInScope(PropertyScope.OUTBOUND).values(); |
129 | |
} |
130 | |
|
131 | |
public Set<Entry<String, Object>> entrySet() |
132 | |
{ |
133 | 0 | return getPropertiesInScope(PropertyScope.OUTBOUND).entrySet(); |
134 | |
} |
135 | |
|
136 | |
|
137 | |
private Map<String, Object> getPropertiesInScope(PropertyScope scope) |
138 | |
{ |
139 | 0 | Map<String, Object> props = new HashMap<String, Object>(); |
140 | 0 | for (String s : message.getPropertyNames(scope)) |
141 | |
{ |
142 | 0 | props.put(s, message.getProperty(s, scope)); |
143 | |
} |
144 | 0 | return props; |
145 | |
} |
146 | |
} |
147 | |
} |