1. /*
  2. * @(#)TransientNameService.java 1.48 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.naming.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.PortableServer.POA;
  15. import org.omg.PortableServer.LifespanPolicyValue;
  16. import org.omg.PortableServer.RequestProcessingPolicyValue;
  17. import org.omg.PortableServer.IdAssignmentPolicyValue;
  18. import org.omg.PortableServer.ServantRetentionPolicyValue;
  19. // Get org.omg.CosNaming types
  20. import org.omg.CosNaming.NamingContext;
  21. // Import transient naming context
  22. import com.sun.corba.se.impl.naming.cosnaming.TransientNamingContext;
  23. import com.sun.corba.se.impl.orbutil.ORBConstants;
  24. import com.sun.corba.se.spi.logging.CORBALogDomains;
  25. import com.sun.corba.se.impl.logging.NamingSystemException;
  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.spi.orb.ORB 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.spi.orb.ORB 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.spi.orb.ORB orb,
  77. String nameServiceName )
  78. throws org.omg.CORBA.INITIALIZE
  79. {
  80. NamingSystemException wrapper = NamingSystemException.get( orb,
  81. CORBALogDomains.NAMING ) ;
  82. try {
  83. POA rootPOA = (POA) orb.resolve_initial_references(
  84. ORBConstants.ROOT_POA_NAME );
  85. rootPOA.the_POAManager().activate();
  86. int i = 0;
  87. Policy[] poaPolicy = new Policy[3];
  88. poaPolicy[i++] = rootPOA.create_lifespan_policy(
  89. LifespanPolicyValue.TRANSIENT);
  90. poaPolicy[i++] = rootPOA.create_id_assignment_policy(
  91. IdAssignmentPolicyValue.SYSTEM_ID);
  92. poaPolicy[i++] = rootPOA.create_servant_retention_policy(
  93. ServantRetentionPolicyValue.RETAIN);
  94. POA nsPOA = rootPOA.create_POA( "TNameService", null, poaPolicy );
  95. nsPOA.the_POAManager().activate();
  96. // Create an initial context
  97. TransientNamingContext initialContext =
  98. new TransientNamingContext(orb, null, nsPOA);
  99. byte[] rootContextId = nsPOA.activate_object( initialContext );
  100. initialContext.localRoot =
  101. nsPOA.id_to_reference( rootContextId );
  102. theInitialNamingContext = initialContext.localRoot;
  103. orb.register_initial_reference( nameServiceName,
  104. theInitialNamingContext );
  105. } catch (org.omg.CORBA.SystemException e) {
  106. throw wrapper.transNsCannotCreateInitialNcSys( e ) ;
  107. } catch (Exception e) {
  108. throw wrapper.transNsCannotCreateInitialNc( e ) ;
  109. }
  110. }
  111. /**
  112. * Return the initial NamingContext.
  113. * @return the object reference for the initial NamingContext.
  114. */
  115. public org.omg.CORBA.Object initialNamingContext()
  116. {
  117. return theInitialNamingContext;
  118. }
  119. // The initial naming context for this name service
  120. private org.omg.CORBA.Object theInitialNamingContext;
  121. }