1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.config.endpoint; |
11 | |
|
12 | |
import org.mule.api.EndpointAnnotationParser; |
13 | |
import org.mule.api.MessageProcessorAnnotationParser; |
14 | |
import org.mule.api.MuleContext; |
15 | |
import org.mule.api.MuleRuntimeException; |
16 | |
import org.mule.api.context.MuleContextAware; |
17 | |
import org.mule.api.expression.ExpressionAnnotationParser; |
18 | |
import org.mule.api.registry.ObjectProcessor; |
19 | |
import org.mule.api.registry.RegistrationException; |
20 | |
import org.mule.config.AnnotationsParserFactory; |
21 | |
import org.mule.config.i18n.CoreMessages; |
22 | |
|
23 | |
import java.lang.annotation.Annotation; |
24 | |
import java.lang.reflect.Member; |
25 | |
import java.util.Collection; |
26 | |
|
27 | |
import org.apache.commons.logging.Log; |
28 | |
import org.apache.commons.logging.LogFactory; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 0 | public class RegistryBackedAnnotationsParserFactory implements AnnotationsParserFactory, MuleContextAware |
35 | |
{ |
36 | |
|
37 | |
|
38 | |
|
39 | 0 | protected transient final Log logger = LogFactory.getLog(RegistryBackedAnnotationsParserFactory.class); |
40 | |
|
41 | |
protected MuleContext muleContext; |
42 | |
|
43 | |
public void setMuleContext(MuleContext context) |
44 | |
{ |
45 | 0 | this.muleContext = context; |
46 | 0 | } |
47 | |
|
48 | |
public EndpointAnnotationParser getEndpointParser(Annotation annotation, Class aClass, Member member) |
49 | |
{ |
50 | 0 | Collection<EndpointAnnotationParser> parsers = muleContext.getRegistry().lookupObjects(EndpointAnnotationParser.class); |
51 | 0 | for (EndpointAnnotationParser parser : parsers) |
52 | |
{ |
53 | 0 | if (parser.supports(annotation, aClass, member)) |
54 | |
{ |
55 | 0 | return parser; |
56 | |
} |
57 | |
} |
58 | 0 | return null; |
59 | |
} |
60 | |
|
61 | |
public ExpressionAnnotationParser getExpressionParser(Annotation annotation) |
62 | |
{ |
63 | 0 | Collection<ExpressionAnnotationParser> parsers = muleContext.getRegistry().lookupObjects(ExpressionAnnotationParser.class); |
64 | 0 | for (ExpressionAnnotationParser parser : parsers) |
65 | |
{ |
66 | 0 | if (parser.supports(annotation)) |
67 | |
{ |
68 | 0 | return parser; |
69 | |
} |
70 | |
} |
71 | 0 | return null; |
72 | |
} |
73 | |
|
74 | |
public MessageProcessorAnnotationParser getRouterParser(Annotation annotation, Class aClass, Member member) |
75 | |
{ |
76 | 0 | Collection<MessageProcessorAnnotationParser> parsers = muleContext.getRegistry().lookupObjects(MessageProcessorAnnotationParser.class); |
77 | 0 | for (MessageProcessorAnnotationParser parser : parsers) |
78 | |
{ |
79 | 0 | if (parser.supports(annotation, aClass, member)) |
80 | |
{ |
81 | 0 | return parser; |
82 | |
} |
83 | |
} |
84 | 0 | return null; |
85 | |
} |
86 | |
|
87 | |
protected void registerObjectProcessor(ObjectProcessor processor) |
88 | |
{ |
89 | |
try |
90 | |
{ |
91 | 0 | muleContext.getRegistry().registerObject("_" + processor.getClass().getSimpleName(), processor); |
92 | |
} |
93 | 0 | catch (RegistrationException e) |
94 | |
{ |
95 | 0 | throw new MuleRuntimeException(CoreMessages.failedToCreate(processor.getClass().getName()), e); |
96 | 0 | } |
97 | 0 | } |
98 | |
|
99 | |
} |