xref: /AOO41X/main/jurt/com/sun/star/lib/connections/socket/ConnectionDescriptor.java (revision 2be432768a66cc90838f6a32e76ec156f587e741)
1*2be43276SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2be43276SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2be43276SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2be43276SAndrew Rist  * distributed with this work for additional information
6*2be43276SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2be43276SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2be43276SAndrew Rist  * "License"); you may not use this file except in compliance
9*2be43276SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*2be43276SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*2be43276SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2be43276SAndrew Rist  * software distributed under the License is distributed on an
15*2be43276SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2be43276SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2be43276SAndrew Rist  * specific language governing permissions and limitations
18*2be43276SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*2be43276SAndrew Rist  *************************************************************/
21*2be43276SAndrew Rist 
22*2be43276SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.lib.connections.socket;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir /**
27cdf0e10cSrcweir  * Helper class for <code>socketAcceptor</code> and
28cdf0e10cSrcweir  * <code>socketConnector</code>.
29cdf0e10cSrcweir  *
30cdf0e10cSrcweir  * <p>FIXME:  Once those classes have been moved from <code>jurt</code> to
31cdf0e10cSrcweir  * <code>javaunohelper</code>, they should use
32cdf0e10cSrcweir  * <code>com.sun.star.lib.uno.helper.UnoUrl</code> either instead of this class
33cdf0e10cSrcweir  * or underneath this class.</p>
34cdf0e10cSrcweir  */
35cdf0e10cSrcweir final class ConnectionDescriptor {
ConnectionDescriptor(String description)36cdf0e10cSrcweir     public ConnectionDescriptor(String description)
37cdf0e10cSrcweir         throws com.sun.star.lang.IllegalArgumentException {
38cdf0e10cSrcweir         for (int i = description.indexOf(','); i >= 0;) {
39cdf0e10cSrcweir             int j = description.indexOf(',', i + 1);
40cdf0e10cSrcweir             int k = j < 0 ? description.length() : j;
41cdf0e10cSrcweir             int l = description.indexOf('=', i + 1);
42cdf0e10cSrcweir             if (l < 0 || l >= k) {
43cdf0e10cSrcweir                 throw new com.sun.star.lang.IllegalArgumentException(
44cdf0e10cSrcweir                     "parameter lacks '='");
45cdf0e10cSrcweir             }
46cdf0e10cSrcweir             String key = description.substring(i + 1, l);
47cdf0e10cSrcweir             String value = description.substring(l + 1, k);
48cdf0e10cSrcweir             if (key.equalsIgnoreCase("host")) {
49cdf0e10cSrcweir                 host = value;
50cdf0e10cSrcweir             } else if (key.equalsIgnoreCase("port")) {
51cdf0e10cSrcweir                 try {
52cdf0e10cSrcweir                     port = Integer.valueOf(value).intValue();
53cdf0e10cSrcweir                 } catch (NumberFormatException e) {
54cdf0e10cSrcweir                     throw new com.sun.star.lang.IllegalArgumentException(
55cdf0e10cSrcweir                         e.toString());
56cdf0e10cSrcweir                 }
57cdf0e10cSrcweir                 if (port < 0 || port > 65535) {
58cdf0e10cSrcweir                     throw new com.sun.star.lang.IllegalArgumentException(
59cdf0e10cSrcweir                         "port parameter must have value between 0 and 65535,"
60cdf0e10cSrcweir                         + " inclusive");
61cdf0e10cSrcweir                 }
62cdf0e10cSrcweir             } else if (key.equalsIgnoreCase("backlog")) {
63cdf0e10cSrcweir                 try {
64cdf0e10cSrcweir                     backlog = Integer.valueOf(value).intValue();
65cdf0e10cSrcweir                 } catch (NumberFormatException e) {
66cdf0e10cSrcweir                     throw new com.sun.star.lang.IllegalArgumentException(
67cdf0e10cSrcweir                         e.toString());
68cdf0e10cSrcweir                 }
69cdf0e10cSrcweir             } else if (key.equalsIgnoreCase("tcpnodelay")) {
70cdf0e10cSrcweir                 if (value.equals("0")) {
71cdf0e10cSrcweir                     tcpNoDelay = Boolean.FALSE;
72cdf0e10cSrcweir                 } else if (value.equals("1")) {
73cdf0e10cSrcweir                     tcpNoDelay = Boolean.TRUE;
74cdf0e10cSrcweir                 } else {
75cdf0e10cSrcweir                     throw new com.sun.star.lang.IllegalArgumentException(
76cdf0e10cSrcweir                         "tcpnodelay parameter must have 0/1 value");
77cdf0e10cSrcweir                 }
78cdf0e10cSrcweir             }
79cdf0e10cSrcweir             i = j;
80cdf0e10cSrcweir         }
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     public String getHost() {
84cdf0e10cSrcweir         return host;
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     public int getPort() {
88cdf0e10cSrcweir         return port;
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     public int getBacklog() {
92cdf0e10cSrcweir         return backlog;
93cdf0e10cSrcweir     }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     public Boolean getTcpNoDelay() {
96cdf0e10cSrcweir         return tcpNoDelay;
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     private String host = null;
100cdf0e10cSrcweir     private int port = 6001;
101cdf0e10cSrcweir     private int backlog = 50;
102cdf0e10cSrcweir     private Boolean tcpNoDelay = null;
103cdf0e10cSrcweir }
104