1. /*
  2. * @(#)IIOPProfile.java 1.28 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. //Source file: J:/ws/serveractivation/src/share/classes/com.sun.corba.se.internal.ior/IIOPProfile.java
  8. package com.sun.corba.se.internal.ior;
  9. import java.util.List ;
  10. import java.util.Iterator ;
  11. import com.sun.corba.se.internal.ior.IdEncapsulationBase ;
  12. import com.sun.corba.se.internal.ior.TaggedProfile ;
  13. import com.sun.corba.se.internal.ior.ObjectId ;
  14. import com.sun.corba.se.internal.ior.IIOPProfileTemplate ;
  15. import com.sun.corba.se.internal.ior.IIOPAddressImpl ;
  16. import com.sun.corba.se.internal.ior.ObjectKey ;
  17. import com.sun.corba.se.internal.ior.ObjectKeyFactory ;
  18. import com.sun.corba.se.internal.ior.AlternateIIOPAddressComponent ;
  19. import com.sun.corba.se.internal.ior.TaggedComponentFactoryFinder ;
  20. import org.omg.CORBA.BAD_PARAM;
  21. import org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS ;
  22. import org.omg.IOP.TAG_INTERNET_IOP;
  23. import org.omg.CORBA.ORB ;
  24. import org.omg.CORBA.CompletionStatus;
  25. import org.omg.CORBA_2_3.portable.OutputStream ;
  26. import org.omg.CORBA_2_3.portable.InputStream ;
  27. import com.sun.corba.se.internal.iiop.CDRInputStream ;
  28. import com.sun.corba.se.internal.corba.EncapsInputStream ;
  29. import com.sun.corba.se.internal.corba.EncapsOutputStream ;
  30. import com.sun.corba.se.internal.core.GIOPVersion ;
  31. import com.sun.corba.se.internal.orbutil.MinorCodes;
  32. /**
  33. * @author
  34. */
  35. public class IIOPProfile extends IdEncapsulationBase
  36. implements TaggedProfile
  37. {
  38. private ObjectId id;
  39. private final IIOPProfileTemplate template;
  40. public boolean equals( Object obj )
  41. {
  42. if (obj == null)
  43. return false ;
  44. if (!(obj instanceof IIOPProfile))
  45. return false ;
  46. IIOPProfile other = (IIOPProfile)obj ;
  47. return id.equals( other.id ) && template.equals( other.template ) ;
  48. }
  49. public ObjectId getObjectId()
  50. {
  51. return id ;
  52. }
  53. public IIOPProfileTemplate getTemplate()
  54. {
  55. return template ;
  56. }
  57. public IIOPProfile( ObjectId id, IIOPProfileTemplate template )
  58. {
  59. this.id = id ;
  60. this.template = template ;
  61. }
  62. public IIOPProfile( InputStream is )
  63. {
  64. InputStream istr = IdEncapsulationBase.getEncapsulationStream( is ) ;
  65. // First, read all of the IIOP IOR data
  66. byte major = istr.read_octet() ;
  67. byte minor = istr.read_octet() ;
  68. IIOPAddress primary = new IIOPAddressImpl( istr ) ;
  69. byte[] key = IdEncapsulationBase.readOctets( istr ) ;
  70. ORB orb = ((CDRInputStream)is).orb() ;
  71. ObjectKey okey = ObjectKeyFactory.get().create( orb, key ) ;
  72. id = okey.getId() ;
  73. template = new IIOPProfileTemplate( major, minor, primary,
  74. okey.getTemplate() ) ;
  75. // Handle any tagged components (if applicable)
  76. if (minor > 0)
  77. template.readIdEncapsulationSequence(
  78. TaggedComponentFactoryFinder.getFinder(), istr ) ;
  79. }
  80. public IIOPProfile(org.omg.CORBA.ORB orb,
  81. org.omg.IOP.TaggedProfile profile) {
  82. if (profile == null ||
  83. profile.tag != TAG_INTERNET_IOP.value ||
  84. profile.profile_data == null) {
  85. throw new BAD_PARAM(MinorCodes.INVALID_TAGGED_PROFILE,
  86. CompletionStatus.COMPLETED_NO);
  87. }
  88. EncapsInputStream istr = new EncapsInputStream(orb,
  89. profile.profile_data,
  90. profile.profile_data.length);
  91. istr.consumeEndian();
  92. // First, read all of the IIOP IOR data
  93. byte major = istr.read_octet() ;
  94. byte minor = istr.read_octet() ;
  95. IIOPAddress primary = new IIOPAddressImpl(istr);
  96. byte[] key = IdEncapsulationBase.readOctets(istr);
  97. ObjectKey okey = ObjectKeyFactory.get().create(orb, key);
  98. id = okey.getId();
  99. template = new IIOPProfileTemplate(major, minor, primary,
  100. okey.getTemplate());
  101. // Handle any tagged components (if applicable)
  102. if (minor > 0) {
  103. template.readIdEncapsulationSequence(
  104. TaggedComponentFactoryFinder.getFinder(), istr);
  105. }
  106. }
  107. /**
  108. * @param arg0
  109. * @return void
  110. * @exception
  111. * @author
  112. * @roseuid 39135D2D02EC
  113. */
  114. public void writeContents(OutputStream os)
  115. {
  116. template.write( id, os ) ;
  117. }
  118. /**
  119. * @return int
  120. * @exception
  121. * @author
  122. * @roseuid 39135D2E00C7
  123. */
  124. public int getId()
  125. {
  126. return template.getId() ;
  127. }
  128. public boolean isEquivalent( IIOPProfile prof )
  129. {
  130. return id.equals( prof.id ) && template.isEquivalent( prof.template ) ;
  131. }
  132. public ObjectKey getObjectKey()
  133. {
  134. ObjectKeyTemplate oktemp = template.getObjectKeyTemplate() ;
  135. ObjectKey result = new ObjectKey( oktemp, id ) ;
  136. return result ;
  137. }
  138. public org.omg.IOP.TaggedProfile getIOPProfile( ORB orb )
  139. {
  140. EncapsOutputStream os = new EncapsOutputStream( orb ) ;
  141. os.write_long( getId() ) ;
  142. write( os ) ;
  143. InputStream is = (InputStream)(os.create_input_stream()) ;
  144. return org.omg.IOP.TaggedProfileHelper.read( is ) ;
  145. }
  146. /**
  147. * @return org.omg.IOP.TaggedComponent[]
  148. * @exception
  149. * @author
  150. * @roseuid 3980B6A4037F
  151. */
  152. public org.omg.IOP.TaggedComponent[] getIOPComponents(
  153. ORB orb, int id )
  154. {
  155. int count = 0 ;
  156. Iterator iter = template.iteratorById( id ) ;
  157. while (iter.hasNext()) {
  158. iter.next() ;
  159. count++ ;
  160. }
  161. org.omg.IOP.TaggedComponent[] result = new
  162. org.omg.IOP.TaggedComponent[count] ;
  163. int index = 0 ;
  164. iter = template.iteratorById( id ) ;
  165. while (iter.hasNext()) {
  166. TaggedComponent comp = (TaggedComponent)(iter.next()) ;
  167. result[index++] = comp.getIOPComponent( orb ) ;
  168. }
  169. return result ;
  170. }
  171. }