| author | Jaroslav Tulach <jtulach@netbeans.org> |
| Fri Aug 27 14:06:39 2010 +0200 | |
| changeset 365 | 0b7ec6ef8a72 |
| parent 300 | b704be5f8463 |
| permissions | -rw-r--r-- |
| 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@337 | 9 |
* Mutable "setter" 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@337 | 21 |
this.name = np; |
| jtulach@337 | 22 |
return this; |
| jtulach@294 | 23 |
} |
| jtulach@294 | 24 |
|
| jtulach@294 | 25 |
public final ServerInfo urlProvider(URLProvider up) {
|
| jtulach@337 | 26 |
this.url = up; |
| jtulach@337 | 27 |
return this; |
| jtulach@294 | 28 |
} |
| jtulach@337 | 29 |
// BEGIN: aserverinfo.builder.setter |
| jtulach@294 | 30 |
public final ServerInfo reset(ResetHandler h) {
|
| jtulach@337 | 31 |
this.reset = h; |
| jtulach@337 | 32 |
return this; |
| jtulach@294 | 33 |
} |
| jtulach@337 | 34 |
// END: aserverinfo.builder.setter |
| jtulach@337 | 35 |
|
| jtulach@294 | 36 |
/** All one needs to do when there is a need to add new |
| jtulach@294 | 37 |
* style of creation is to add new method for a builder. |
| jtulach@294 | 38 |
* @param handler |
| jtulach@294 | 39 |
* @return |
| jtulach@294 | 40 |
* @since 2.0 |
| jtulach@294 | 41 |
*/ |
| jtulach@294 | 42 |
public final ServerInfo shutdown(ShutdownHandler handler) {
|
| jtulach@337 | 43 |
this.shutdown = handler; |
| jtulach@337 | 44 |
return this; |
| jtulach@294 | 45 |
} |
| jtulach@294 | 46 |
|
| jtulach@294 | 47 |
/** Creates the server connector based on current values in the |
| jtulach@294 | 48 |
* info. Builder factory method. |
| jtulach@294 | 49 |
* @return server connector |
| jtulach@294 | 50 |
*/ |
| jtulach@294 | 51 |
public final ServerConnector connect() {
|
| jtulach@294 | 52 |
return new ServerConnector(name, url, reset, shutdown); |
| jtulach@294 | 53 |
} |
| jtulach@300 | 54 |
// FINISH: aserverinfo.builder.factory |
| jtulach@294 | 55 |
|
| jtulach@337 | 56 |
private NameProvider name; |
| jtulach@337 | 57 |
private URLProvider url; |
| jtulach@337 | 58 |
private ResetHandler reset; |
| jtulach@337 | 59 |
private ShutdownHandler shutdown; |
| jtulach@294 | 60 |
|
| jtulach@294 | 61 |
private ServerInfo( |
| jtulach@294 | 62 |
NameProvider name, URLProvider url, |
| jtulach@294 | 63 |
ResetHandler reset, ShutdownHandler shutdown |
| jtulach@294 | 64 |
) {
|
| jtulach@294 | 65 |
this.name = name; |
| jtulach@294 | 66 |
this.url = url; |
| jtulach@294 | 67 |
this.reset = reset; |
| jtulach@294 | 68 |
this.shutdown = shutdown; |
| jtulach@294 | 69 |
} |
| jtulach@294 | 70 |
|
| jtulach@294 | 71 |
} |