KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > webservice > WebServiceInvoker


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * WebServiceInvoker.java
20  *
21  * The web service invoker inherits from the RPCProvider and is responsible for
22  * making the final call on the web service. Doing this makes it responsible for
23  * setting the thread context loader appropriatly so that the RMI stubs can be
24  * loaded from the appropriat jars.
25  */

26
27 // The path to the package
28
package com.rift.coad.lib.webservice;
29
30 // java imports
31
import java.lang.reflect.Method JavaDoc;
32
33 // axis imports
34
import org.apache.axis.MessageContext;
35 import org.apache.axis.providers.java.RPCProvider;
36
37 /**
38  * The web service invoker inherits from the RPCProvider and is responsible for
39  * making the final call on the web service. Doing this makes it responsible for
40  * setting the thread context loader appropriatly so that the RMI stubs can be
41  * loaded from the appropriat jars.
42  *
43  * @author Brett Chaldecott
44  */

45 public class WebServiceInvoker extends RPCProvider {
46     
47     // the reference to the class loader
48
private ClassLoader JavaDoc classLoader = null;
49     
50     /**
51      * Creates a new instance of WebServiceInvoker
52      */

53     public WebServiceInvoker(ClassLoader JavaDoc classLoader) {
54         this.classLoader = classLoader;
55     }
56     
57     
58     /**
59      * This method encapsulates the method invocation.
60      *
61      * @return The object resulting from the call.
62      * @param msgContext The message context for this call.
63      * @param method The reference to the method to invoke.
64      * @param obj The target object to invoke the method on.
65      * @param argValues The method parameters.
66      * @exception Exception
67      */

68     protected Object JavaDoc invokeMethod(MessageContext msgContext, Method JavaDoc method,
69             Object JavaDoc obj, Object JavaDoc[] argValues) throws Exception JavaDoc {
70         ClassLoader JavaDoc originalClassLoader = Thread.currentThread().
71                 getContextClassLoader();
72         try {
73             Thread.currentThread().setContextClassLoader(this.classLoader);
74             return method.invoke(obj,argValues);
75         } finally {
76             Thread.currentThread().setContextClassLoader(originalClassLoader);
77         }
78     }
79     
80 }
81
Popular Tags