1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/aserverinfo/src/org/apidesign/aserverinfo/builder/ServerInfo.java Sat Nov 15 08:19:20 2008 +0100
1.3 @@ -0,0 +1,67 @@
1.4 +package org.apidesign.aserverinfo.builder;
1.5 +
1.6 +import org.apidesign.aserverinfo.spi.NameProvider;
1.7 +import org.apidesign.aserverinfo.spi.ResetHandler;
1.8 +import org.apidesign.aserverinfo.spi.ShutdownHandler;
1.9 +import org.apidesign.aserverinfo.spi.URLProvider;
1.10 +
1.11 +/**
1.12 + *
1.13 + * @author Jaroslav Tulach <jtulach@netbeans.org>
1.14 + */
1.15 +public class ServerInfo {
1.16 +
1.17 + //
1.18 + // cumulative factory methods for the builder pattern
1.19 + //
1.20 +
1.21 + // BEGIN: aserverinfo.builder.factory
1.22 + public static ServerInfo empty() {
1.23 + return new ServerInfo(null, null, null, null);
1.24 + }
1.25 +
1.26 + public final ServerInfo nameProvider(NameProvider np) {
1.27 + return new ServerInfo(np, this.url, this.reset, this.shutdown);
1.28 + }
1.29 +
1.30 + public final ServerInfo urlProvider(URLProvider up) {
1.31 + return new ServerInfo(this.name, up, this.reset, this.shutdown);
1.32 + }
1.33 + public final ServerInfo reset(ResetHandler h) {
1.34 + return new ServerInfo(this.name, this.url, h, this.shutdown);
1.35 + }
1.36 + /** All one needs to do when there is a need to add new
1.37 + * style of creation is to add new method for a builder.
1.38 + * @param handler
1.39 + * @return
1.40 + * @since 2.0
1.41 + */
1.42 + public final ServerInfo shutdown(ShutdownHandler handler) {
1.43 + return new ServerInfo(this.name, this.url, this.reset, handler);
1.44 + }
1.45 +
1.46 + /** Creates the server connector based on current values in the
1.47 + * info. Builder factory method.
1.48 + * @return server connector
1.49 + */
1.50 + public final ServerConnector connect() {
1.51 + return new ServerConnector(name, url, reset, shutdown);
1.52 + }
1.53 + // END: aserverinfo.builder.factory
1.54 +
1.55 + private final NameProvider name;
1.56 + private final URLProvider url;
1.57 + private final ResetHandler reset;
1.58 + private final ShutdownHandler shutdown;
1.59 +
1.60 + private ServerInfo(
1.61 + NameProvider name, URLProvider url,
1.62 + ResetHandler reset, ShutdownHandler shutdown
1.63 + ) {
1.64 + this.name = name;
1.65 + this.url = url;
1.66 + this.reset = reset;
1.67 + this.shutdown = shutdown;
1.68 + }
1.69 +
1.70 +}