}
@Override
public final Object getService(Bundle bundle, ServiceRegistration registration)
{
Plugin plugin = pluginAccessor.getPlugin(OsgiHeaderUtil.getPluginKey(bundle));
if (plugin == null)
{
throw new IllegalArgumentException("Clients can only be used by plugins");
}
Set<String> permissions = permissionsReader.getPermissionsForPlugin(plugin);
BundleContext bundleContext = bundle.getBundleContext();
return clientClass.cast(Proxy.newProxyInstance(
new ChainingClassLoader(getClass().getClassLoader(), clientClass.getClassLoader()),
new Class[]{clientClass},
new ClientInvocationHandler(
"confluence2",
wrapService(bundleContext, HostXmlRpcClient.class, getClass().getClassLoader()),
permissions,
plugin.getKey(),
wrapService(bundleContext, HostHttpClient.class, getClass().getClassLoader()),
wrapService(bundleContext, RequestContext.class, getClass().getClassLoader()))));
}