git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/common/common-gcore-stubs/1.0@119181 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
03c097ddac
commit
3637558618
|
@ -1,15 +1,22 @@
|
|||
package org.gcube.common.clients.stubs.jaxws.proxies;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GenericProxyFactory {
|
||||
|
||||
private static Map<String, Object> proxyMap = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T, I extends T> T getProxy(Class<T> intf,
|
||||
final I obj) {
|
||||
return (T)
|
||||
Proxy.newProxyInstance(obj.getClass().getClassLoader(),
|
||||
new Class[] { intf },
|
||||
new MethodRetriever<I>(obj));
|
||||
if (proxyMap.containsKey(intf.getCanonicalName()))
|
||||
return (T) proxyMap.get(intf.getCanonicalName());
|
||||
T proxy = (T) Proxy.newProxyInstance(obj.getClass().getClassLoader(),
|
||||
new Class[] { intf },
|
||||
new MethodRetriever<I>(obj));
|
||||
proxyMap.put(intf.getCanonicalName(), proxy);
|
||||
return proxy;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue