This commit is contained in:
Lucio Lelii 2015-09-29 15:16:54 +00:00
parent 03c097ddac
commit 3637558618
1 changed files with 11 additions and 4 deletions

View File

@ -1,15 +1,22 @@
package org.gcube.common.clients.stubs.jaxws.proxies; package org.gcube.common.clients.stubs.jaxws.proxies;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;
public class GenericProxyFactory { public class GenericProxyFactory {
private static Map<String, Object> proxyMap = new HashMap<>();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T, I extends T> T getProxy(Class<T> intf, public static <T, I extends T> T getProxy(Class<T> intf,
final I obj) { final I obj) {
return (T) if (proxyMap.containsKey(intf.getCanonicalName()))
Proxy.newProxyInstance(obj.getClass().getClassLoader(), return (T) proxyMap.get(intf.getCanonicalName());
new Class[] { intf }, T proxy = (T) Proxy.newProxyInstance(obj.getClass().getClassLoader(),
new MethodRetriever<I>(obj)); new Class[] { intf },
new MethodRetriever<I>(obj));
proxyMap.put(intf.getCanonicalName(), proxy);
return proxy;
} }
} }