1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.util.expression; |
12 | |
|
13 | |
import org.mule.api.MuleMessage; |
14 | |
import org.mule.api.MuleRuntimeException; |
15 | |
import org.mule.api.transformer.TransformerException; |
16 | |
import org.mule.api.transport.MessageAdapter; |
17 | |
import org.mule.config.i18n.CoreMessages; |
18 | |
import org.mule.util.ClassUtils; |
19 | |
import org.mule.util.StringUtils; |
20 | |
|
21 | |
import org.apache.commons.logging.Log; |
22 | |
import org.apache.commons.logging.LogFactory; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 1152 | public class MessagePayloadExpressionEvaluator implements ExpressionEvaluator |
44 | |
{ |
45 | |
public static final String NAME = "payload"; |
46 | |
public static final String BYTE_ARRAY = "byte[]"; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 1152 | protected transient final Log logger = LogFactory.getLog(MessagePayloadExpressionEvaluator.class); |
52 | |
|
53 | |
public Object evaluate(String expression, Object message) |
54 | |
{ |
55 | 36 | if (message instanceof MuleMessage) |
56 | |
{ |
57 | 28 | if (StringUtils.isEmpty(expression)) |
58 | |
{ |
59 | 22 | return ((MuleMessage) message).getPayload(); |
60 | |
} |
61 | |
else |
62 | |
{ |
63 | |
try |
64 | |
{ |
65 | 6 | if (expression.equals(BYTE_ARRAY)) |
66 | |
{ |
67 | 2 | return ((MuleMessage) message).getPayload(byte[].class); |
68 | |
} |
69 | |
else |
70 | |
{ |
71 | 4 | return ((MuleMessage) message).getPayload(ClassUtils.loadClass(expression, getClass())); |
72 | |
} |
73 | |
} |
74 | 0 | catch (TransformerException e) |
75 | |
{ |
76 | 0 | throw new MuleRuntimeException(CoreMessages.failedToProcessExtractorFunction(expression), e); |
77 | |
} |
78 | 0 | catch (ClassNotFoundException e) |
79 | |
{ |
80 | 0 | throw new MuleRuntimeException(CoreMessages.failedToProcessExtractorFunction(expression), e); |
81 | |
} |
82 | |
} |
83 | |
} |
84 | |
else |
85 | |
{ |
86 | 8 | logger.warn("Message is not of type MuleMessage, the expression will return the object without modification"); |
87 | 8 | if (message instanceof MessageAdapter) |
88 | |
{ |
89 | 0 | return ((MessageAdapter) message).getPayload(); |
90 | |
} |
91 | |
} |
92 | 8 | return message; |
93 | |
|
94 | |
} |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public String getName() |
100 | |
{ |
101 | 1146 | return NAME; |
102 | |
} |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
public void setName(String name) |
108 | |
{ |
109 | 0 | throw new UnsupportedOperationException("setName"); |
110 | |
} |
111 | |
} |