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. package com.sun.corba.se.impl.ior.iiop ;
  8. import org.omg.CORBA.BAD_PARAM ;
  9. import org.omg.CORBA_2_3.portable.InputStream ;
  10. import org.omg.CORBA_2_3.portable.OutputStream ;
  11. import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
  12. /**
  13. * @author
  14. */
  15. abstract class IIOPAddressBase implements IIOPAddress
  16. {
  17. // Ports are marshalled as shorts on the wire. The IDL
  18. // type is unsigned short, which lacks a convenient representation
  19. // in Java in the 32768-65536 range. So, we treat ports as
  20. // ints throught this code, except that marshalling requires a
  21. // scaling conversion. intToShort and shortToInt are provided
  22. // for this purpose.
  23. protected short intToShort( int value )
  24. {
  25. if (value > 32767)
  26. return (short)(value - 65536) ;
  27. return (short)value ;
  28. }
  29. protected int shortToInt( short value )
  30. {
  31. if (value < 0)
  32. return value + 65536 ;
  33. return value ;
  34. }
  35. public void write( OutputStream os )
  36. {
  37. os.write_string( getHost() ) ;
  38. int port = getPort() ;
  39. os.write_short( intToShort( port ) ) ;
  40. }
  41. public boolean equals( Object obj )
  42. {
  43. if (!(obj instanceof IIOPAddress))
  44. return false ;
  45. IIOPAddress other = (IIOPAddress)obj ;
  46. return getHost().equals(other.getHost()) &&
  47. (getPort() == other.getPort()) ;
  48. }
  49. public int hashCode()
  50. {
  51. return getHost().hashCode() ^ getPort() ;
  52. }
  53. public String toString()
  54. {
  55. return "IIOPAddress[" + getHost() + "," + getPort() + "]" ;
  56. }
  57. }