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