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