File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\jenkins\util\ServerTcpPort.java.html

1 package jenkins.util;
2
3 import net.sf.json.JSONObject;
4 import org.kohsuke.stapler.DataBoundConstructor;
5
6 /**
7 * Used in conjunction with /lib/form/serverTcpPort tag to parse the submitted JSON back into a port number.
8 *
9 * @author Kohsuke Kawaguchi
10 * @since 1.445
11 */
12 public class ServerTcpPort {
13 private int value;
14 private String type;
15
16 @DataBoundConstructor
17 public ServerTcpPort(int value, String type) {
18 this.value = value;
19 this.type = type;
20 }
21
22 public ServerTcpPort(JSONObject o) {
23 type = o.getString("type");
24 value = o.optInt("value");
25 }
26
27 /**
28 * Parses the value back into the port number
29 */
30 public int getPort() {
31 if (type.equals("fixed")) return value;
32 if (type.equals("random")) return 0;
33 return -1;
34 }
35 }
36