• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.server
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • Last Change
  • Annotate
  • Revision Log

root/trunk/components/common/src/ome/system/Server.java

Revision 1167, 3.2 kB (checked in by jmoore, 2 years ago)

[svn:keywords] Id,Date,Revision,URL for *.java and Id for *.xml

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

Download in other formats:

  • Plain Text
  • Original Format

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/