package org.gcube.common.clients.gcore.plugins; import java.rmi.Remote; import org.apache.axis.client.Stub; import org.apache.axis.message.addressing.EndpointReferenceType; import org.gcube.common.clients.config.ProxyConfig; import org.gcube.common.clients.delegates.ProxyDelegate; import org.gcube.common.core.contexts.GCUBERemotePortTypeContext; import org.gcube.common.core.scope.GCUBEScopeManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A {@link Plugin} that adapts an existing {@link Plugin}. * * @author Fabio Simeoni * * @param the type of service stubs * @param

the type of service proxies * */ public final class PluginAdapter implements Plugin { private static Logger log = LoggerFactory.getLogger(PluginAdapter.class); private final Plugin plugin; public PluginAdapter(Plugin plugin) { this.plugin=plugin; } /** * Returns the name of the service porttype. * @return the name */ public String name() { return plugin.name(); } /** * Returns the gCube name of the service. * @return the name */ public String serviceClass() { return plugin.serviceClass(); } /** * Returns the gCube class of the service. * @return the class */ public String serviceName() { return plugin.serviceName(); } /** * Returns the namespace of the service * @return the namespace */ public String namespace() { return plugin.namespace(); } @Override public S resolve(EndpointReferenceType address, ProxyConfig config) throws Exception { S stub = plugin.resolve(address,config); Remote remote = null; //add scope if (stub instanceof Remote) { try { remote = GCUBERemotePortTypeContext.getProxy((Remote) stub,GCUBEScopeManager.DEFAULT); } catch(Exception e) { throw new RuntimeException(e); } //set timeout if (remote instanceof Stub) ((Stub) remote).setTimeout((int)config.timeout()); else log.warn("could not set timeout on stub of {} as {} does not implement the org.apache.axis.client.Stub interface",name(),stub); } else log.error("could not set scope and timeout on stub of {} as {} does not implement the java.rmi.Remote interface",name(),stub); return stub; } @Override public Exception convert(Exception fault,ProxyConfig config) { // TODO gcore-specific fault analysis return plugin.convert(fault,config); } @Override public P newProxy(ProxyDelegate config) { return plugin.newProxy(config); } }