1. /*
  2. * @(#)WireObjectKeyTemplate.java 1.19 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;
  8. import org.omg.CORBA.OctetSeqHolder ;
  9. import org.omg.CORBA_2_3.portable.OutputStream ;
  10. import org.omg.CORBA_2_3.portable.InputStream ;
  11. import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
  12. import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
  13. import com.sun.corba.se.spi.ior.ObjectId ;
  14. import com.sun.corba.se.spi.ior.ObjectAdapterId ;
  15. import com.sun.corba.se.spi.orb.ORB ;
  16. import com.sun.corba.se.spi.orb.ORBVersion ;
  17. import com.sun.corba.se.spi.orb.ORBVersionFactory ;
  18. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  19. import com.sun.corba.se.impl.orbutil.ORBConstants ;
  20. import com.sun.corba.se.impl.encoding.CDRInputStream ;
  21. import com.sun.corba.se.impl.logging.IORSystemException ;
  22. /**
  23. * @author Ken Cavanaugh
  24. */
  25. public class WireObjectKeyTemplate implements ObjectKeyTemplate
  26. {
  27. private ORB orb ;
  28. private IORSystemException wrapper ;
  29. public boolean equals( Object obj )
  30. {
  31. if (obj == null)
  32. return false ;
  33. return obj instanceof WireObjectKeyTemplate ;
  34. }
  35. public int hashCode()
  36. {
  37. return 53 ; // All WireObjectKeyTemplates are the same, so they should
  38. // have the same hashCode.
  39. }
  40. private byte[] getId( InputStream is )
  41. {
  42. CDRInputStream cis = (CDRInputStream)is ;
  43. int len = cis.getBufferLength() ;
  44. byte[] result = new byte[ len ] ;
  45. cis.read_octet_array( result, 0, len ) ;
  46. return result ;
  47. }
  48. public WireObjectKeyTemplate( ORB orb )
  49. {
  50. initORB( orb ) ;
  51. }
  52. public WireObjectKeyTemplate( InputStream is, OctetSeqHolder osh )
  53. {
  54. osh.value = getId( is ) ;
  55. initORB( (ORB)(is.orb())) ;
  56. }
  57. private void initORB( ORB orb )
  58. {
  59. this.orb = orb ;
  60. wrapper = IORSystemException.get( orb,
  61. CORBALogDomains.OA_IOR ) ;
  62. }
  63. public void write( ObjectId id, OutputStream os )
  64. {
  65. byte[] key = id.getId() ;
  66. os.write_octet_array( key, 0, key.length ) ;
  67. }
  68. public void write( OutputStream os )
  69. {
  70. // Does nothing
  71. }
  72. public int getSubcontractId()
  73. {
  74. return ORBConstants.DEFAULT_SCID ;
  75. }
  76. /** While it might make sense to throw an exception here, this causes
  77. * problems since we need to check whether unusual object references
  78. * are local or not. It seems that the easiest way to handle this is
  79. * to return an invalid server id.
  80. */
  81. public int getServerId()
  82. {
  83. return -1 ;
  84. }
  85. public String getORBId()
  86. {
  87. throw wrapper.orbIdNotAvailable() ;
  88. }
  89. public ObjectAdapterId getObjectAdapterId()
  90. {
  91. throw wrapper.objectAdapterIdNotAvailable() ;
  92. }
  93. /** Adapter ID is not available, since our
  94. * ORB did not implement the object carrying this key.
  95. */
  96. public byte[] getAdapterId()
  97. {
  98. throw wrapper.adapterIdNotAvailable() ;
  99. }
  100. public ORBVersion getORBVersion()
  101. {
  102. return ORBVersionFactory.getFOREIGN() ;
  103. }
  104. public CorbaServerRequestDispatcher getServerRequestDispatcher( ORB orb, ObjectId id )
  105. {
  106. byte[] bid = id.getId() ;
  107. String str = new String( bid ) ;
  108. return orb.getRequestDispatcherRegistry().getServerRequestDispatcher( str ) ;
  109. }
  110. }