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