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.InboundHeaders; |
14 | |
import org.mule.api.expression.ExpressionAnnotationParser; |
15 | |
import org.mule.expression.ExpressionConfig; |
16 | |
import org.mule.expression.MessageHeaderExpressionEvaluator; |
17 | |
import org.mule.expression.MessageHeadersExpressionEvaluator; |
18 | |
import org.mule.expression.MessageHeadersListExpressionEvaluator; |
19 | |
import org.mule.expression.transformers.ExpressionArgument; |
20 | |
|
21 | |
import java.lang.annotation.Annotation; |
22 | |
import java.util.List; |
23 | |
import java.util.Map; |
24 | |
|
25 | |
import static org.mule.expression.ExpressionConstants.OPTIONAL_ARGUMENT; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 0 | public class InboundHeadersAnnotationParser implements ExpressionAnnotationParser |
32 | |
{ |
33 | |
public ExpressionArgument parse(Annotation annotation, Class<?> parameterType) |
34 | |
{ |
35 | 0 | Evaluator evaluator = annotation.annotationType().getAnnotation(Evaluator.class); |
36 | |
|
37 | 0 | if (evaluator != null) |
38 | |
{ |
39 | 0 | String expr = ((InboundHeaders) annotation).value(); |
40 | |
|
41 | 0 | boolean optional = false; |
42 | 0 | String eval = MessageHeaderExpressionEvaluator.NAME; |
43 | 0 | if (parameterType.isAssignableFrom(Map.class)) |
44 | |
{ |
45 | 0 | eval = MessageHeadersExpressionEvaluator.NAME; |
46 | |
} |
47 | 0 | else if (parameterType.isAssignableFrom(List.class)) |
48 | |
{ |
49 | 0 | eval = MessageHeadersListExpressionEvaluator.NAME; |
50 | |
} |
51 | 0 | else if (expr.endsWith(OPTIONAL_ARGUMENT)) |
52 | |
{ |
53 | |
|
54 | |
|
55 | 0 | optional = true; |
56 | |
} |
57 | 0 | return new ExpressionArgument(null, new ExpressionConfig("INBOUND:" + expr, eval, null), optional, parameterType); |
58 | |
} |
59 | |
else |
60 | |
{ |
61 | 0 | throw new IllegalArgumentException("The @Evaluator annotation must be set on an Expression Annotation"); |
62 | |
} |
63 | |
} |
64 | |
|
65 | |
public boolean supports(Annotation annotation) |
66 | |
{ |
67 | 0 | return annotation instanceof InboundHeaders; |
68 | |
} |
69 | |
} |