1. /*
  2. * @(#)TransientNameService.java 1.45 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.CosNaming;
  8. // Get CORBA type
  9. import org.omg.CORBA.INITIALIZE;
  10. import org.omg.CORBA.ORB;
  11. import org.omg.CORBA.CompletionStatus;
  12. import org.omg.CORBA.Policy;
  13. import org.omg.CORBA.INTERNAL;
  14. import org.omg.CORBA.portable.ObjectImpl;
  15. import org.omg.PortableServer.POA;
  16. import org.omg.PortableServer.LifespanPolicyValue;
  17. import org.omg.PortableServer.RequestProcessingPolicyValue;
  18. import org.omg.PortableServer.IdAssignmentPolicyValue;
  19. import org.omg.PortableServer.ServantRetentionPolicyValue;
  20. // Get org.omg.CosNaming types
  21. import org.omg.CosNaming.NamingContext;
  22. // Import transient naming context
  23. import com.sun.corba.se.internal.CosNaming.TransientNamingContext;
  24. import com.sun.corba.se.internal.orbutil.ORBConstants;
  25. import com.sun.corba.se.internal.POA.*;
  26. /**
  27. * Class TransientNameService implements a transient name service
  28. * using TransientNamingContexts and TransientBindingIterators, which
  29. * implement the org.omg.CosNaming::NamingContext and org.omg.CosNaming::BindingIterator
  30. * interfaces specfied by the OMG Common Object Services Specification.
  31. * <p>
  32. * The TransientNameService creates the initial NamingContext object.
  33. * @see NamingContextImpl
  34. * @see BindingIteratorImpl
  35. * @see TransientNamingContext
  36. * @see TransientBindingIterator
  37. */
  38. public class TransientNameService
  39. {
  40. /**
  41. * Constructs a new TransientNameService, and creates an initial
  42. * NamingContext, whose object
  43. * reference can be obtained by the initialNamingContext method.
  44. * @param orb The ORB object
  45. * @exception org.omg.CORBA.INITIALIZE Thrown if
  46. * the TransientNameService cannot initialize.
  47. */
  48. public TransientNameService(com.sun.corba.se.internal.POA.POAORB orb )
  49. throws org.omg.CORBA.INITIALIZE
  50. {
  51. // Default constructor uses "NameService" as the key for the Root Naming
  52. // Context. If default constructor is used then INS's object key for
  53. // Transient Name Service is "NameService"
  54. initialize( orb, "NameService" );
  55. }
  56. /**
  57. * Constructs a new TransientNameService, and creates an initial
  58. * NamingContext, whose object
  59. * reference can be obtained by the initialNamingContext method.
  60. * @param orb The ORB object
  61. * @param nameserviceName Stringified key used for INS Service registry
  62. * @exception org.omg.CORBA.INITIALIZE Thrown if
  63. * the TransientNameService cannot initialize.
  64. */
  65. public TransientNameService(com.sun.corba.se.internal.POA.POAORB orb,
  66. String serviceName ) throws org.omg.CORBA.INITIALIZE
  67. {
  68. // This constructor gives the flexibility of providing the Object Key
  69. // for the Root Naming Context that is registered with INS.
  70. initialize( orb, serviceName );
  71. }
  72. /**
  73. * This method initializes Transient Name Service by associating Root
  74. * context with POA and registering the root context with INS Object Keymap.
  75. */
  76. private void initialize( com.sun.corba.se.internal.POA.POAORB orb,
  77. String nameServiceName )
  78. throws org.omg.CORBA.INITIALIZE
  79. {
  80. try {
  81. POA rootPOA = (POA) orb.resolve_initial_references( "RootPOA" );
  82. rootPOA.the_POAManager().activate();
  83. int i = 0;
  84. Policy[] poaPolicy = new Policy[3];
  85. poaPolicy[i++] = rootPOA.create_lifespan_policy(
  86. LifespanPolicyValue.TRANSIENT);
  87. poaPolicy[i++] = rootPOA.create_id_assignment_policy(
  88. IdAssignmentPolicyValue.SYSTEM_ID);
  89. poaPolicy[i++] = rootPOA.create_servant_retention_policy(
  90. ServantRetentionPolicyValue.RETAIN);
  91. POA nsPOA = rootPOA.create_POA( "TNameService", null, poaPolicy );
  92. nsPOA.the_POAManager().activate();
  93. // Create an initial context
  94. TransientNamingContext initialContext =
  95. new TransientNamingContext(orb, null, nsPOA);
  96. byte[] rootContextId = nsPOA.activate_object( initialContext );
  97. initialContext.localRoot =
  98. nsPOA.id_to_reference( rootContextId );
  99. theInitialNamingContext = initialContext.localRoot;
  100. orb.register_initial_reference( nameServiceName,
  101. theInitialNamingContext );
  102. } catch (org.omg.CORBA.SystemException e) {
  103. NamingUtils.printException(e);
  104. throw new org.omg.CORBA.INITIALIZE(
  105. MinorCodes.TRANS_NS_CANNOT_CREATE_INITIAL_NC_SYS,
  106. CompletionStatus.COMPLETED_NO);
  107. } catch (Exception e) {
  108. NamingUtils.printException(e);
  109. throw new org.omg.CORBA.INITIALIZE(
  110. MinorCodes.TRANS_NS_CANNOT_CREATE_INITIAL_NC,
  111. CompletionStatus.COMPLETED_NO);
  112. }
  113. }
  114. /**
  115. * Return the initial NamingContext.
  116. * @return the object reference for the initial NamingContext.
  117. */
  118. public org.omg.CORBA.Object initialNamingContext()
  119. {
  120. return theInitialNamingContext;
  121. }
  122. // The initial naming context for this name service
  123. private org.omg.CORBA.Object theInitialNamingContext;
  124. }