samples/aserverinfo/src/org/apidesign/aserverinfo/builder/ServerInfo.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat Nov 15 13:12:46 2008 +0100
changeset 300 b704be5f8463
parent 294 0753acb192c7
child 337 d5b6a877e5a8
permissions -rw-r--r--
Typo and bigger code snippet
     1 package org.apidesign.aserverinfo.builder;
     2 
     3 import org.apidesign.aserverinfo.spi.NameProvider;
     4 import org.apidesign.aserverinfo.spi.ResetHandler;
     5 import org.apidesign.aserverinfo.spi.ShutdownHandler;
     6 import org.apidesign.aserverinfo.spi.URLProvider;
     7 
     8 /**
     9  * Cumulative factory methods for the builder pattern
    10  *
    11  * @author Jaroslav Tulach <jtulach@netbeans.org>
    12  */
    13 // BEGIN: aserverinfo.builder.factory
    14 public class ServerInfo {
    15 
    16     public static ServerInfo empty() {
    17         return new ServerInfo(null, null, null, null);
    18     }
    19 
    20     public final ServerInfo nameProvider(NameProvider np) {
    21         return new ServerInfo(np, this.url, this.reset, this.shutdown);
    22     }
    23 
    24     public final ServerInfo urlProvider(URLProvider up) {
    25         return new ServerInfo(this.name, up, this.reset, this.shutdown);
    26     }
    27     public final ServerInfo reset(ResetHandler h) {
    28         return new ServerInfo(this.name, this.url, h, this.shutdown);
    29     }
    30     /** All one needs to do when there is a need to add new
    31      * style of creation is to add new method for a builder.
    32      * @param handler
    33      * @return
    34      * @since 2.0
    35      */
    36     public final ServerInfo shutdown(ShutdownHandler handler) {
    37         return new ServerInfo(this.name, this.url, this.reset, handler);
    38     }
    39     
    40     /** Creates the server connector based on current values in the 
    41      * info. Builder factory method.
    42      * @return server connector
    43      */
    44     public final ServerConnector connect() {
    45         return new ServerConnector(name, url, reset, shutdown);
    46     }
    47     // FINISH: aserverinfo.builder.factory
    48 
    49     private final NameProvider name;
    50     private final URLProvider url;
    51     private final ResetHandler reset;
    52     private final ShutdownHandler shutdown;
    53 
    54     private ServerInfo(
    55         NameProvider name, URLProvider url,
    56         ResetHandler reset, ShutdownHandler shutdown
    57     ) {
    58         this.name = name;
    59         this.url = url;
    60         this.reset = reset;
    61         this.shutdown = shutdown;
    62     }
    63 
    64 }