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