Coverage Report - org.mule.providers.soap.ServiceProxy
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceProxy
0%
0/37
0%
0/26
3.5
 
 1  
 /*
 2  
  * $Id: ServiceProxy.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 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  
  * <code>ServiceProxy</code> is a proxy that wraps a soap endpointUri to look like
 27  
  * a Web service. Also provides helper methods for building and describing web
 28  
  * service interfaces in Mule.
 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  
             // get all implemented interfaces from superclasses as well
 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  
 }