1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ksb.messaging; |
17 | |
|
18 | |
import java.lang.reflect.InvocationHandler; |
19 | |
import java.lang.reflect.InvocationTargetException; |
20 | |
import java.lang.reflect.Method; |
21 | |
import java.lang.reflect.Proxy; |
22 | |
|
23 | |
import javax.xml.namespace.QName; |
24 | |
|
25 | |
import org.apache.log4j.Logger; |
26 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class KSBClientProxy implements InvocationHandler { |
37 | |
|
38 | 0 | private static final Logger LOG = Logger.getLogger(KSBClientProxy.class); |
39 | |
|
40 | |
QName serviceName; |
41 | |
Object service; |
42 | |
|
43 | |
@SuppressWarnings("unchecked") |
44 | |
public static <T> T newInstance(String serviceQName, Class<T> interfaceClass) throws InstantiationException, IllegalAccessException { |
45 | 0 | return (T)Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class[] { interfaceClass }, new KSBClientProxy(serviceQName)); |
46 | |
} |
47 | |
|
48 | 0 | public KSBClientProxy(String serviceQName){ |
49 | 0 | this.serviceName = QName.valueOf(serviceQName); |
50 | 0 | } |
51 | |
|
52 | |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { |
53 | 0 | if (this.service == null){ |
54 | 0 | LOG.info("Getting service using GRL for: " + serviceName); |
55 | 0 | service = GlobalResourceLoader.getService(serviceName); |
56 | 0 | LOG.info("Obtained service using GRL for: " + serviceName); |
57 | |
} |
58 | |
try { |
59 | 0 | return method.invoke(service, args); |
60 | 0 | } catch (InvocationTargetException e) { |
61 | 0 | throw e.getCause(); |
62 | |
} |
63 | |
} |
64 | |
|
65 | |
} |