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