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