1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.module.ibeans.config; |
8 | |
|
9 | |
import org.mule.MessageExchangePattern; |
10 | |
import org.mule.api.MuleException; |
11 | |
import org.mule.api.annotations.meta.Channel; |
12 | |
import org.mule.api.annotations.meta.ChannelType; |
13 | |
import org.mule.api.endpoint.InboundEndpoint; |
14 | |
import org.mule.api.endpoint.OutboundEndpoint; |
15 | |
import org.mule.config.endpoint.AbstractEndpointAnnotationParser; |
16 | |
import org.mule.config.endpoint.AnnotatedEndpointData; |
17 | |
import org.mule.module.ibeans.i18n.IBeansMessages; |
18 | |
import org.mule.module.ibeans.spi.support.CallOutboundEndpoint; |
19 | |
import org.mule.module.ibeans.spi.support.CallRequestEndpoint; |
20 | |
|
21 | |
import java.beans.ExceptionListener; |
22 | |
import java.lang.annotation.Annotation; |
23 | |
import java.lang.reflect.Member; |
24 | |
import java.lang.reflect.Method; |
25 | |
import java.util.Map; |
26 | |
|
27 | |
import org.ibeans.annotation.Call; |
28 | |
import org.ibeans.api.CallException; |
29 | |
import org.ibeans.api.ExceptionListenerAware; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 0 | public class CallAnnotationParser extends AbstractEndpointAnnotationParser |
35 | |
{ |
36 | |
protected AnnotatedEndpointData createEndpointData(Annotation annotation) throws MuleException |
37 | |
{ |
38 | 0 | Call call = (Call) annotation; |
39 | 0 | AnnotatedEndpointData epd = new AnnotatedEndpointData(MessageExchangePattern.REQUEST_RESPONSE, ChannelType.Outbound, call); |
40 | 0 | epd.setAddress(call.uri()); |
41 | 0 | epd.setProperties(AnnotatedEndpointData.convert(call.properties())); |
42 | 0 | return epd; |
43 | |
} |
44 | |
|
45 | |
protected String getIdentifier() |
46 | |
{ |
47 | 0 | return Call.class.getAnnotation(Channel.class).identifer(); |
48 | |
} |
49 | |
|
50 | |
@Override |
51 | |
public boolean supports(Annotation annotation, Class clazz, Member member) |
52 | |
{ |
53 | |
|
54 | 0 | boolean supports = clazz.isInterface(); |
55 | 0 | if (supports) |
56 | |
{ |
57 | 0 | supports = annotation instanceof Call; |
58 | |
} |
59 | 0 | if (supports) |
60 | |
{ |
61 | |
|
62 | 0 | if (ExceptionListenerAware.class.isAssignableFrom(clazz)) |
63 | |
{ |
64 | 0 | supports = true; |
65 | |
} |
66 | |
else |
67 | |
{ |
68 | 0 | Class[] exceptionTypes = ((Method) member).getExceptionTypes(); |
69 | 0 | boolean hasValidExceptionType = false; |
70 | 0 | for (int i = 0; i < exceptionTypes.length; i++) |
71 | |
{ |
72 | 0 | Class exceptionType = exceptionTypes[i]; |
73 | 0 | hasValidExceptionType = exceptionType.equals(Exception.class) || exceptionType.isAssignableFrom(CallException.class) || clazz.isAssignableFrom(ExceptionListener.class); |
74 | |
} |
75 | 0 | if (!hasValidExceptionType) |
76 | |
{ |
77 | 0 | throw new IllegalArgumentException(IBeansMessages.illegalCallMethod((Method)member).getMessage()); |
78 | |
} |
79 | |
} |
80 | |
} |
81 | 0 | return supports; |
82 | |
} |
83 | |
|
84 | |
public OutboundEndpoint parseOutboundEndpoint(Annotation annotation, Map metaInfo) throws MuleException |
85 | |
{ |
86 | 0 | AnnotatedEndpointData data = createEndpointData(annotation); |
87 | 0 | if (data.getConnectorName() == null) |
88 | |
{ |
89 | 0 | data.setConnectorName((String) metaInfo.get("connectorName")); |
90 | |
} |
91 | 0 | return new CallOutboundEndpoint(muleContext, data); |
92 | |
} |
93 | |
|
94 | |
public InboundEndpoint parseInboundEndpoint(Annotation annotation, Map metaInfo) throws MuleException |
95 | |
{ |
96 | 0 | AnnotatedEndpointData data = createEndpointData(annotation); |
97 | 0 | if (data.getConnectorName() == null) |
98 | |
{ |
99 | 0 | data.setConnectorName((String) metaInfo.get("connectorName")); |
100 | |
} |
101 | 0 | return new CallRequestEndpoint(muleContext, data); |
102 | |
} |
103 | |
} |