1. /*
  2. * @(#)IORTemplateImpl.java 1.14 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.INTERNAL ;
  10. import org.omg.CORBA_2_3.portable.OutputStream ;
  11. import org.omg.CORBA_2_3.portable.InputStream ;
  12. import org.omg.IOP.TAG_INTERNET_IOP ;
  13. import com.sun.corba.se.spi.ior.IdentifiableContainerBase ;
  14. import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ;
  15. import com.sun.corba.se.spi.ior.IORTemplate ;
  16. import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
  17. import com.sun.corba.se.spi.ior.TaggedProfileTemplate ;
  18. import com.sun.corba.se.spi.ior.ObjectId ;
  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.orb.ORB ;
  22. /**
  23. * This class is a container of TaggedProfileTemplates.
  24. * @author
  25. */
  26. public class IORTemplateImpl extends IdentifiableContainerBase implements IORTemplate
  27. {
  28. private ObjectKeyTemplate oktemp ;
  29. public boolean equals( Object obj )
  30. {
  31. if (obj == null)
  32. return false ;
  33. if (!(obj instanceof IORTemplateImpl))
  34. return false ;
  35. IORTemplateImpl other = (IORTemplateImpl)obj ;
  36. return super.equals( obj ) && oktemp.equals( other.getObjectKeyTemplate() ) ;
  37. }
  38. public int hashCode()
  39. {
  40. return super.hashCode() ^ oktemp.hashCode() ;
  41. }
  42. public ObjectKeyTemplate getObjectKeyTemplate()
  43. {
  44. return oktemp ;
  45. }
  46. public IORTemplateImpl( ObjectKeyTemplate oktemp )
  47. {
  48. this.oktemp = oktemp ;
  49. }
  50. public IOR makeIOR( ORB orb, String typeid, ObjectId oid )
  51. {
  52. return new IORImpl( orb, typeid, this, oid ) ;
  53. }
  54. public boolean isEquivalent( IORFactory other )
  55. {
  56. if (!(other instanceof IORTemplate))
  57. return false ;
  58. IORTemplate list = (IORTemplate)other ;
  59. Iterator thisIterator = iterator() ;
  60. Iterator listIterator = list.iterator() ;
  61. while (thisIterator.hasNext() && listIterator.hasNext()) {
  62. TaggedProfileTemplate thisTemplate =
  63. (TaggedProfileTemplate)thisIterator.next() ;
  64. TaggedProfileTemplate listTemplate =
  65. (TaggedProfileTemplate)listIterator.next() ;
  66. if (!thisTemplate.isEquivalent( listTemplate ))
  67. return false ;
  68. }
  69. return (thisIterator.hasNext() == listIterator.hasNext()) &&
  70. getObjectKeyTemplate().equals( list.getObjectKeyTemplate() ) ;
  71. }
  72. /** Ensure that this IORTemplate and all of its profiles can not be
  73. * modified. This overrides the method inherited from
  74. * FreezableList through IdentifiableContainerBase.
  75. */
  76. public void makeImmutable()
  77. {
  78. makeElementsImmutable() ;
  79. super.makeImmutable() ;
  80. }
  81. public void write( OutputStream os )
  82. {
  83. oktemp.write( os ) ;
  84. EncapsulationUtility.writeIdentifiableSequence( this, os ) ;
  85. }
  86. public IORTemplateImpl( InputStream is )
  87. {
  88. ORB orb = (ORB)(is.orb()) ;
  89. IdentifiableFactoryFinder finder =
  90. orb.getTaggedProfileTemplateFactoryFinder() ;
  91. oktemp = orb.getObjectKeyFactory().createTemplate( is ) ;
  92. EncapsulationUtility.readIdentifiableSequence( this, finder, is ) ;
  93. makeImmutable() ;
  94. }
  95. }