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