KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > naming > cosnaming > TransientNameService


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
8 package com.sun.corba.se.impl.naming.cosnaming;
9
10 // Get CORBA type
11
import org.omg.CORBA.INITIALIZE JavaDoc;
12 import org.omg.CORBA.ORB JavaDoc;
13 import org.omg.CORBA.CompletionStatus JavaDoc;
14
15 import org.omg.CORBA.Policy JavaDoc;
16 import org.omg.CORBA.INTERNAL JavaDoc;
17 import org.omg.PortableServer.POA JavaDoc;
18 import org.omg.PortableServer.LifespanPolicyValue JavaDoc;
19 import org.omg.PortableServer.RequestProcessingPolicyValue JavaDoc;
20 import org.omg.PortableServer.IdAssignmentPolicyValue JavaDoc;
21 import org.omg.PortableServer.ServantRetentionPolicyValue JavaDoc;
22
23 // Get org.omg.CosNaming types
24
import org.omg.CosNaming.NamingContext JavaDoc;
25
26 // Import transient naming context
27
import com.sun.corba.se.impl.naming.cosnaming.TransientNamingContext;
28 import com.sun.corba.se.impl.orbutil.ORBConstants;
29
30 import com.sun.corba.se.spi.logging.CORBALogDomains;
31
32 import com.sun.corba.se.impl.logging.NamingSystemException;
33
34 /**
35  * Class TransientNameService implements a transient name service
36  * using TransientNamingContexts and TransientBindingIterators, which
37  * implement the org.omg.CosNaming::NamingContext and org.omg.CosNaming::BindingIterator
38  * interfaces specfied by the OMG Common Object Services Specification.
39  * <p>
40  * The TransientNameService creates the initial NamingContext object.
41  * @see NamingContextImpl
42  * @see BindingIteratorImpl
43  * @see TransientNamingContext
44  * @see TransientBindingIterator
45  */

46 public class TransientNameService
47 {
48     /**
49      * Constructs a new TransientNameService, and creates an initial
50      * NamingContext, whose object
51      * reference can be obtained by the initialNamingContext method.
52      * @param orb The ORB object
53      * @exception org.omg.CORBA.INITIALIZE Thrown if
54      * the TransientNameService cannot initialize.
55      */

56     public TransientNameService(com.sun.corba.se.spi.orb.ORB orb )
57         throws org.omg.CORBA.INITIALIZE JavaDoc
58     {
59         // Default constructor uses "NameService" as the key for the Root Naming
60
// Context. If default constructor is used then INS's object key for
61
// Transient Name Service is "NameService"
62
initialize( orb, "NameService" );
63     }
64
65     /**
66      * Constructs a new TransientNameService, and creates an initial
67      * NamingContext, whose object
68      * reference can be obtained by the initialNamingContext method.
69      * @param orb The ORB object
70      * @param nameserviceName Stringified key used for INS Service registry
71      * @exception org.omg.CORBA.INITIALIZE Thrown if
72      * the TransientNameService cannot initialize.
73      */

74     public TransientNameService(com.sun.corba.se.spi.orb.ORB orb,
75         String JavaDoc serviceName ) throws org.omg.CORBA.INITIALIZE JavaDoc
76     {
77         // This constructor gives the flexibility of providing the Object Key
78
// for the Root Naming Context that is registered with INS.
79
initialize( orb, serviceName );
80     }
81
82
83     /**
84      * This method initializes Transient Name Service by associating Root
85      * context with POA and registering the root context with INS Object Keymap.
86      */

87     private void initialize( com.sun.corba.se.spi.orb.ORB orb,
88         String JavaDoc nameServiceName )
89         throws org.omg.CORBA.INITIALIZE JavaDoc
90     {
91     NamingSystemException wrapper = NamingSystemException.get( orb,
92         CORBALogDomains.NAMING ) ;
93
94         try {
95             POA JavaDoc rootPOA = (POA JavaDoc) orb.resolve_initial_references(
96         ORBConstants.ROOT_POA_NAME );
97             rootPOA.the_POAManager().activate();
98
99             int i = 0;
100             Policy JavaDoc[] poaPolicy = new Policy JavaDoc[3];
101             poaPolicy[i++] = rootPOA.create_lifespan_policy(
102                 LifespanPolicyValue.TRANSIENT);
103             poaPolicy[i++] = rootPOA.create_id_assignment_policy(
104                 IdAssignmentPolicyValue.SYSTEM_ID);
105             poaPolicy[i++] = rootPOA.create_servant_retention_policy(
106                 ServantRetentionPolicyValue.RETAIN);
107
108             POA JavaDoc nsPOA = rootPOA.create_POA( "TNameService", null, poaPolicy );
109             nsPOA.the_POAManager().activate();
110
111             // Create an initial context
112
TransientNamingContext initialContext =
113                 new TransientNamingContext(orb, null, nsPOA);
114             byte[] rootContextId = nsPOA.activate_object( initialContext );
115             initialContext.localRoot =
116                 nsPOA.id_to_reference( rootContextId );
117             theInitialNamingContext = initialContext.localRoot;
118             orb.register_initial_reference( nameServiceName,
119                 theInitialNamingContext );
120         } catch (org.omg.CORBA.SystemException JavaDoc e) {
121         throw wrapper.transNsCannotCreateInitialNcSys( e ) ;
122         } catch (Exception JavaDoc e) {
123         throw wrapper.transNsCannotCreateInitialNc( e ) ;
124         }
125     }
126
127
128     /**
129      * Return the initial NamingContext.
130      * @return the object reference for the initial NamingContext.
131      */

132     public org.omg.CORBA.Object JavaDoc initialNamingContext()
133     {
134     return theInitialNamingContext;
135     }
136
137
138     // The initial naming context for this name service
139
private org.omg.CORBA.Object JavaDoc theInitialNamingContext;
140 }
141
Popular Tags