1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.expression; |
12 | |
|
13 | |
import org.mule.api.MuleMessage; |
14 | |
import org.mule.api.expression.ExpressionEvaluator; |
15 | |
import org.mule.api.expression.RequiredValueException; |
16 | |
import org.mule.config.i18n.CoreMessages; |
17 | |
|
18 | |
import javax.activation.DataHandler; |
19 | |
|
20 | |
import static org.mule.expression.ExpressionConstants.OPTIONAL_ARGUMENT; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 0 | public class MessageAttachmentExpressionEvaluator implements ExpressionEvaluator |
31 | |
{ |
32 | |
public static final String NAME = "attachment"; |
33 | |
|
34 | |
public Object evaluate(String expression, MuleMessage message) |
35 | |
{ |
36 | 0 | if (expression == null) |
37 | |
{ |
38 | 0 | return null; |
39 | |
} |
40 | |
|
41 | |
boolean required; |
42 | 0 | if (expression.endsWith(OPTIONAL_ARGUMENT)) |
43 | |
{ |
44 | 0 | expression = expression.substring(0, expression.length() - OPTIONAL_ARGUMENT.length()); |
45 | 0 | required = false; |
46 | |
} |
47 | |
else |
48 | |
{ |
49 | 0 | required = true; |
50 | |
} |
51 | 0 | DataHandler dh = message.getInboundAttachment(expression); |
52 | |
|
53 | 0 | if (dh == null && required) |
54 | |
{ |
55 | 0 | throw new RequiredValueException(CoreMessages.expressionEvaluatorReturnedNull(NAME, expression)); |
56 | |
} |
57 | 0 | return dh; |
58 | |
} |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
public String getName() |
64 | |
{ |
65 | 0 | return NAME; |
66 | |
} |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
public void setName(String name) |
72 | |
{ |
73 | 0 | throw new UnsupportedOperationException(); |
74 | |
} |
75 | |
} |