1. /*
  2. * @(#)ObjectKeyTemplateBase.java 1.13 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. // @(#)ObjectKeyTemplateBase.java 1.10 00/10/11
  8. package com.sun.corba.se.internal.ior;
  9. import com.sun.corba.se.internal.ior.ObjectId ;
  10. import com.sun.corba.se.internal.ior.ObjectKeyFactory ;
  11. import org.omg.CORBA_2_3.portable.InputStream ;
  12. import org.omg.CORBA_2_3.portable.OutputStream ;
  13. import com.sun.corba.se.internal.corba.EncapsOutputStream ;
  14. import com.sun.corba.se.internal.core.ORBVersion ;
  15. import org.omg.CORBA.ORB ;
  16. /**
  17. * @author
  18. */
  19. public abstract class ObjectKeyTemplateBase implements ObjectKeyTemplate
  20. {
  21. private ORBVersion version ;
  22. private int magic ;
  23. private int scid ;
  24. private int serverid ;
  25. /**
  26. * @param scid
  27. * @param serverid
  28. * @return
  29. * @exception
  30. * @author
  31. * @roseuid 3915FF9803AA
  32. */
  33. public ObjectKeyTemplateBase( int magic, int scid, int serverid)
  34. {
  35. this.magic = magic ;
  36. this.scid = scid ;
  37. this.serverid = serverid ;
  38. }
  39. public boolean equals( Object obj )
  40. {
  41. if (!(obj instanceof ObjectKeyTemplateBase))
  42. return false ;
  43. ObjectKeyTemplateBase other = (ObjectKeyTemplateBase)obj ;
  44. return (magic == other.magic) && (scid == other.scid) &&
  45. (serverid == other.serverid) && (version.equals( other.version )) ;
  46. }
  47. public byte[] getAdapterId( ORB orb )
  48. {
  49. EncapsOutputStream os = new EncapsOutputStream( orb ) ;
  50. write( os ) ;
  51. byte[] result = os.toByteArray() ;
  52. return result ;
  53. }
  54. /**
  55. * @return int
  56. * @exception
  57. * @author
  58. * @roseuid 3915FFEC0102
  59. */
  60. public int getSubcontractId()
  61. {
  62. return scid ;
  63. }
  64. public int getServerId()
  65. {
  66. return serverid ;
  67. }
  68. /*
  69. public byte[] getId( InputStream is )
  70. {
  71. int len = is.read_long() ;
  72. byte[] result = new byte[ len ] ;
  73. is.read_octet_array( result, 0, len ) ;
  74. return result ;
  75. }
  76. */
  77. /**
  78. * @param objectId
  79. * @param os
  80. * @return void
  81. * @exception
  82. * @author
  83. * @roseuid 3915FFEB0287
  84. */
  85. public void write(ObjectId objectId, OutputStream os)
  86. {
  87. write( os ) ;
  88. byte[] data = objectId.getId() ;
  89. os.write_long( data.length ) ;
  90. os.write_octet_array( data, 0, data.length ) ;
  91. }
  92. abstract protected void write( OutputStream os ) ;
  93. protected int getMagic()
  94. {
  95. return magic ;
  96. }
  97. // All subclasses should set the version in their constructors.
  98. protected void setORBVersion( ORBVersion version )
  99. {
  100. this.version = version ;
  101. }
  102. public ORBVersion getORBVersion()
  103. {
  104. return version ;
  105. }
  106. protected byte[] readObjectKey( InputStream is )
  107. {
  108. int len = is.read_long() ;
  109. byte[] result = new byte[len] ;
  110. is.read_octet_array( result, 0, len ) ;
  111. return result ;
  112. }
  113. }