xref: /AOO41X/main/jurt/com/sun/star/lib/connections/socket/ConnectionDescriptor.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package com.sun.star.lib.connections.socket;
29 
30 /**
31  * Helper class for <code>socketAcceptor</code> and
32  * <code>socketConnector</code>.
33  *
34  * <p>FIXME:  Once those classes have been moved from <code>jurt</code> to
35  * <code>javaunohelper</code>, they should use
36  * <code>com.sun.star.lib.uno.helper.UnoUrl</code> either instead of this class
37  * or underneath this class.</p>
38  */
39 final class ConnectionDescriptor {
40     public ConnectionDescriptor(String description)
41         throws com.sun.star.lang.IllegalArgumentException {
42         for (int i = description.indexOf(','); i >= 0;) {
43             int j = description.indexOf(',', i + 1);
44             int k = j < 0 ? description.length() : j;
45             int l = description.indexOf('=', i + 1);
46             if (l < 0 || l >= k) {
47                 throw new com.sun.star.lang.IllegalArgumentException(
48                     "parameter lacks '='");
49             }
50             String key = description.substring(i + 1, l);
51             String value = description.substring(l + 1, k);
52             if (key.equalsIgnoreCase("host")) {
53                 host = value;
54             } else if (key.equalsIgnoreCase("port")) {
55                 try {
56                     port = Integer.valueOf(value).intValue();
57                 } catch (NumberFormatException e) {
58                     throw new com.sun.star.lang.IllegalArgumentException(
59                         e.toString());
60                 }
61                 if (port < 0 || port > 65535) {
62                     throw new com.sun.star.lang.IllegalArgumentException(
63                         "port parameter must have value between 0 and 65535,"
64                         + " inclusive");
65                 }
66             } else if (key.equalsIgnoreCase("backlog")) {
67                 try {
68                     backlog = Integer.valueOf(value).intValue();
69                 } catch (NumberFormatException e) {
70                     throw new com.sun.star.lang.IllegalArgumentException(
71                         e.toString());
72                 }
73             } else if (key.equalsIgnoreCase("tcpnodelay")) {
74                 if (value.equals("0")) {
75                     tcpNoDelay = Boolean.FALSE;
76                 } else if (value.equals("1")) {
77                     tcpNoDelay = Boolean.TRUE;
78                 } else {
79                     throw new com.sun.star.lang.IllegalArgumentException(
80                         "tcpnodelay parameter must have 0/1 value");
81                 }
82             }
83             i = j;
84         }
85     }
86 
87     public String getHost() {
88         return host;
89     }
90 
91     public int getPort() {
92         return port;
93     }
94 
95     public int getBacklog() {
96         return backlog;
97     }
98 
99     public Boolean getTcpNoDelay() {
100         return tcpNoDelay;
101     }
102 
103     private String host = null;
104     private int port = 6001;
105     private int backlog = 50;
106     private Boolean tcpNoDelay = null;
107 }
108