1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.config.expression; |
11 | |
|
12 | |
import org.mule.api.MuleContext; |
13 | |
import org.mule.api.expression.ExpressionAnnotationParser; |
14 | |
import org.mule.api.lifecycle.InitialisationException; |
15 | |
import org.mule.api.registry.RegistrationException; |
16 | |
import org.mule.api.transformer.TransformerException; |
17 | |
import org.mule.config.AnnotationsParserFactory; |
18 | |
import org.mule.config.i18n.AnnotationsMessages; |
19 | |
import org.mule.expression.transformers.ExpressionArgument; |
20 | |
import org.mule.expression.transformers.ExpressionTransformer; |
21 | |
|
22 | |
import java.lang.annotation.Annotation; |
23 | |
import java.lang.reflect.Method; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 0 | public class ExpressionAnnotationsHelper |
29 | |
{ |
30 | |
public static ExpressionTransformer getTransformerForMethodWithAnnotations(Method method, MuleContext context) throws TransformerException, InitialisationException |
31 | |
{ |
32 | 0 | ExpressionTransformer trans = new ExpressionTransformer(); |
33 | 0 | trans.setMuleContext(context); |
34 | |
|
35 | 0 | Annotation[][] annotations = method.getParameterAnnotations(); |
36 | |
|
37 | 0 | for (int i = 0; i < annotations.length; i++) |
38 | |
{ |
39 | 0 | Annotation[] annotation = annotations[i]; |
40 | 0 | for (int j = 0; j < annotation.length; j++) |
41 | |
{ |
42 | 0 | Annotation ann = annotation[j]; |
43 | 0 | ExpressionArgument arg = parseAnnotation(ann, method.getParameterTypes()[i], context); |
44 | |
|
45 | 0 | trans.addArgument(arg); |
46 | |
} |
47 | |
} |
48 | 0 | trans.initialise(); |
49 | 0 | return trans; |
50 | |
} |
51 | |
|
52 | |
static synchronized ExpressionArgument parseAnnotation(Annotation annotation, |
53 | |
Class<?> paramType, MuleContext muleContext) |
54 | |
{ |
55 | |
AnnotationsParserFactory factory; |
56 | |
try |
57 | |
{ |
58 | 0 | factory = muleContext.getRegistry().lookupObject(AnnotationsParserFactory.class); |
59 | |
} |
60 | 0 | catch (RegistrationException e) |
61 | |
{ |
62 | |
|
63 | 0 | throw new IllegalArgumentException(AnnotationsMessages.noParserFoundForAnnotation(annotation).getMessage()); |
64 | 0 | } |
65 | |
|
66 | 0 | ExpressionAnnotationParser parser = factory.getExpressionParser(annotation); |
67 | 0 | if (parser == null) |
68 | |
{ |
69 | 0 | throw new IllegalArgumentException(AnnotationsMessages.noParserFoundForAnnotation(annotation).getMessage()); |
70 | |
} |
71 | 0 | return parser.parse(annotation, paramType); |
72 | |
} |
73 | |
} |