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