KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > naming > cos > CosNamingContextManager


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * CosNamingContextManager.java
20  *
21  * This class is responsible for managing the naming naming context.
22  */

23
24 // package path
25
package com.rift.coad.lib.naming.cos;
26
27 // java imports
28
import java.util.Hashtable JavaDoc;
29
30 // coadunation imports
31
import com.rift.coad.lib.naming.NamingContextManager;
32 import com.rift.coad.lib.naming.NamingException;
33 import com.rift.coad.lib.naming.OrbManager;
34 import com.rift.coad.lib.thread.CoadunationThreadGroup;
35
36 /**
37  * This class is responsible for managing the naming naming context.
38  *
39  * @author Brett Chaldecott
40  */

41 public class CosNamingContextManager implements NamingContextManager {
42     
43     // the class singleton, this is not a traditionally clean way of doing this
44
// but since this object is started from another singleton it will not
45
// cause any problems
46
private static CosNamingContextManager singleton = null;
47     
48     // classes private member variables
49
private MasterContext masterContext = null;
50     
51     /**
52      * Creates a new instance of CosNamingContextManager
53      *
54      * @param threadGroup The coadunation thread group.
55      * @param orbManager The reference to the orb manager.
56      * @param instanceId The reference to the instance id of this Coadunation
57      * Server.
58      * @exception CosNamingException
59      */

60     public CosNamingContextManager(CoadunationThreadGroup threadGroup,
61             OrbManager orbManager, String JavaDoc instanceId) throws
62             CosNamingException {
63         try {
64             singleton = this;
65             masterContext = new MasterContext(new Hashtable JavaDoc(),threadGroup,
66                     orbManager,instanceId);
67         } catch (Exception JavaDoc ex) {
68             throw new CosNamingException("Failed to instanicate the cos naming " +
69                     "context manager : " + ex.getMessage());
70         }
71     }
72     
73     
74     /**
75      * The singleton method to retrieve a reference to the cos naming context
76      * manager.
77      *
78      * @return A reference to
79      */

80     public static CosNamingContextManager getInstance() throws
81             CosNamingException {
82         if (singleton == null) {
83             throw new CosNamingException("The COS naming context manager has " +
84                     "not been initialized.");
85         }
86         return singleton;
87     }
88     
89     
90     /**
91      * This method returns the string identifying the context factory.
92      *
93      * @return The string containing the class name of the initial context
94      * factory.
95      */

96     public String JavaDoc getInitialContextFactory() {
97         return "com.rift.coad.lib.naming.cos.URLInitialContextFactory";
98     }
99     
100     
101     /**
102      * The url packages.
103      *
104      * @return Returns the string name for the class responsible for the URL
105      * packages.
106      */

107     public String JavaDoc getURLContextFactory() {
108         return "com.rift.coad.lib.naming.cos.javaURLContextFactory";
109     }
110     
111     /**
112      * This method is called to init the context for a class loader.
113      *
114      * @exception NamingException
115      */

116     public void initContext() throws NamingException {
117         masterContext.initContext();
118     }
119     
120     
121     /**
122      * This method is called to release the context for class loader.
123      */

124     public void releaseContext() {
125         masterContext.releaseContext();
126     }
127     
128     
129     /**
130      * The method to shut down the naming context.
131      */

132     public void shutdown() {
133         masterContext.terminate();
134     }
135     
136     
137     /**
138      * This method returns the current master context
139      */

140     public MasterContext getMasterContext() {
141         return masterContext;
142     }
143 }
144
Popular Tags