~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to java/src/IceInternal/UnknownEndpointI.java

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// **********************************************************************
2
 
//
3
 
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
4
 
//
5
 
// This copy of Ice is licensed to you under the terms described in the
6
 
// ICE_LICENSE file included in this distribution.
7
 
//
8
 
// **********************************************************************
9
 
 
10
 
package IceInternal;
11
 
 
12
 
final class UnknownEndpointI extends EndpointI
13
 
{
14
 
    public
15
 
    UnknownEndpointI(String str)
16
 
    {
17
 
        int topt = 0;
18
 
        int vopt = 0;
19
 
 
20
 
        String[] arr = str.split("[ \t\n\r]+");
21
 
        int i = 0;
22
 
        while(i < arr.length)
23
 
        {
24
 
            if(arr[i].length() == 0)
25
 
            {
26
 
                i++;
27
 
                continue;
28
 
            }
29
 
 
30
 
            String option = arr[i++];
31
 
            if(option.length() != 2 || option.charAt(0) != '-')
32
 
            {
33
 
                throw new Ice.EndpointParseException("opaque " + str);
34
 
            }
35
 
 
36
 
            String argument = null;
37
 
            if(i < arr.length && arr[i].charAt(0) != '-')
38
 
            {
39
 
                argument = arr[i++];
40
 
            }
41
 
 
42
 
            switch(option.charAt(1))
43
 
            {
44
 
                case 't':
45
 
                {
46
 
                    if(argument == null)
47
 
                    {
48
 
                        throw new Ice.EndpointParseException("opaque " + str);
49
 
                    }
50
 
 
51
 
                    int t;
52
 
                    try
53
 
                    {
54
 
                        t = Integer.parseInt(argument);
55
 
                    }
56
 
                    catch(NumberFormatException ex)
57
 
                    {
58
 
                        throw new Ice.EndpointParseException("opaque " + str);
59
 
                    }
60
 
 
61
 
                    if(t < 0 || t > 65535)
62
 
                    {
63
 
                        throw new Ice.EndpointParseException("opaque " + str);
64
 
                    }
65
 
 
66
 
                    _type = (short)t;
67
 
                    ++topt;
68
 
                    break;
69
 
                }
70
 
 
71
 
                case 'v':
72
 
                {
73
 
                    if(argument == null)
74
 
                    {
75
 
                        throw new Ice.EndpointParseException("opaque " + str);
76
 
                    }
77
 
                    for(int j = 0; j < argument.length(); ++j)
78
 
                    {
79
 
                        if(!IceUtilInternal.Base64.isBase64(argument.charAt(j)))
80
 
                        {
81
 
                            throw new Ice.EndpointParseException("opaque " + str);
82
 
                        }
83
 
                    }
84
 
                    _rawBytes = IceUtilInternal.Base64.decode(argument);
85
 
                    ++vopt;
86
 
                    break;
87
 
                }
88
 
 
89
 
                default:
90
 
                {
91
 
                    throw new Ice.EndpointParseException("opaque " + str);
92
 
                }
93
 
            }
94
 
        }
95
 
 
96
 
        if(topt != 1 || vopt != 1)
97
 
        {
98
 
            throw new Ice.EndpointParseException("opaque " + str);
99
 
        }
100
 
        calcHashValue();
101
 
    }
102
 
 
103
 
    public
104
 
    UnknownEndpointI(short type, BasicStream s)
105
 
    {
106
 
        _type = type;
107
 
        s.startReadEncaps();
108
 
        int sz = s.getReadEncapsSize();
109
 
        _rawBytes = s.readBlob(sz);
110
 
        s.endReadEncaps();
111
 
        calcHashValue();
112
 
    }
113
 
 
114
 
    //
115
 
    // Marshal the endpoint
116
 
    //
117
 
    public void
118
 
    streamWrite(BasicStream s)
119
 
    {
120
 
        s.writeShort(_type);
121
 
        s.startWriteEncaps();
122
 
        s.writeBlob(_rawBytes);
123
 
        s.endWriteEncaps();
124
 
    }
125
 
 
126
 
    //
127
 
    // Convert the endpoint to its string form
128
 
    //
129
 
    public String
130
 
    _toString()
131
 
    {
132
 
        String val = IceUtilInternal.Base64.encode(_rawBytes);
133
 
        return "opaque -t " + _type + " -v " + val;
134
 
    }
135
 
 
136
 
    //
137
 
    // Return the endpoint type
138
 
    //
139
 
    public short
140
 
    type()
141
 
    {
142
 
        return _type;
143
 
    }
144
 
 
145
 
    //
146
 
    // Return the timeout for the endpoint in milliseconds. 0 means
147
 
    // non-blocking, -1 means no timeout.
148
 
    //
149
 
    public int
150
 
    timeout()
151
 
    {
152
 
        return -1;
153
 
    }
154
 
    
155
 
    //
156
 
    // Return a new endpoint with a different timeout value, provided
157
 
    // that timeouts are supported by the endpoint. Otherwise the same
158
 
    // endpoint is returned.
159
 
    //
160
 
    public EndpointI
161
 
    timeout(int t)
162
 
    {
163
 
        return this;
164
 
    }
165
 
 
166
 
    //
167
 
    // Return a new endpoint with a different connection id.
168
 
    //
169
 
    public EndpointI
170
 
    connectionId(String connectionId)
171
 
    {
172
 
        return this;
173
 
    }
174
 
    
175
 
    //
176
 
    // Return true if the endpoints support bzip2 compress, or false
177
 
    // otherwise.
178
 
    //
179
 
    public boolean
180
 
    compress()
181
 
    {
182
 
        return false;
183
 
    }
184
 
 
185
 
    //
186
 
    // Return a new endpoint with a different compression value,
187
 
    // provided that compression is supported by the
188
 
    // endpoint. Otherwise the same endpoint is returned.
189
 
    //
190
 
    public EndpointI
191
 
    compress(boolean compress)
192
 
    {
193
 
        return this;
194
 
    }
195
 
 
196
 
    //
197
 
    // Return true if the endpoint is datagram-based.
198
 
    //
199
 
    public boolean
200
 
    datagram()
201
 
    {
202
 
        return false;
203
 
    }
204
 
    
205
 
    //
206
 
    // Return true if the endpoint is secure.
207
 
    //
208
 
    public boolean
209
 
    secure()
210
 
    {
211
 
        return false;
212
 
    }
213
 
 
214
 
    //
215
 
    // Return true if the endpoint type is unknown.
216
 
    //
217
 
    public boolean
218
 
    unknown()
219
 
    {
220
 
        return true;
221
 
    }
222
 
    
223
 
    //
224
 
    // Return a server side transceiver for this endpoint, or null if a
225
 
    // transceiver can only be created by an acceptor. In case a
226
 
    // transceiver is created, this operation also returns a new
227
 
    // "effective" endpoint, which might differ from this endpoint,
228
 
    // for example, if a dynamic port number is assigned.
229
 
    //
230
 
    public Transceiver
231
 
    transceiver(EndpointIHolder endpoint)
232
 
    {
233
 
        endpoint.value = null;
234
 
        return null;
235
 
    }
236
 
 
237
 
    //
238
 
    // Return connectors for this endpoint, or empty list if no connector
239
 
    // is available.
240
 
    //
241
 
    public java.util.List<Connector>
242
 
    connectors()
243
 
    {
244
 
        return new java.util.ArrayList<Connector>();
245
 
    }
246
 
 
247
 
    public void
248
 
    connectors_async(EndpointI_connectors callback)
249
 
    {
250
 
        callback.connectors(new java.util.ArrayList<Connector>());
251
 
    }
252
 
 
253
 
    //
254
 
    // Return an acceptor for this endpoint, or null if no acceptors
255
 
    // is available. In case an acceptor is created, this operation
256
 
    // also returns a new "effective" endpoint, which might differ
257
 
    // from this endpoint, for example, if a dynamic port number is
258
 
    // assigned.
259
 
    //
260
 
    public Acceptor
261
 
    acceptor(EndpointIHolder endpoint, String adapterName)
262
 
    {
263
 
        endpoint.value = null;
264
 
        return null;
265
 
    }
266
 
 
267
 
    //
268
 
    // Expand endpoint out in to separate endpoints for each local
269
 
    // host if listening on INADDR_ANY on server side or if no host
270
 
    // was specified on client side.
271
 
    //
272
 
    public java.util.List<EndpointI>
273
 
    expand()
274
 
    {
275
 
        java.util.List<EndpointI> endps = new java.util.ArrayList<EndpointI>();
276
 
        endps.add(this);
277
 
        return endps;
278
 
    }
279
 
 
280
 
    //
281
 
    // Check whether the endpoint is equivalent to another one.
282
 
    //
283
 
    public boolean
284
 
    equivalent(EndpointI endpoint)
285
 
    {
286
 
        return false;
287
 
    }
288
 
 
289
 
    public int
290
 
    hashCode()
291
 
    {
292
 
        return _hashCode;
293
 
    }
294
 
    
295
 
    //
296
 
    // Compare endpoints for sorting purposes
297
 
    //
298
 
    public boolean
299
 
    equals(java.lang.Object obj)
300
 
    {
301
 
        try
302
 
        {
303
 
            return compareTo((EndpointI)obj) == 0;
304
 
        }
305
 
        catch(ClassCastException ee)
306
 
        {
307
 
            assert(false);
308
 
            return false;
309
 
        }
310
 
    }
311
 
 
312
 
    public int
313
 
    compareTo(EndpointI obj) // From java.lang.Comparable
314
 
    {
315
 
        UnknownEndpointI p = null;
316
 
 
317
 
        try
318
 
        {
319
 
            p = (UnknownEndpointI)obj;
320
 
        }
321
 
        catch(ClassCastException ex)
322
 
        {
323
 
            return 1;
324
 
        }
325
 
 
326
 
        if(this == p)
327
 
        {
328
 
            return 0;
329
 
        }
330
 
 
331
 
        if(_type < p._type)
332
 
        {
333
 
            return -1;
334
 
        }
335
 
        else if(p._type < _type)
336
 
        {
337
 
            return 1;
338
 
        }
339
 
 
340
 
        if(_rawBytes.length < p._rawBytes.length)
341
 
        {
342
 
            return -1;
343
 
        }
344
 
        else if(p._rawBytes.length < _rawBytes.length)
345
 
        {
346
 
            return 1;
347
 
        }
348
 
        for(int i = 0; i < _rawBytes.length; i++)
349
 
        {
350
 
            if(_rawBytes[i] < p._rawBytes[i])
351
 
            {
352
 
                return -1;
353
 
            }
354
 
            else if(p._rawBytes[i] < _rawBytes[i])
355
 
            {
356
 
                return 1;
357
 
            }
358
 
        }
359
 
 
360
 
        return 0;
361
 
    }
362
 
 
363
 
    private void
364
 
    calcHashValue()
365
 
    {
366
 
        _hashCode = _type;
367
 
        for(int i = 0; i < _rawBytes.length; i++)
368
 
        {
369
 
            _hashCode = 5 * _hashCode + _rawBytes[i];
370
 
        }
371
 
    }
372
 
 
373
 
    private short _type;
374
 
    private byte[] _rawBytes;
375
 
    private int _hashCode;
376
 
}