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