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 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 super.setEndpoint(uri, props);
35
36 int i = address.indexOf(".");
37 if(i ==-1)
38 {
39 throw new MalformedEndpointException(uri.toString());
40 }
41
42 String ibean = address.substring(0, i);
43 String method = address. substring(i+1);
44 IBeanHolder holder = muleContext.getRegistry().lookupObject(ibean);
45 if(holder == null)
46 {
47 throw new MalformedEndpointException(IBeansMessages.ibeanNotRegistered(ibean), uri.toString());
48 }
49 boolean match = false;
50 Method[] methods = holder.getIbeanClass().getMethods();
51 for (int j = 0; j < methods.length; j++)
52 {
53 Method m = methods[j];
54 if(m.getName().equals(method))
55 {
56 if(m.isAnnotationPresent(Call.class) || m.isAnnotationPresent(Template.class))
57 {
58 match = true;
59 break;
60 }
61 else
62 {
63 throw new MalformedEndpointException(IBeansMessages.ibeanMethodFoundButNotValid(ibean, method), uri.toString());
64 }
65 }
66 }
67 if(!match)
68 {
69 throw new MalformedEndpointException(IBeansMessages.ibeanMethodNotFound(ibean, method), uri.toString());
70 }
71 }
72
73 @Override
74 public EndpointURI build(URI uri, MuleContext muleContext) throws MalformedEndpointException
75 {
76 this.muleContext = muleContext;
77 return super.build(uri, muleContext);
78 }
79 }