1. /*
  2. * @(#)IIOPAddressBase.java 1.3 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. //Source file: J:/ws/serveractivation/src/share/classes/com.sun.corba.se.internal.ior/IIOPAddress.java
  8. package com.sun.corba.se.internal.ior;
  9. import org.omg.CORBA.BAD_PARAM ;
  10. import org.omg.CORBA_2_3.portable.InputStream ;
  11. import org.omg.CORBA_2_3.portable.OutputStream ;
  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 String toString()
  50. {
  51. return "IIOPAddress[" + getHost() + "," + getPort() + "]" ;
  52. }
  53. }