1. /*
  2. * @(#)IORInfoImpl.java 1.21 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. package com.sun.corba.se.internal.Interceptors;
  8. import org.omg.PortableInterceptor.IORInfo;
  9. import com.sun.corba.se.interceptor.IORInfoExt;
  10. import com.sun.corba.se.interceptor.UnknownType;
  11. import com.sun.corba.se.internal.POA.POAImpl;
  12. import com.sun.corba.se.internal.ior.IORTemplate;
  13. import com.sun.corba.se.internal.ior.TaggedProfileTemplate;
  14. import com.sun.corba.se.internal.ior.TaggedComponentFactoryFinder;
  15. import org.omg.IOP.TaggedComponent;
  16. import org.omg.CORBA.BAD_PARAM;
  17. import org.omg.CORBA.CompletionStatus;
  18. import org.omg.CORBA.INV_POLICY;
  19. import org.omg.CORBA.NO_IMPLEMENT;
  20. import org.omg.CORBA.Policy;
  21. import org.omg.CORBA.LocalObject;
  22. import org.omg.CORBA.ORB ;
  23. import java.util.*;
  24. /**
  25. * IORInfoImpl is the implementation of the IORInfo class, as described
  26. * in orbos/99-12-02, section 7.
  27. */
  28. public final class IORInfoImpl
  29. extends LocalObject
  30. implements IORInfo, IORInfoExt
  31. {
  32. // The ORB
  33. private ORB orb;
  34. // The POAImpl associated with this IORInfo object.
  35. private POAImpl poaImpl;
  36. /**
  37. * Creates a new IORInfo implementation. This info object will establish
  38. * tagged components with the template for the provided IOR Template.
  39. */
  40. IORInfoImpl( ORB orb, POAImpl poaImpl ) {
  41. this.orb = orb;
  42. this.poaImpl = poaImpl;
  43. }
  44. /**
  45. * An ORB service implementation may determine what server side policy
  46. * of a particular type is in effect for an IOR being constructed by
  47. * calling the get_effective_policy operation. When the IOR being
  48. * constructed is for an object implemented using a POA, all Policy
  49. * objects passed to the PortableServer::POA::create_POA call that
  50. * created that POA are accessible via get_effective_policy.
  51. * <p>
  52. * If a policy for the given type is not known to the ORB, then this
  53. * operation will raise INV_POLICY with a standard minor code of 2.
  54. *
  55. * @param type The CORBA::PolicyType specifying the type of policy to
  56. * return.
  57. * @return The effective CORBA::Policy object of the requested type.
  58. * If the given policy type is known, but no policy of that tpye is
  59. * in effect, then this operation will return a nil object reference.
  60. */
  61. public Policy get_effective_policy (int type) {
  62. return poaImpl.get_effective_policy( type );
  63. }
  64. /**
  65. * A portable ORB service implementation calls this method from its
  66. * implementation of establish_components to add a tagged component to
  67. * the set which will be included when constructing IORs. The
  68. * components in this set will be included in all profiles.
  69. * <p>
  70. * Any number of components may exist with the same component ID.
  71. *
  72. * @param tagged_component The IOP::TaggedComponent to add
  73. */
  74. public void add_ior_component (TaggedComponent tagged_component) {
  75. if( tagged_component == null ) nullParam();
  76. addIORComponentToProfileInternal( tagged_component,
  77. poaImpl.getIORTemplate().iterator());
  78. }
  79. /**
  80. * A portable ORB service implementation calls this method from its
  81. * implementation of establish_components to add a tagged component to
  82. * the set which will be included when constructing IORs. The
  83. * components in this set will be included in the specified profile.
  84. * <p>
  85. * Any number of components may exist with the same component ID.
  86. * <p>
  87. * If the given profile ID does not define a known profile or it is
  88. * impossible to add components to thgat profile, BAD_PARAM is raised
  89. * with a minor code of TBD_BP + 3.
  90. *
  91. * @param tagged_component The IOP::TaggedComponent to add.
  92. * @param profile_id The IOP::ProfileId tof the profile to which this
  93. * component will be added.
  94. */
  95. public void add_ior_component_to_profile (
  96. TaggedComponent tagged_component, int profile_id )
  97. {
  98. if( tagged_component == null ) nullParam();
  99. addIORComponentToProfileInternal(
  100. tagged_component, poaImpl.getIORTemplate().iteratorById(
  101. profile_id ) );
  102. }
  103. /**
  104. * @param type The type of the server port
  105. * (see connection.ORBSocketFactory for discussion).
  106. * @return The listen port number for that type.
  107. * @throws UnknownType if no port of the given type is found.
  108. */
  109. public int getServerPort(String type)
  110. throws
  111. UnknownType
  112. {
  113. int port = ((com.sun.corba.se.internal.Interceptors.PIORB)orb)
  114. .getServerPort(type);
  115. if (port == -1) {
  116. throw new UnknownType();
  117. }
  118. return port;
  119. }
  120. /**
  121. * Internal utility method to add an IOR component to the set of profiles
  122. * present in the iterator.
  123. */
  124. private void addIORComponentToProfileInternal(
  125. TaggedComponent tagged_component, Iterator iterator )
  126. {
  127. // Convert the given IOP::TaggedComponent into the appropriate
  128. // type for the TaggedProfileTemplate
  129. TaggedComponentFactoryFinder finder =
  130. TaggedComponentFactoryFinder.getFinder();
  131. Object newTaggedComponent = finder.create( orb, tagged_component );
  132. // Iterate through TaggedProfileTemplates and add the given tagged
  133. // component to the appropriate one(s).
  134. boolean found = false;
  135. while( iterator.hasNext() ) {
  136. found = true;
  137. TaggedProfileTemplate taggedProfileTemplate =
  138. (TaggedProfileTemplate)iterator.next();
  139. taggedProfileTemplate.add( newTaggedComponent );
  140. }
  141. // If no profile was found with the given id, throw a BAD_PARAM:
  142. // (See orbos/00-08-06, section 21.5.3.3.)
  143. if( !found ) {
  144. throw new BAD_PARAM(
  145. "Profile ID does not define a known profile or it is " +
  146. "impossible to add components to that profile.",
  147. com.sun.corba.se.internal.Interceptors.MinorCodes.
  148. INVALID_PROFILE_ID, CompletionStatus.COMPLETED_NO );
  149. }
  150. }
  151. /**
  152. * Called when an invalid null parameter was passed. Throws a
  153. * BAD_PARAM with a minor code of 1
  154. */
  155. private void nullParam()
  156. throws BAD_PARAM
  157. {
  158. throw new BAD_PARAM(
  159. com.sun.corba.se.internal.orbutil.MinorCodes.NULL_PARAM,
  160. CompletionStatus.COMPLETED_NO );
  161. }
  162. }