1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.config.transformer; |
11 | |
|
12 | |
import org.mule.api.MuleContext; |
13 | |
import org.mule.api.MuleException; |
14 | |
import org.mule.api.annotations.ContainsTransformerMethods; |
15 | |
import org.mule.api.annotations.Transformer; |
16 | |
import org.mule.api.context.MuleContextAware; |
17 | |
import org.mule.api.registry.PreInitProcessor; |
18 | |
import org.mule.util.annotation.AnnotationMetaData; |
19 | |
import org.mule.util.annotation.AnnotationUtils; |
20 | |
|
21 | |
import java.lang.reflect.Method; |
22 | |
import java.util.List; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class AnnotatedTransformerObjectProcessor implements PreInitProcessor, MuleContextAware |
32 | |
{ |
33 | |
|
34 | |
private MuleContext muleContext; |
35 | |
|
36 | |
public AnnotatedTransformerObjectProcessor() |
37 | 0 | { |
38 | 0 | } |
39 | |
|
40 | |
public AnnotatedTransformerObjectProcessor(MuleContext muleContext) |
41 | 0 | { |
42 | 0 | setMuleContext(muleContext); |
43 | 0 | } |
44 | |
|
45 | |
public void setMuleContext(MuleContext context) |
46 | |
{ |
47 | 0 | this.muleContext = context; |
48 | 0 | } |
49 | |
|
50 | |
public Object process(Object object) |
51 | |
{ |
52 | 0 | Class<? extends Object> clazz = object.getClass(); |
53 | 0 | if (clazz.getAnnotation(ContainsTransformerMethods.class) == null) |
54 | |
{ |
55 | 0 | return object; |
56 | |
} |
57 | 0 | List<AnnotationMetaData> annos = AnnotationUtils.getMethodAnnotations(clazz, Transformer.class); |
58 | |
|
59 | 0 | if (annos.size() == 0) |
60 | |
{ |
61 | 0 | return object; |
62 | |
} |
63 | 0 | for (AnnotationMetaData data : annos) |
64 | |
{ |
65 | |
try |
66 | |
{ |
67 | 0 | Transformer anno = (Transformer) data.getAnnotation(); |
68 | 0 | AnnotatedTransformerProxy trans = new AnnotatedTransformerProxy( |
69 | |
anno.priorityWeighting(), |
70 | |
object, (Method) data.getMember(), anno.sourceTypes(), |
71 | |
null , null ); |
72 | |
|
73 | 0 | muleContext.getRegistry().registerTransformer(trans); |
74 | |
} |
75 | 0 | catch (MuleException e) |
76 | |
{ |
77 | 0 | throw new RuntimeException(e); |
78 | 0 | } |
79 | |
} |
80 | 0 | return object; |
81 | |
} |
82 | |
} |