KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > soap > ServiceProxy


1 /*
2  * $Id: ServiceProxy.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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 JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Arrays JavaDoc;
23 import java.util.List JavaDoc;
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  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
31  * @version $Revision: 3798 $
32  */

33
34 public class ServiceProxy
35 {
36     public static Class JavaDoc[] getInterfacesForComponent(UMOComponent component)
37         throws UMOException, ClassNotFoundException JavaDoc
38     {
39         Class JavaDoc[] interfaces;
40         List JavaDoc ifaces = (List JavaDoc)component.getDescriptor().getProperties().get("serviceInterfaces");
41         if (ifaces == null || ifaces.size() == 0)
42         {
43             final Class JavaDoc implementationClass = component.getDescriptor().getImplementationClass();
44             // get all implemented interfaces from superclasses as well
45
final List JavaDoc intfList = ClassUtils.getAllInterfaces(implementationClass);
46             interfaces = (Class JavaDoc[])intfList.toArray(new Class JavaDoc[intfList.size()]);
47
48         }
49         else
50         {
51             interfaces = new Class JavaDoc[ifaces.size()];
52             for (int i = 0; i < ifaces.size(); i++)
53             {
54                 String JavaDoc iface = (String JavaDoc)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 JavaDoc[] removeInterface(Class JavaDoc[] interfaces, Class JavaDoc iface)
66     {
67         if (interfaces == null)
68         {
69             return null;
70         }
71         List JavaDoc results = new ArrayList JavaDoc();
72         for (int i = 0; i < interfaces.length; i++)
73         {
74             Class JavaDoc anInterface = interfaces[i];
75             if (!anInterface.equals(iface))
76             {
77                 results.add(anInterface);
78             }
79         }
80         Class JavaDoc[] arResults = new Class JavaDoc[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 JavaDoc[] getMethods(Class JavaDoc[] interfaces)
93     {
94         List JavaDoc methodNames = new ArrayList JavaDoc();
95         for (int i = 0; i < interfaces.length; i++)
96         {
97             methodNames.addAll(Arrays.asList(interfaces[i].getMethods()));
98         }
99         Method JavaDoc[] results = new Method JavaDoc[methodNames.size()];
100         return (Method JavaDoc[])methodNames.toArray(results);
101
102     }
103
104     public static String JavaDoc[] getMethodNames(Class JavaDoc[] interfaces)
105     {
106         Method JavaDoc[] methods = getMethods(interfaces);
107
108         String JavaDoc[] results = new String JavaDoc[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