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