final ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(loader);
Class aProxyClass = loader.loadClass(proxyClassName);
AssociationProxy aProxy = (AssociationProxy)aProxyClass.newInstance();
List<Class> list = loadAssociatedInterfaces(association.getAssociationDescriptor(), loader);
aProxy.setProxyInterfaces(list.toArray(new Class[list.size()]));
list.add(AssociationProxy.class);
if(strategyClassName!=null) {
ServiceSelectionStrategy strategy =
(ServiceSelectionStrategy)loader.loadClass(strategyClassName).newInstance();
strategy.setAssociation(association);
aProxy.setServiceSelectionStrategy(strategy);
}
Class[] interfaces = list.toArray(new Class[list.size()]);
proxy = Proxy.newProxyInstance(loader, interfaces, aProxy.getInvocationHandler(association));
} finally {
Thread.currentThread().setContextClassLoader(currentCL);
}
return proxy;
}