KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > itut_q816Components > ContainmentServiceProviderMonolithicImpl


1 /*====================================================================
2 Tnis file was produced by the OpenCCM ir3_jimpl generator.
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or any later version.
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 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 USA
18 Initial developer(s): Philippe Merle, Mathieu Vadet.
19 Contributor(s): Sylvain Leblanc_______________________.
20 ====================================================================*/

21 package ist.coach.itut_q816Components;
22
23 import ist.coach.coachEmfCommon.Utils;
24 import ist.coach.coachEmfCommon.ExceptionMessages;
25 import ist.coach.coachEmfCommon.DeleteErrorInfoTypeImpl;
26 import ist.coach.coachEmfCommon.CreateErrorInfoTypeImpl;
27 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl;
28
29 import intt.itu.itut_x780.UIDType;
30 import intt.itu.itut_x780.ApplicationError;
31 import intt.itu.itut_x780.CreateError;
32 import intt.itu.itut_x780.DeleteError;
33
34 /**
35  ** Implementation skeleton class for the ::itut_q816Components::ContainmentServiceProvider component.
36  ** Business operations MUST be completed !!!
37  **/

38 public class ContainmentServiceProviderMonolithicImpl
39        extends org.omg.CORBA.LocalObject JavaDoc
40        implements CCM_ContainmentServiceProvider,
41                   intt.itu.itut_q816.CCM_Containment,
42                   intt.itu.itut_q816.CCM_ContainmentComponent,
43                   org.omg.Components.SessionComponent
44 {
45     // ==================================================================
46
//
47
// Internal State.
48
//
49
// ===================================================================
50
/**
51      ** Context reference.
52      **/

53     private CCM_ContainmentServiceProvider_Context the_context_;
54
55         /**** Business logic *****/
56
57         // hashtable that records for each object the existing children
58
// Key: the stringnified object Name
59
// Value: Vector with stringnified children Names
60
private java.util.Hashtable JavaDoc tree;
61
62         // hashtable that looks-up parents of objects
63
// needed during remove so that to index the tree table.
64
private java.util.Hashtable JavaDoc reverse_tree;
65
66     String JavaDoc _local_root = null;
67     // ==================================================================
68
//
69
// Constructor.
70
//
71
// ===================================================================
72
/**
73      ** The default constructor.
74      **/

75     public
76     ContainmentServiceProviderMonolithicImpl()
77     {
78         the_context_ = null;
79         tree = new java.util.Hashtable JavaDoc();
80         reverse_tree = new java.util.Hashtable JavaDoc();
81     }
82     // ==================================================================
83
//
84
// Internal methods.
85
//
86
// ===================================================================
87
// ==================================================================
88
//
89
// Public methods.
90
//
91
// ===================================================================
92
/**
93      ** To obtain the context.
94      **
95      ** @return The context that has been previously set by
96      ** the set_session_context operation.
97      **/

98     public CCM_ContainmentServiceProvider_Context
99     getContext()
100     {
101         return the_context_;
102     }
103     // ==================================================================
104
//
105
// Methods for the OMG IDL Components::EnterpriseComponent local interface.
106
//
107
// ==================================================================
108
//
109
// IDL:omg.org/Components/EnterpriseComponent/configuration_complete:1.0
110
//
111
/**
112      ** Completes the component configuration.
113      **
114      ** @throws org.omg.Components.InvalidConfiguration
115      ** Thrown if the configuration is invalid.
116      **/

117     public void
118     configuration_complete()
119     throws org.omg.Components.InvalidConfiguration
120     {
121         //
122
// DONE : implement !!!
123
//
124

125
126         System.err.println("Local Root = " + _local_root);
127         if (_local_root != null && _local_root.length() > 0)
128             tree.put(_local_root, new java.util.Vector JavaDoc());
129
130             // FSET: HACK : Registration in Naming Service must be done
131
// during deployment!
132

133
134         System.err.println("ContainmentServiceProvider configuration completed...");
135     }
136     // ==================================================================
137
//
138
// Methods for the OMG IDL Components::SessionComponent local interface.
139
//
140
// ==================================================================
141
//
142
// IDL:omg.org/Components/SessionComponent/set_session_context:1.0
143
//
144
/**
145      * Called by the container when the component session context will be fixed.
146      *
147      * @param context The session context.
148      *
149      * @throws org.omg.Components.CCMException
150      * Thrown if a system level error occured.
151      */

152     public void
153     set_session_context(org.omg.Components.SessionContext context)
154     throws org.omg.Components.CCMException
155     {
156         the_context_ = (CCM_ContainmentServiceProvider_Context)context;
157     }
158     //
159
// IDL:omg.org/Components/SessionComponent/ccm_activate:1.0
160
//
161
/**
162      *
163      * Called by the container when the component will be activated.
164      *
165      * @throws org.omg.Components.CCMException
166      * Thrown if a system level error occured.
167      */

168     public void
169     ccm_activate()
170     throws org.omg.Components.CCMException
171     {
172         //
173
// Unused by actual OpenCCM containers
174
//
175
}
176     //
177
// IDL:omg.org/Components/SessionComponent/ccm_passivate:1.0
178
//
179
/**
180      *
181      * Called by the container when the component will be passivated.
182      *
183      * @throws org.omg.Components.CCMException
184      * Thrown if a system level error occured.
185      */

186     public void
187     ccm_passivate()
188     throws org.omg.Components.CCMException
189     {
190         //
191
// Unused by actual OpenCCM containers
192
//
193
}
194     //
195
// IDL:omg.org/Components/SessionComponent/ccm_remove:1.0
196
//
197
/**
198      *
199      * Called by the container when the component will be removed.
200      *
201      * @throws org.omg.Components.CCMException
202      * Thrown if a system level error occured.
203      */

204     public void
205     ccm_remove()
206     throws org.omg.Components.CCMException
207     {
208         //
209
// TO DO: implement !!!
210
//
211
}
212     // ==================================================================
213
//
214
// Public methods for the CCM_ContainmentServiceProvider local interface.
215
//
216
// ==================================================================
217
//
218
// IDL:coach.ist/itut_q816Components/CCM_ContainmentServiceProvider/get_containment_query:1.0
219
//
220
/**
221      ** Implementation of the ::itut_q816Components::CCM_ContainmentServiceProvider::get_containment_query operation.
222      **/

223     public intt.itu.itut_q816.CCM_Containment
224     get_containment_query()
225     {
226         return this;
227     }
228     //
229
// IDL:coach.ist/itut_q816Components/CCM_ContainmentServiceProvider/get_containment_admin:1.0
230
//
231
/**
232      ** Implementation of the ::itut_q816Components::CCM_ContainmentServiceProvider::get_containment_admin operation.
233      **/

234     public intt.itu.itut_q816.CCM_ContainmentComponent
235     get_containment_admin()
236     {
237         return this;
238     }
239
240     /**
241      ** Implementation of the ::itut_x780Components::CCM_NamedComponent_Executor::
242      ** local_root attribute as accessor operation. **/

243     public java.lang.String JavaDoc
244     local_root() {
245          //
246
// DONE : implement
247
//
248
return _local_root;
249     }
250
251     /**
252      ** Implementation of the ::itut_x780Components::CCM_NamedComponent_Executor::
253      ** local_root attribute as mutator operation. **/

254     public void
255     local_root(java.lang.String JavaDoc val)
256     {
257         //
258
// DONE : implement
259
//
260
_local_root = val;
261         if (! tree.contains(_local_root))
262             tree.put(_local_root, new java.util.Vector JavaDoc());
263      }
264
265     // ==================================================================
266
//
267
// Public methods for the ::itut_q816::CCM_Containment local interface.
268
//
269
// ==================================================================
270
//
271
// IDL:itu.intt/itut_q816/Containment/exists:1.0
272
//
273
/**
274      ** Implementation of the ::itut_q816::Containment::exists operation.
275      **/

276     public boolean
277     exists(org.omg.CosNaming.NameComponent JavaDoc[] name)
278     throws intt.itu.itut_x780.ApplicationError
279     {
280         //
281
// DONE : implement
282
//
283

284         if (tree.containsKey(Utils.name2string(name)))
285             return true;
286         else
287             return false;
288
289     }
290     //
291
// IDL:itu.intt/itut_q816/Containment/getContained:1.0
292
//
293
/**
294      ** Implementation of the ::itut_q816::Containment::getContained operation.
295      **/

296     public org.omg.CosNaming.NameComponent JavaDoc[][]
297     getContained(org.omg.CosNaming.NameComponent JavaDoc[] name)
298     throws intt.itu.itut_x780.ApplicationError
299     {
300         //
301
// DONE : implement
302
//
303
//System.err.println("getContained was called for *" + Utils.name2string(name) + "*");
304
//System.err.println("Size of tree is " + tree.size());
305

306         org.omg.CosNaming.NameComponent JavaDoc[][] contained_objects =
307                 new org.omg.CosNaming.NameComponent JavaDoc[0][0];
308
309         String JavaDoc name_str = Utils.name2string(name);
310         if (tree.containsKey(name_str)) {
311             java.util.Vector JavaDoc contained_vector = (java.util.Vector JavaDoc) tree.get(name_str);
312
313             contained_objects =
314                 new org.omg.CosNaming.NameComponent JavaDoc[contained_vector.size()][0];
315
316             for(int i = 0; i < contained_vector.size(); i++) {
317
318                 String JavaDoc child_name = (String JavaDoc) contained_vector.elementAt(i);
319
320                 if (child_name == null || child_name.length() == 0)
321                      System.err.println("Note that a NULL child found!");
322                 else {
323                     contained_objects[i] = Utils.string2name(child_name);
324                 }
325             }
326         }
327         //System.err.println("getContained returns " +
328
// contained_objects.length + " children");
329
return contained_objects;
330
331     }
332     //
333
// IDL:itu.intt/itut_q816/Containment/getContainedByKind:1.0
334
//
335
/**
336      ** Implementation of the ::itut_q816::Containment::getContainedByKind operation.
337      **/

338     public org.omg.CosNaming.NameComponent JavaDoc[][]
339     getContainedByKind(org.omg.CosNaming.NameComponent JavaDoc[] name, java.lang.String JavaDoc kind)
340     throws intt.itu.itut_x780.ApplicationError
341     {
342         //
343
// DONE : implement
344
//
345
org.omg.CosNaming.NameComponent JavaDoc[][] contained_objects =
346                 new org.omg.CosNaming.NameComponent JavaDoc[0][0];
347         String JavaDoc name_str = Utils.name2string(name);
348
349         if (! tree.containsKey(name_str)) {
350             ApplicationErrorInfoTypeImpl error_code =
351                     new ApplicationErrorInfoTypeImpl();
352             error_code.error = new UIDType(
353                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
354                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
355             error_code.details = ExceptionMessages.root_delete_error;
356
357             throw new ApplicationError(error_code);
358         }
359         java.util.Vector JavaDoc contained_vector = (java.util.Vector JavaDoc) tree.get(name_str);
360
361         java.util.Vector JavaDoc contained_by_kind_vector = new java.util.Vector JavaDoc();
362         String JavaDoc child_str;
363         for (int i = 0; i < contained_vector.size(); i++) {
364             child_str = (String JavaDoc) contained_vector.elementAt(i);
365
366             if (kind.equals(Utils.name2kind(child_str))) {
367                 contained_by_kind_vector.add(child_str);
368             }
369
370         }
371         contained_objects = new org.omg.CosNaming.NameComponent JavaDoc[
372                     contained_by_kind_vector.size()][0];
373
374         for(int j = 0; j < contained_by_kind_vector.size(); j++) {
375
376             child_str = (String JavaDoc) contained_by_kind_vector.elementAt(j);
377
378             if (child_str == null || child_str.length() == 0)
379                 System.err.println("NULL child found!");
380             else
381                 contained_objects[j] = Utils.string2name(child_str);
382         }
383
384         return contained_objects;
385     }
386     // ==================================================================
387
//
388
// Public methods for the ::itut_q816::CCM_ContainmentComponent local interface.
389
//
390
// ==================================================================
391
//
392
// IDL:itu.intt/itut_q816/ContainmentComponent/registerLocalRoot:1.0
393
//
394
/**
395      ** Implementation of the ::itut_q816::ContainmentComponent::registerLocalRoot
396      ** operation.
397      **/

398     public void
399     registerLocalRoot(org.omg.CosNaming.NameComponent JavaDoc[] name,
400         org.omg.CosNaming.NamingContext JavaDoc localRoot)
401     throws intt.itu.itut_x780.ApplicationError
402     {
403         //
404
// DONE : implement
405
//
406
_local_root = Utils.name2string(name);
407         if (! tree.contains(_local_root))
408             tree.put(_local_root, new java.util.Vector JavaDoc());
409     }
410     //
411
// IDL:itu.intt/itut_q816/ContainmentComponent/unregisterLocalRoot:1.0
412
//
413
/**
414      ** Implementation of the ::itut_q816::ContainmentComponent::unregisterLocalRoot operation.
415      **/

416     public void
417     unregisterLocalRoot(org.omg.CosNaming.NameComponent JavaDoc[] name)
418     throws intt.itu.itut_x780.ApplicationError
419     {
420         //
421
// TODO : implement
422
//
423
}
424     //
425
// IDL:itu.intt/itut_q816/ContainmentComponent/addName:1.0
426
//
427
/**
428      ** Implementation of the ::itut_q816::ContainmentComponent::addName operation.
429      **/

430     public void
431     addName(org.omg.CosNaming.NameComponent JavaDoc[] name,
432         org.omg.CosNaming.NameComponent JavaDoc[] superior)
433     throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.CreateError
434     {
435         //
436
// DONE : implement
437
//
438
java.util.Vector JavaDoc children = new java.util.Vector JavaDoc();
439         String JavaDoc name_str = Utils.name2string(name);
440         String JavaDoc superior_str = Utils.name2string(superior);
441
442         if (tree.containsKey(superior_str)) {
443             children = (java.util.Vector JavaDoc) tree.get(superior_str);
444         }
445         else {
446             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
447             error_code.error = new UIDType(
448                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
449                 intt.itu.itut_x780.CreateErrorConst.badName.value);
450             error_code.details = ExceptionMessages.parent_object_error;
451             throw new ApplicationError(error_code);
452         }
453
454         if (tree.containsKey(name_str)) {
455             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
456             error_code.error = new UIDType(
457                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
458                 intt.itu.itut_x780.CreateErrorConst.duplicateName.value);
459
460             error_code.details = name_str + ExceptionMessages.not_exists_error;
461             throw new CreateError(error_code);
462
463         }
464         else
465             tree.put(name_str, new java.util.Vector JavaDoc());
466
467
468         if (! children.contains(name_str)) {
469             children.add(name_str);
470             tree.put(superior_str, children);
471             reverse_tree.put(name_str, superior_str);
472         }
473     }
474     //
475
// IDL:itu.intt/itut_q816/ContainmentComponent/removeName:1.0
476
//
477
/**
478      ** Implementation of the ::itut_q816::ContainmentComponent::removeName operation.
479      **/

480     public void
481     removeName(org.omg.CosNaming.NameComponent JavaDoc[] name)
482     throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.DeleteError
483     {
484         //
485
// DONE : implement
486
//
487
if (name.length <= 1) {
488             ApplicationErrorInfoTypeImpl error_code =
489                     new ApplicationErrorInfoTypeImpl();
490             error_code.error = new UIDType(
491                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
492                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
493             error_code.details = ExceptionMessages.root_delete_error;
494
495             throw new ApplicationError(error_code);
496         }
497
498         String JavaDoc name_str = Utils.name2string(name);
499
500         if (!tree.containsKey(name_str)) {
501             ApplicationErrorInfoTypeImpl error_code =
502                 new ApplicationErrorInfoTypeImpl();
503             error_code.error = new UIDType(
504                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
505                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
506             error_code.details = name_str + ExceptionMessages.not_exists_error;
507
508             throw new ApplicationError(error_code);
509         }
510
511         java.util.Vector JavaDoc children = (java.util.Vector JavaDoc) tree.get(name_str);
512
513          // There must be no contained names registered with
514
// the Containment service when a name is removed.
515

516         if (children != null && children.size() > 0) {
517             DeleteErrorInfoTypeImpl error_code =
518                 new DeleteErrorInfoTypeImpl();
519             error_code.error = new UIDType(
520                 intt.itu.itut_x780.DeleteErrorConst.moduleName.value,
521                 intt.itu.itut_x780.DeleteErrorConst.containsObjects.value);
522             error_code.details = name_str + ExceptionMessages.contains_object_error;
523
524             throw new DeleteError(error_code);
525         }
526
527         tree.remove(name_str);
528         String JavaDoc superior = (String JavaDoc) reverse_tree.remove(name_str);
529
530         if (superior == null)
531             return;
532
533         java.util.Vector JavaDoc superior_children = (java.util.Vector JavaDoc) tree.get(superior);
534         if (superior_children.contains(name_str)) {
535             superior_children.remove(name_str);
536             tree. put(superior, superior_children);
537             //System.err.println("\tProceeding to remove from " + name_str
538
// + " from " + superior);
539
}
540
541     }
542
543 }
544
Popular Tags