jtulach@292: package org.apidesign.aserverinfo.cummulativefactory; jtulach@292: jtulach@292: import org.apidesign.aserverinfo.spi.NameProvider; jtulach@292: import org.apidesign.aserverinfo.spi.ResetHandler; jtulach@292: import org.apidesign.aserverinfo.spi.URLProvider; jtulach@292: import java.net.URL; jtulach@292: import org.apidesign.aserverinfo.spi.ShutdownHandler; jtulach@292: jtulach@292: // BEGIN: aserverinfo.api jtulach@292: /** A class to connect to server, identify it and manipulate with jtulach@300: * its state. The Practical API Design jtulach@292: * book used to call it AServerInfo. jtulach@292: *

jtulach@292: */ jtulach@292: public final class ServerConnector { jtulach@292: public String getName() { jtulach@292: return name == null ? "noname" : name.getName(); jtulach@292: } jtulach@292: jtulach@292: public URL getURL() { jtulach@292: return url == null ? null : url.getURL(); jtulach@292: } jtulach@292: jtulach@292: public void reset() { jtulach@292: if (reset != null) { jtulach@292: reset.reset(); jtulach@292: } jtulach@292: } jtulach@292: jtulach@292: /** Additional method for API clients not available from first version. jtulach@292: * @since 2.0 jtulach@292: */ jtulach@292: public void shutdown() { jtulach@292: if (shutdown != null) { jtulach@292: shutdown.shutdown(); jtulach@292: } jtulach@292: } jtulach@292: // FINISH: aserverinfo.api jtulach@292: jtulach@292: // jtulach@292: // cumulative factory methods jtulach@292: // jtulach@292: jtulach@292: // BEGIN: aserverinfo.cumulative.factory jtulach@292: public static ServerConnector empty() { jtulach@292: return new ServerConnector(null, null, null, null); jtulach@292: } jtulach@292: jtulach@292: public final ServerConnector nameProvider(NameProvider np) { jtulach@292: return new ServerConnector(np, this.url, this.reset, this.shutdown); jtulach@292: } jtulach@292: jtulach@292: public final ServerConnector urlProvider(URLProvider up) { jtulach@292: return new ServerConnector(this.name, up, this.reset, this.shutdown); jtulach@292: } jtulach@292: public final ServerConnector reset(ResetHandler h) { jtulach@292: return new ServerConnector(this.name, this.url, h, this.shutdown); jtulach@292: } jtulach@292: /** All one needs to do when there is a need to add new jtulach@292: * style of creation is to add new clonning method. jtulach@292: * @param handler jtulach@292: * @return jtulach@292: * @since 2.0 jtulach@292: */ jtulach@292: public final ServerConnector shutdown(ShutdownHandler handler) { jtulach@292: return new ServerConnector(this.name, this.url, this.reset, handler); jtulach@292: } jtulach@292: // END: aserverinfo.cumulative.factory jtulach@292: jtulach@292: // jtulach@292: // private part jtulach@292: // jtulach@292: jtulach@292: private final NameProvider name; jtulach@292: private final URLProvider url; jtulach@292: private final ResetHandler reset; jtulach@292: private final ShutdownHandler shutdown; jtulach@292: jtulach@292: private ServerConnector( jtulach@292: NameProvider name, URLProvider url, jtulach@292: ResetHandler reset, ShutdownHandler shutdown jtulach@292: ) { jtulach@292: this.name = name; jtulach@292: this.url = url; jtulach@292: this.reset = reset; jtulach@292: this.shutdown = shutdown; jtulach@292: } jtulach@292: }