/
Server.java
112 lines (96 loc) · 3.02 KB
/
Server.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* ome.system.Server
*
* Copyright 2006 University of Dundee. All rights reserved.
* Use is subject to license terms supplied in LICENSE.txt
*/
package ome.system;
import java.util.Properties;
import ome.conditions.ApiUsageException;
/**
* Provides simplified handling of server properties when creating a
* {@link ome.system.ServiceFactory}. For more complicated uses,
* {@link java.util.Properties} can also be used. In which case, the constant
* {@link java.lang.String strings} provided in this class can be used as the
* keys to the {@link java.util.Properties properties instance} passed to
* {@link ome.system.ServiceFactory#ServiceFactory(Properties)}.
*
* @author Josh Moore <a
* href="mailto:josh.moore@gmx.de">josh.moore@gmx.de</a>
* @version 1.0
* @see ome.system.ServiceFactory
* @since 1.0
*/
public class Server {
/**
* Java property name for use in configuration of the client connection.
*/
public final static String OMERO_HOST = "server.host";
/**
* Java property name for use in configuration of the client connection.
*/
public final static String OMERO_PORT = "server.port";
public final static int DEFAULT_PORT = 1099;
private String _server, _port;
// Need at least user and password
private Server() {
}
/**
* standard constructor which users {@link #DEFAULT_PORT}.
*
* @param serverHost
* Not null.
*/
public Server(String serverHost) {
if (serverHost == null) {
throw new ApiUsageException("serverHost argument "
+ "to Server constructor cannot be null");
}
_server = serverHost;
_port = Integer.toString(DEFAULT_PORT);
}
/**
* extended constructor. As with {@link #Server(String)}, serverHost may
* not be null.
*
* @param serverHost
* Not null.
* @param port
*/
public Server(String serverHost, int port) {
this(serverHost);
if (port < 0) {
throw new ApiUsageException("serverPort may not be null.");
}
_port = Integer.toString(port);
}
// ~ Views
// =========================================================================
/**
* produces a copy of the internal fields as a {@link java.util.Properties}
* instance. Only those keys are present for which a field is non-null.
*
* @return Properties. Not null.
*/
public Properties asProperties() {
Properties p = new Properties();
p.setProperty(OMERO_HOST, _server);
p.setProperty(OMERO_PORT, _port);
return p;
}
/**
* simple getter for the server host passed into the constructor
*
* @return host name Not null.
*/
public String getHost() {
return _server;
}
/**
* simple getter for the port passed into the constructor or the default
* port if none.
*/
public int getPort() {
return Integer.valueOf(_port);
}
}