1. /*
  2. * @(#)ObjectReferenceFactoryImpl.java 1.9 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.ObjectReferenceFactory ;
  14. import org.omg.PortableInterceptor.ObjectReferenceFactoryHelper ;
  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.IORTemplateList;
  22. import com.sun.corba.se.spi.ior.IORFactories;
  23. import com.sun.corba.se.impl.orbutil.ORBUtility ;
  24. import com.sun.corba.se.spi.orb.ORB ;
  25. /** This is an implementation of the ObjectReferenceFactory abstract value
  26. * type defined by the portable interceptors IDL.
  27. * Note that this is a direct Java implementation
  28. * of the abstract value type: there is no stateful value type defined in IDL,
  29. * since defining the state in IDL is awkward and inefficient. The best way
  30. * to define the state is to use internal data structures that can be written
  31. * to and read from CORBA streams.
  32. */
  33. public class ObjectReferenceFactoryImpl extends ObjectReferenceProducerBase
  34. implements ObjectReferenceFactory, StreamableValue
  35. {
  36. transient private IORTemplateList iorTemplates ;
  37. public ObjectReferenceFactoryImpl( InputStream is )
  38. {
  39. super( (ORB)(is.orb()) ) ;
  40. _read( is ) ;
  41. }
  42. public ObjectReferenceFactoryImpl( ORB orb, IORTemplateList iortemps )
  43. {
  44. super( orb ) ;
  45. iorTemplates = iortemps ;
  46. }
  47. public boolean equals( Object obj )
  48. {
  49. if (!(obj instanceof ObjectReferenceFactoryImpl))
  50. return false ;
  51. ObjectReferenceFactoryImpl other = (ObjectReferenceFactoryImpl)obj ;
  52. return (iorTemplates != null) &&
  53. iorTemplates.equals( other.iorTemplates ) ;
  54. }
  55. public int hashCode()
  56. {
  57. return iorTemplates.hashCode() ;
  58. }
  59. // Note that this repository ID must reflect the implementation
  60. // of the abstract valuetype (that is, this class), not the
  61. // repository ID of the org.omg.PortableInterceptor.ObjectReferenceFactory
  62. // class. This allows for multiple independent implementations
  63. // of the abstract valuetype, should that become necessary.
  64. public static final String repositoryId =
  65. "IDL:com/sun/corba/se/impl/ior/ObjectReferenceFactoryImpl:1.0" ;
  66. public String[] _truncatable_ids()
  67. {
  68. return new String[] { repositoryId } ;
  69. }
  70. public TypeCode _type()
  71. {
  72. return ObjectReferenceFactoryHelper.type() ;
  73. }
  74. /** Read the data into a (presumably) empty ObjectReferenceFactoryImpl.
  75. * This sets the orb to the ORB of the InputStream.
  76. */
  77. public void _read( InputStream is )
  78. {
  79. org.omg.CORBA_2_3.portable.InputStream istr =
  80. (org.omg.CORBA_2_3.portable.InputStream)is ;
  81. iorTemplates = IORFactories.makeIORTemplateList( istr ) ;
  82. }
  83. /** Write the state to the OutputStream.
  84. */
  85. public void _write( OutputStream os )
  86. {
  87. org.omg.CORBA_2_3.portable.OutputStream ostr =
  88. (org.omg.CORBA_2_3.portable.OutputStream)os ;
  89. iorTemplates.write( ostr ) ;
  90. }
  91. public IORFactory getIORFactory()
  92. {
  93. return iorTemplates ;
  94. }
  95. public IORTemplateList getIORTemplateList()
  96. {
  97. return iorTemplates ;
  98. }
  99. }