KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > OpenCCM_DCI > cif > HomeManagementSegImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 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): Briclet Frederic
23 Contributor(s): ___________________________________________________.
24
25 ====================================================================*/

26
27
28
29 package org.objectweb.openccm.OpenCCM_DCI.cif;
30
31 import org.objectweb.openccm.OpenCCM_DCI.*;
32 import org.ist.coach.DCI.HomeInfo;
33 import org.objectweb.openccm.corba.*;
34 /**
35  * This is the implementation of the HomeFinder and HomeRegistration
36  * interfaces..
37  *
38  * This class inherits from the skeleton
39  * generated by the OpenCCM's CIF to Java mapping generator.
40  *
41  * @author <a HREF="mailto:Frederic.Briclet@lifl.fr">Briclet Frederic</A>
42  */

43 public class HomeManagementSegImpl
44        extends org.objectweb.openccm.OpenCCM_DCI.
45                 DCIManagerSessionComposition.HomeManagementSeg
46 {
47
48     /*private class HomeInfo{
49      
50      public String home_repid;
51      public String component_repid;
52      public String name;
53      public org.omg.Components.CCMHome home;
54      
55      public HomeInfo(org.omg.Components.CCMHome home,
56                      String home_repid,
57                      String component_repid,
58                      String name){
59        this.home=home;
60        this.home_repid=home_repid;
61        this.component_repid=component_repid;
62        this.name=name;
63        }
64     }*/

65     
66     /**
67      ** To store (cookie, HomeInfo) associations.
68      **/

69     private org.objectweb.ccm.util.Table by_cookies_;
70
71     /**
72      ** To store (home_repid, CCMHome) associations.
73      **/

74     private org.objectweb.ccm.util.Table by_home_repids_;
75
76     /**
77      ** To store (component_repid, CCMHome) associations.
78      **/

79     private org.objectweb.ccm.util.Table by_component_repids_;
80
81     /**
82      ** To store (home_name, CCMHome) associations.
83      **/

84     private org.objectweb.ccm.util.Table by_home_names_;
85     
86     /**
87      ** The reference on the DCIManager component interface
88      * */

89     private org.objectweb.openccm.OpenCCM_DCI.DCIManagerCCM DCI;
90
91
92     // ==================================================================
93
//
94
// Constructor.
95
//
96
// ==================================================================
97

98     /**
99      ** The default constructor.
100      **/

101     public
102     HomeManagementSegImpl()
103     {
104         by_cookies_ = new org.objectweb.ccm.util.Table();
105         by_home_repids_ = new org.objectweb.ccm.util.Table();
106         by_component_repids_ = new org.objectweb.ccm.util.Table();
107         by_home_names_ = new org.objectweb.ccm.util.Table();
108     }
109
110     // ==================================================================
111
//
112
// Internal methods.
113
//
114
// ==================================================================
115

116     // ==================================================================
117
//
118
// Public methods.
119
//
120
// ==================================================================
121
public void setupDCI(){
122         DCI=(org.objectweb.openccm.OpenCCM_DCI.DCIManagerCCM)get_context();
123     }
124    
125
126     // ==================================================================
127
//
128
// Methods for the Components::HomeFinder interface.
129
//
130
// ==================================================================
131

132     //
133
// IDL:omg.org/Components/HomeFinder/find_home_by_component_type:1.0
134
//
135
/**
136      ** Finds an home by its managed component type.
137      **
138      ** @param comp_repid The requested component repository ID.
139      **
140      ** @return The associated home.
141      **
142      ** @exception org.omg.Components.HomeNotFound
143      ** Thrown if there is no home for the requested
144      ** component type.
145      **/

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

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

206     public org.omg.Components.CCMHome
207     find_home_by_name(String JavaDoc home_name)
208     throws org.omg.Components.HomeNotFound
209     {
210     // Search by home name.
211
Object JavaDoc result = by_home_names_.get(home_name);
212
213     // Check that a CCMHome has been found.
214
if(result == null)
215     {
216         throw new org.omg.Components.HomeNotFound();
217     }
218
219     // Return the found CCMHome.
220
return (org.omg.Components.CCMHome)result;
221     }
222
223
224     public HomeInfo []
225     get_all_homes()
226     {
227         java.util.Collection JavaDoc cc=
228             by_cookies_.values();
229         
230         return
231             (HomeInfo [])
232                 cc.toArray(new HomeInfo[cc.size()]);
233                         
234     }
235     // ==================================================================
236
//
237
// Methods for the OpenCCM::Components::HomeManager interface.
238
//
239
// ==================================================================
240

241     //
242
// IDL:goal.lifl.fr/OpenCCM/Components/HomeManager/register_home:1.0
243
//
244
/**
245      ** Register a CCMHome.
246      **
247      ** @param home The CCMHome reference.
248      ** @param home_repid The CCMHome Repository Id.
249      ** @param component_repid The managed component Repository Id.
250      ** @param name The INS name associated to the home.
251      **
252      ** @return The cookie associated to this registration.
253      **/

254     public org.omg.Components.Cookie
255     register_home(org.omg.Components.CCMHome home,
256                   String JavaDoc home_repid,
257                   String JavaDoc component_repid,
258                   String JavaDoc name)
259     {
260     
261
262     try{
263         // Connect the Home to the DCI
264
org.omg.Components.Cookie cookie = DCI.connect_homes(home);
265         // Register the home information by the generated cookie.
266
by_cookies_.put(cookie,
267             new org.ist.coach.DCI.HomeInfo(
268                     home_repid,
269                     component_repid,
270                     home,
271                     name,
272                     "Unknown"));
273         // Register the home by its repository Id.
274
by_home_repids_.put(home_repid, home);
275
276         // Register the home by its managed component repository Id.
277
by_component_repids_.put(component_repid, home);
278
279         // Register the home by its name.
280
by_home_names_.put(name, home);
281     
282         // Return the generated cookie.
283
return cookie;
284         }
285     catch(Exception JavaDoc e){
286             System.err.println("Cannot connect home to the DCI");
287             return null;
288         }
289     }
290
291     //
292
// IDL:goal.lifl.fr/OpenCCM/Components/HomeManager/unregister_home:1.0
293
//
294
/**
295      ** Unregister a CCMHome.
296      **
297      ** @param The registration cookie.
298      **
299      ** @exception ::Components::CookieRequired
300      ** Thrown when an invalid cookie is used.
301      **/

302     public void
303     unregister_home(org.omg.Components.Cookie ck)
304     throws org.omg.Components.CookieRequired
305     {
306     if(ck==null)
307         throw new org.omg.Components.CookieRequired();
308     // Search the home info by its associated cookie.
309
HomeInfo home_info = (HomeInfo)by_cookies_.remove(ck);
310
311     // Check that a home info is associated to the cookie.
312
if(home_info == null)
313     {
314         throw new org.omg.Components.CookieRequired();
315     }
316
317     // Remove in the home repository id table.
318
by_home_repids_.remove(home_info.home_repid);
319
320     // Remove in the component repository id table.
321
by_component_repids_.remove(home_info.component_repid);
322
323     // Remove in the home name table.
324
by_home_names_.remove(home_info.uid);
325     try{
326         //disconnect the home from the DCI
327
DCI.disconnect_homes(ck);
328         }
329     catch(Exception JavaDoc e){
330             System.err.println("Cannot disconnect home from the DCI");
331         }
332     }
333
334
335 }
336
Popular Tags