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