package org.gcube.common.clients.builders; import java.net.URI; import java.net.URL; import java.util.concurrent.TimeUnit; import javax.xml.ws.wsaddressing.W3CEndpointReference; import org.gcube.common.clients.builders.StatefulBuilderAPI.Builder; import org.gcube.common.clients.builders.StatefulBuilderAPI.FinalClause; import org.gcube.common.clients.builders.StatefulBuilderAPI.SecondClause; import org.gcube.common.clients.cache.EndpointCache; import org.gcube.common.clients.config.Property; import org.gcube.common.clients.delegates.ProxyPlugin; import org.gcube.common.clients.queries.Query; /** * Partial implementation of proxy builders for stateful services. * * @author Fabio Simeoni * * @param the type of service addresses * @param the type of service stubs * @param

the type of service proxies */ public abstract class AbstractStatefulBuilder extends AbstractBuilder implements Builder,SecondClause

,FinalClause

{ /** * Constructs an instance with a given {@link ProxyPlugin}, and {@link EndpointCache}, and zero or more default {@link Property}s. * @param plugin the plugin * @param plugin the cache * @param properties the properties */ protected AbstractStatefulBuilder(ProxyPlugin plugin, EndpointCache cache,Property ... properties) { super(plugin,cache,properties); } @Override public SecondClause

matching(Query query) { setQuery(query); return this; }; @Override public SecondClause

at(W3CEndpointReference address) { setAddress(address); return this; } @Override public SecondClause

at(String key, String host, int port) { setAddress(AddressingUtils.address(contextPath(),plugin().name(), plugin().namespace(), key, host, port)); return this; } @Override public SecondClause

at(String key, URL address) { setAddress(AddressingUtils.address(contextPath(),plugin().name(), plugin().namespace(), key, address)); return this; } @Override public SecondClause

at(String key, URI address) { this.setAddress(AddressingUtils.address(contextPath(),plugin().name(), plugin().namespace(), key, address)); return this; } @Override public FinalClause

withTimeout(int duration, TimeUnit unit) { setTimeout((int) unit.toMillis(duration)); return this; } @Override public SecondClause

with(Property property) { addProperty(property); return this; } @Override public SecondClause

with(String name, T value) { addProperty(new Property(name, value)); return this; } }