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 | 0 | public class ServiceProxy |
32 | |
{ |
33 | |
|
34 | |
public static Class[] getInterfacesForComponent(UMOComponent component) |
35 | |
throws UMOException, ClassNotFoundException |
36 | |
{ |
37 | |
Class[] interfaces; |
38 | 0 | List ifaces = (List)component.getDescriptor().getProperties().get("serviceInterfaces"); |
39 | 0 | if (ifaces == null || ifaces.size() == 0) |
40 | |
{ |
41 | 0 | final Class implementationClass = component.getDescriptor().getImplementationClass(); |
42 | |
|
43 | 0 | final List intfList = ClassUtils.getAllInterfaces(implementationClass); |
44 | 0 | interfaces = (Class[])intfList.toArray(new Class[intfList.size()]); |
45 | |
|
46 | 0 | } |
47 | |
else |
48 | |
{ |
49 | 0 | interfaces = new Class[ifaces.size()]; |
50 | 0 | for (int i = 0; i < ifaces.size(); i++) |
51 | |
{ |
52 | 0 | String iface = (String)ifaces.get(i); |
53 | 0 | interfaces[i] = ClassUtils.loadClass(iface, ServiceProxy.class); |
54 | |
} |
55 | |
} |
56 | |
|
57 | 0 | interfaces = removeInterface(interfaces, Callable.class); |
58 | 0 | interfaces = removeInterface(interfaces, Disposable.class); |
59 | 0 | interfaces = removeInterface(interfaces, Initialisable.class); |
60 | 0 | return interfaces; |
61 | |
} |
62 | |
|
63 | |
public static Class[] removeInterface(Class[] interfaces, Class iface) |
64 | |
{ |
65 | 0 | if (interfaces == null) |
66 | |
{ |
67 | 0 | return null; |
68 | |
} |
69 | 0 | List results = new ArrayList(); |
70 | 0 | for (int i = 0; i < interfaces.length; i++) |
71 | |
{ |
72 | 0 | Class anInterface = interfaces[i]; |
73 | 0 | if (!anInterface.equals(iface)) |
74 | |
{ |
75 | 0 | results.add(anInterface); |
76 | |
} |
77 | |
} |
78 | 0 | Class[] arResults = new Class[results.size()]; |
79 | 0 | if (arResults.length == 0) |
80 | |
{ |
81 | 0 | return arResults; |
82 | |
} |
83 | |
else |
84 | |
{ |
85 | 0 | results.toArray(arResults); |
86 | 0 | return arResults; |
87 | |
} |
88 | |
} |
89 | |
|
90 | |
public static Method[] getMethods(Class[] interfaces) |
91 | |
{ |
92 | 0 | List methodNames = new ArrayList(); |
93 | 0 | for (int i = 0; i < interfaces.length; i++) |
94 | |
{ |
95 | 0 | methodNames.addAll(Arrays.asList(interfaces[i].getMethods())); |
96 | |
} |
97 | 0 | Method[] results = new Method[methodNames.size()]; |
98 | 0 | return (Method[])methodNames.toArray(results); |
99 | |
|
100 | |
} |
101 | |
|
102 | |
public static String[] getMethodNames(Class[] interfaces) |
103 | |
{ |
104 | 0 | Method[] methods = getMethods(interfaces); |
105 | |
|
106 | 0 | String[] results = new String[methods.length]; |
107 | 0 | for (int i = 0; i < results.length; i++) |
108 | |
{ |
109 | 0 | results[i] = methods[i].getName(); |
110 | |
} |
111 | 0 | return results; |
112 | |
} |
113 | |
} |