1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.config.parsers; |
8 | |
|
9 | |
import org.mule.api.annotations.meta.Evaluator; |
10 | |
import org.mule.api.annotations.param.InboundAttachments; |
11 | |
import org.mule.api.expression.ExpressionAnnotationParser; |
12 | |
import org.mule.expression.ExpressionConfig; |
13 | |
import org.mule.expression.MessageAttachmentExpressionEvaluator; |
14 | |
import org.mule.expression.MessageAttachmentsExpressionEvaluator; |
15 | |
import org.mule.expression.MessageAttachmentsListExpressionEvaluator; |
16 | |
import org.mule.expression.transformers.ExpressionArgument; |
17 | |
|
18 | |
import java.lang.annotation.Annotation; |
19 | |
import java.util.List; |
20 | |
import java.util.Map; |
21 | |
|
22 | |
import static org.mule.expression.ExpressionConstants.OPTIONAL_ARGUMENT; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 0 | public class InboundAttachmentsAnnotationParser implements ExpressionAnnotationParser |
29 | |
{ |
30 | |
public ExpressionArgument parse(Annotation annotation, Class<?> parameterType) |
31 | |
{ |
32 | 0 | Evaluator evaluator = annotation.annotationType().getAnnotation(Evaluator.class); |
33 | 0 | if (evaluator != null) |
34 | |
{ |
35 | 0 | String expr = ((InboundAttachments) annotation).value(); |
36 | 0 | boolean optional = false; |
37 | |
|
38 | |
|
39 | 0 | String eval = MessageAttachmentExpressionEvaluator.NAME; |
40 | 0 | if (parameterType.isAssignableFrom(Map.class)) |
41 | |
{ |
42 | 0 | eval = MessageAttachmentsExpressionEvaluator.NAME; |
43 | |
} |
44 | 0 | else if (parameterType.isAssignableFrom(List.class)) |
45 | |
{ |
46 | 0 | eval = MessageAttachmentsListExpressionEvaluator.NAME; |
47 | |
} |
48 | 0 | else if(expr.endsWith(OPTIONAL_ARGUMENT)) |
49 | |
{ |
50 | |
|
51 | |
|
52 | 0 | optional = true; |
53 | |
} |
54 | 0 | return new ExpressionArgument(null, new ExpressionConfig(expr, eval, null), optional, parameterType); |
55 | |
} |
56 | |
else |
57 | |
{ |
58 | 0 | throw new IllegalArgumentException("The @Evaluator annotation must be set on an Expression Annotation"); |
59 | |
} |
60 | |
} |
61 | |
|
62 | |
public boolean supports(Annotation annotation) |
63 | |
{ |
64 | 0 | return annotation instanceof InboundAttachments; |
65 | |
} |
66 | |
} |