1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.transport.ibean; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.endpoint.EndpointURI; |
11 | |
import org.mule.api.endpoint.MalformedEndpointException; |
12 | |
import org.mule.endpoint.ResourceNameEndpointURIBuilder; |
13 | |
import org.mule.module.ibeans.config.IBeanHolder; |
14 | |
import org.mule.module.ibeans.i18n.IBeansMessages; |
15 | |
|
16 | |
import java.lang.reflect.Method; |
17 | |
import java.net.URI; |
18 | |
import java.util.Properties; |
19 | |
|
20 | |
import org.ibeans.annotation.Call; |
21 | |
import org.ibeans.annotation.Template; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | 0 | public class IBeansEndpointURIBuilder extends ResourceNameEndpointURIBuilder |
28 | |
{ |
29 | |
private MuleContext muleContext; |
30 | |
|
31 | |
@Override |
32 | |
protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException |
33 | |
{ |
34 | 0 | super.setEndpoint(uri, props); |
35 | |
|
36 | 0 | int i = address.indexOf("."); |
37 | 0 | if(i ==-1) |
38 | |
{ |
39 | 0 | throw new MalformedEndpointException(uri.toString()); |
40 | |
} |
41 | |
|
42 | 0 | String ibean = address.substring(0, i); |
43 | 0 | String method = address. substring(i+1); |
44 | 0 | IBeanHolder holder = muleContext.getRegistry().lookupObject(ibean); |
45 | 0 | if(holder == null) |
46 | |
{ |
47 | 0 | throw new MalformedEndpointException(IBeansMessages.ibeanNotRegistered(ibean), uri.toString()); |
48 | |
} |
49 | 0 | boolean match = false; |
50 | 0 | Method[] methods = holder.getIbeanClass().getMethods(); |
51 | 0 | for (int j = 0; j < methods.length; j++) |
52 | |
{ |
53 | 0 | Method m = methods[j]; |
54 | 0 | if(m.getName().equals(method)) |
55 | |
{ |
56 | 0 | if(m.isAnnotationPresent(Call.class) || m.isAnnotationPresent(Template.class)) |
57 | |
{ |
58 | 0 | match = true; |
59 | 0 | break; |
60 | |
} |
61 | |
else |
62 | |
{ |
63 | 0 | throw new MalformedEndpointException(IBeansMessages.ibeanMethodFoundButNotValid(ibean, method), uri.toString()); |
64 | |
} |
65 | |
} |
66 | |
} |
67 | 0 | if(!match) |
68 | |
{ |
69 | 0 | throw new MalformedEndpointException(IBeansMessages.ibeanMethodNotFound(ibean, method), uri.toString()); |
70 | |
} |
71 | 0 | } |
72 | |
|
73 | |
@Override |
74 | |
public EndpointURI build(URI uri, MuleContext muleContext) throws MalformedEndpointException |
75 | |
{ |
76 | 0 | this.muleContext = muleContext; |
77 | 0 | return super.build(uri, muleContext); |
78 | |
} |
79 | |
} |