1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.soap;
12
13 import org.mule.umo.UMOComponent;
14 import org.mule.umo.UMOException;
15 import org.mule.umo.lifecycle.Callable;
16 import org.mule.umo.lifecycle.Disposable;
17 import org.mule.umo.lifecycle.Initialisable;
18 import org.mule.util.ClassUtils;
19
20 import java.lang.reflect.Method;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24
25
26
27
28
29
30
31 public class ServiceProxy
32 {
33
34 public static Class[] getInterfacesForComponent(UMOComponent component)
35 throws UMOException, ClassNotFoundException
36 {
37 Class[] interfaces;
38 List ifaces = (List)component.getDescriptor().getProperties().get("serviceInterfaces");
39 if (ifaces == null || ifaces.size() == 0)
40 {
41 final Class implementationClass = component.getDescriptor().getImplementationClass();
42
43 final List intfList = ClassUtils.getAllInterfaces(implementationClass);
44 interfaces = (Class[])intfList.toArray(new Class[intfList.size()]);
45
46 }
47 else
48 {
49 interfaces = new Class[ifaces.size()];
50 for (int i = 0; i < ifaces.size(); i++)
51 {
52 String iface = (String)ifaces.get(i);
53 interfaces[i] = ClassUtils.loadClass(iface, ServiceProxy.class);
54 }
55 }
56
57 interfaces = removeInterface(interfaces, Callable.class);
58 interfaces = removeInterface(interfaces, Disposable.class);
59 interfaces = removeInterface(interfaces, Initialisable.class);
60 return interfaces;
61 }
62
63 public static Class[] removeInterface(Class[] interfaces, Class iface)
64 {
65 if (interfaces == null)
66 {
67 return null;
68 }
69 List results = new ArrayList();
70 for (int i = 0; i < interfaces.length; i++)
71 {
72 Class anInterface = interfaces[i];
73 if (!anInterface.equals(iface))
74 {
75 results.add(anInterface);
76 }
77 }
78 Class[] arResults = new Class[results.size()];
79 if (arResults.length == 0)
80 {
81 return arResults;
82 }
83 else
84 {
85 results.toArray(arResults);
86 return arResults;
87 }
88 }
89
90 public static Method[] getMethods(Class[] interfaces)
91 {
92 List methodNames = new ArrayList();
93 for (int i = 0; i < interfaces.length; i++)
94 {
95 methodNames.addAll(Arrays.asList(interfaces[i].getMethods()));
96 }
97 Method[] results = new Method[methodNames.size()];
98 return (Method[])methodNames.toArray(results);
99
100 }
101
102 public static String[] getMethodNames(Class[] interfaces)
103 {
104 Method[] methods = getMethods(interfaces);
105
106 String[] results = new String[methods.length];
107 for (int i = 0; i < results.length; i++)
108 {
109 results[i] = methods[i].getName();
110 }
111 return results;
112 }
113 }