KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > ior > iiop > IIOPAddressBase


1 /*
2  * @(#)IIOPAddressBase.java 1.5 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.ior.iiop ;
9
10 import org.omg.CORBA.BAD_PARAM JavaDoc ;
11
12 import org.omg.CORBA_2_3.portable.InputStream JavaDoc ;
13 import org.omg.CORBA_2_3.portable.OutputStream JavaDoc ;
14
15 import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
16
17 /**
18  * @author
19  */

20 abstract class IIOPAddressBase implements IIOPAddress
21 {
22     // Ports are marshalled as shorts on the wire. The IDL
23
// type is unsigned short, which lacks a convenient representation
24
// in Java in the 32768-65536 range. So, we treat ports as
25
// ints throught this code, except that marshalling requires a
26
// scaling conversion. intToShort and shortToInt are provided
27
// for this purpose.
28
protected short intToShort( int value )
29     {
30     if (value > 32767)
31         return (short)(value - 65536) ;
32     return (short)value ;
33     }
34
35     protected int shortToInt( short value )
36     {
37     if (value < 0)
38         return value + 65536 ;
39     return value ;
40     }
41
42     public void write( OutputStream JavaDoc os )
43     {
44     os.write_string( getHost() ) ;
45     int port = getPort() ;
46     os.write_short( intToShort( port ) ) ;
47     }
48
49     public boolean equals( Object JavaDoc obj )
50     {
51     if (!(obj instanceof IIOPAddress))
52         return false ;
53
54     IIOPAddress other = (IIOPAddress)obj ;
55
56     return getHost().equals(other.getHost()) &&
57         (getPort() == other.getPort()) ;
58     }
59
60     public int hashCode()
61     {
62     return getHost().hashCode() ^ getPort() ;
63     }
64
65     public String JavaDoc toString()
66     {
67     return "IIOPAddress[" + getHost() + "," + getPort() + "]" ;
68     }
69 }
70
Popular Tags