KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Components > HomeManagerImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Mathieu Vadet, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.Components;
28
29 import org.objectweb.openccm.Components.HomeManagerPOA;
30 import org.objectweb.openccm.Components.HomeInfo;
31
32 /**
33  * Implementation of the OpenCCM::HomeManager interface.
34  *
35  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
36  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
37  *
38  * @version 0.3
39  */

40
41 public class HomeManagerImpl
42      extends HomeManagerPOA
43 {
44     // ==================================================================
45
//
46
// Internal state.
47
//
48
// ==================================================================
49

50     /**
51      ** To store (cookie, HomeInfo) associations.
52      **/

53     private org.objectweb.ccm.util.Table by_cookies_;
54
55     /**
56      ** To store (home_repid, CCMHome) associations.
57      **/

58     private org.objectweb.ccm.util.Table by_home_repids_;
59
60     /**
61      ** To store (component_repid, CCMHome) associations.
62      **/

63     private org.objectweb.ccm.util.Table by_component_repids_;
64
65     /**
66      ** To store (home_name, CCMHome) associations.
67      **/

68     private org.objectweb.ccm.util.Table by_home_names_;
69
70     // ==================================================================
71
//
72
// Constructor.
73
//
74
// ==================================================================
75

76     /**
77      ** The default constructor.
78      **/

79     public
80     HomeManagerImpl()
81     {
82         by_cookies_ = new org.objectweb.ccm.util.Table();
83         by_home_repids_ = new org.objectweb.ccm.util.Table();
84         by_component_repids_ = new org.objectweb.ccm.util.Table();
85         by_home_names_ = new org.objectweb.ccm.util.Table();
86     }
87
88     // ==================================================================
89
//
90
// Internal methods.
91
//
92
// ==================================================================
93

94     // ==================================================================
95
//
96
// Public methods.
97
//
98
// ==================================================================
99

100     // ==================================================================
101
//
102
// Methods for the OpenCCM::Shutdownable interface.
103
//
104
// ==================================================================
105

106     //
107
// IDL:goal.lifl.fr/OpenCCM/Shutdownable/shutdown:1.0
108
//
109
/**
110      ** Shutdown an OpenCCM server.
111      **/

112     public void
113     shutdown()
114     {
115     org.objectweb.openccm.corba.TheORB.shutdown(true);
116     }
117
118     // ==================================================================
119
//
120
// Methods for the Components::HomeFinder interface.
121
//
122
// ==================================================================
123

124     //
125
// IDL:omg.org/Components/HomeFinder/find_home_by_component_type:1.0
126
//
127
/**
128      ** Finds an home by its managed component type.
129      **
130      ** @param comp_repid The requested component repository ID.
131      **
132      ** @return The associated home.
133      **
134      ** @exception org.omg.Components.HomeNotFound
135      ** Thrown if there is no home for the requested
136      ** component type.
137      **/

138     public org.omg.Components.CCMHome
139     find_home_by_component_type(String JavaDoc comp_repid)
140     throws org.omg.Components.HomeNotFound
141     {
142     // Search by component repository id.
143
Object JavaDoc result = by_component_repids_.get(comp_repid);
144
145     // Check that a CCMHome has been found.
146
if(result == null)
147     {
148         throw new org.omg.Components.HomeNotFound();
149     }
150
151     // Return the found CCMHome.
152
return (org.omg.Components.CCMHome)result;
153     }
154
155     //
156
// IDL:omg.org/Components/HomeFinder/find_home_by_home_type:1.0
157
//
158
/**
159      ** Finds an home by its home type.
160      **
161      ** @param home_repid The requested home repository ID.
162      **
163      ** @return The associated home.
164      **
165      ** @exception org.omg.Components.HomeNotFound
166      ** Thrown if there is no home for the requested home type.
167      **/

168     public org.omg.Components.CCMHome
169     find_home_by_home_type(String JavaDoc home_repid)
170     throws org.omg.Components.HomeNotFound
171     {
172     // Search by home repository id.
173
Object JavaDoc result = by_home_repids_.get(home_repid);
174
175     // Check that a CCMHome has been found.
176
if(result == null)
177     {
178         throw new org.omg.Components.HomeNotFound();
179     }
180
181     // Return the found CCMHome.
182
return (org.omg.Components.CCMHome)result;
183     }
184
185     //
186
// IDL:omg.org/Components/HomeFinder/find_home_by_name:1.0
187
//
188
/**
189      ** Finds an home by its name.
190      **
191      ** @param home_name The requested home name.
192      **
193      ** @return The associated home.
194      **
195      ** @exception org.omg.Components.HomeNotFound
196      ** Thrown if there is no home for the requested home name.
197      **/

198     public org.omg.Components.CCMHome
199     find_home_by_name(String JavaDoc home_name)
200     throws org.omg.Components.HomeNotFound
201     {
202     // Search by home name.
203
Object JavaDoc result = by_home_names_.get(home_name);
204
205     // Check that a CCMHome has been found.
206
if(result == null)
207     {
208         throw new org.omg.Components.HomeNotFound();
209     }
210
211     // Return the found CCMHome.
212
return (org.omg.Components.CCMHome)result;
213     }
214
215     // ==================================================================
216
//
217
// Methods for the OpenCCM::Components::HomeManager interface.
218
//
219
// ==================================================================
220

221     //
222
// IDL:goal.lifl.fr/OpenCCM/Components/HomeManager/register_home:1.0
223
//
224
/**
225      ** Register a CCMHome.
226      **
227      ** @param home The CCMHome reference.
228      ** @param home_repid The CCMHome Repository Id.
229      ** @param component_repid The managed component Repository Id.
230      ** @param name The INS name associated to the home.
231      **
232      ** @return The cookie associated to this registration.
233      **/

234     public org.omg.Components.Cookie
235     register_home(org.omg.Components.CCMHome home,
236                   String JavaDoc home_repid,
237                   String JavaDoc component_repid,
238                   String JavaDoc name)
239     {
240     // Register the home by its repository Id.
241
by_home_repids_.put(home_repid, home);
242
243     // Register the home by its managed component repository Id.
244
by_component_repids_.put(component_repid, home);
245
246     // Register the home by its name.
247
by_home_names_.put(name, home);
248
249     // Generate a cookie.
250
org.omg.Components.Cookie cookie = CookieImpl.generate();
251
252     // Register the home information by the generated cookie.
253
by_cookies_.put(cookie,
254             new HomeInfo(home,
255                      home_repid,
256                      component_repid,
257                      name) );
258
259     // Return the generated cookie.
260
return cookie;
261     }
262
263     //
264
// IDL:goal.lifl.fr/OpenCCM/Components/HomeManager/unregister_home:1.0
265
//
266
/**
267      ** Unregister a CCMHome.
268      **
269      ** @param The registration cookie.
270      **
271      ** @exception ::Components::CookieRequired
272      ** Thrown when an invalid cookie is used.
273      **/

274     public void
275     unregister_home(org.omg.Components.Cookie ck)
276     throws org.omg.Components.CookieRequired
277     {
278     // Search the home info by its associated cookie.
279
HomeInfo home_info = (HomeInfo)by_cookies_.get(ck);
280
281     // Check that a home info is associated to the cookie.
282
if(home_info == null)
283     {
284         throw new org.omg.Components.CookieRequired();
285     }
286
287     // Remove in the home repository id table.
288
by_home_repids_.remove(home_info.home_repid);
289
290     // Remove in the component repository id table.
291
by_component_repids_.remove(home_info.component_repid);
292
293     // Remove in the home name table.
294
by_home_names_.remove(home_info.name);
295     }
296 }
297
Popular Tags