1. /*
  2. * @(#)ObjectReferenceTemplateImpl.java 1.35 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 java.util.Iterator ;
  9. import org.omg.CORBA.portable.InputStream ;
  10. import org.omg.CORBA.portable.OutputStream ;
  11. import org.omg.CORBA.portable.StreamableValue ;
  12. import org.omg.CORBA.TypeCode ;
  13. import org.omg.PortableInterceptor.ObjectReferenceTemplate ;
  14. import org.omg.PortableInterceptor.ObjectReferenceTemplateHelper ;
  15. import com.sun.corba.se.spi.oa.ObjectAdapter ;
  16. import com.sun.corba.se.spi.ior.ObjectId ;
  17. import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
  18. import com.sun.corba.se.spi.ior.ObjectAdapterId ;
  19. import com.sun.corba.se.spi.ior.IOR;
  20. import com.sun.corba.se.spi.ior.IORFactory;
  21. import com.sun.corba.se.spi.ior.IORTemplate;
  22. import com.sun.corba.se.spi.ior.IORTemplateList;
  23. import com.sun.corba.se.spi.ior.IORFactories;
  24. import com.sun.corba.se.impl.orbutil.ORBUtility ;
  25. import com.sun.corba.se.spi.orb.ORB ;
  26. /** This is an implementation of the ObjectReferenceTemplate abstract value
  27. * type defined by the portable interceptors IDL.
  28. * Note that this is a direct Java implementation
  29. * of the abstract value type: there is no stateful value type defined in IDL,
  30. * since defining the state in IDL is awkward and inefficient. The best way
  31. * to define the state is to use internal data structures that can be written
  32. * to and read from CORBA streams.
  33. */
  34. public class ObjectReferenceTemplateImpl extends ObjectReferenceProducerBase
  35. implements ObjectReferenceTemplate, StreamableValue
  36. {
  37. transient private IORTemplate iorTemplate ;
  38. public ObjectReferenceTemplateImpl( InputStream is )
  39. {
  40. super( (ORB)(is.orb()) ) ;
  41. _read( is ) ;
  42. }
  43. public ObjectReferenceTemplateImpl( ORB orb, IORTemplate iortemp )
  44. {
  45. super( orb ) ;
  46. iorTemplate = iortemp ;
  47. }
  48. public boolean equals( Object obj )
  49. {
  50. if (!(obj instanceof ObjectReferenceTemplateImpl))
  51. return false ;
  52. ObjectReferenceTemplateImpl other = (ObjectReferenceTemplateImpl)obj ;
  53. return (iorTemplate != null) &&
  54. iorTemplate.equals( other.iorTemplate ) ;
  55. }
  56. public int hashCode()
  57. {
  58. return iorTemplate.hashCode() ;
  59. }
  60. // Note that this repository ID must reflect the implementation
  61. // of the abstract valuetype (that is, this class), not the
  62. // repository ID of the org.omg.PortableInterceptor.ObjectReferenceTemplate
  63. // class. This allows for multiple independent implementations
  64. // of the abstract valuetype, should that become necessary.
  65. public static final String repositoryId =
  66. "IDL:com/sun/corba/se/impl/ior/ObjectReferenceTemplateImpl:1.0" ;
  67. public String[] _truncatable_ids()
  68. {
  69. return new String[] { repositoryId } ;
  70. }
  71. public TypeCode _type()
  72. {
  73. return ObjectReferenceTemplateHelper.type() ;
  74. }
  75. /** Read the data into a (presumably) empty ORTImpl. This sets the
  76. * orb to the ORB of the InputStream.
  77. */
  78. public void _read( InputStream is )
  79. {
  80. org.omg.CORBA_2_3.portable.InputStream istr =
  81. (org.omg.CORBA_2_3.portable.InputStream)is ;
  82. iorTemplate = IORFactories.makeIORTemplate( istr ) ;
  83. orb = (ORB)(istr.orb()) ;
  84. }
  85. /** Write the state to the OutputStream.
  86. */
  87. public void _write( OutputStream os )
  88. {
  89. org.omg.CORBA_2_3.portable.OutputStream ostr =
  90. (org.omg.CORBA_2_3.portable.OutputStream)os ;
  91. iorTemplate.write( ostr ) ;
  92. }
  93. public String server_id ()
  94. {
  95. int val = iorTemplate.getObjectKeyTemplate().getServerId() ;
  96. return Integer.toString( val ) ;
  97. }
  98. public String orb_id ()
  99. {
  100. return iorTemplate.getObjectKeyTemplate().getORBId() ;
  101. }
  102. public String[] adapter_name()
  103. {
  104. ObjectAdapterId poaid =
  105. iorTemplate.getObjectKeyTemplate().getObjectAdapterId() ;
  106. return poaid.getAdapterName() ;
  107. }
  108. public IORFactory getIORFactory()
  109. {
  110. return iorTemplate ;
  111. }
  112. public IORTemplateList getIORTemplateList()
  113. {
  114. IORTemplateList tl = IORFactories.makeIORTemplateList() ;
  115. tl.add( iorTemplate ) ;
  116. tl.makeImmutable() ;
  117. return tl ;
  118. }
  119. }