KickJava   Java API By Example, From Geeks To Geeks.

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


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.ApplicationErrorInfoTypeImpl;
27
28 import intt.itu.itut_x780.UIDType;
29 import intt.itu.itut_x780.ApplicationError;
30 import intt.itu.itut_x780.DeleteError;
31 import intt.itu.itut_x780.ManagedObject_F;
32
33 import org.omg.CosNaming.NameComponent JavaDoc;
34
35 /**
36  ** Implementation skeleton class for the ::itut_q816Components::TerminatorServiceProvider component.
37  ** Business operations MUST be completed !!!
38  **/

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

53     private CCM_TerminatorServiceProvider_Context the_context_;
54     intt.itu.itut_q816.ContainmentComponent c_admin = null;
55     intt.itu.itut_q816.Containment c_query = null;
56
57     // ==================================================================
58
//
59
// Constructor.
60
//
61
// ===================================================================
62
/**
63      ** The default constructor.
64      **/

65     public
66     TerminatorServiceProviderMonolithicImpl()
67     {
68         the_context_ = null;
69     }
70     // ==================================================================
71
//
72
// Internal methods.
73
//
74
// ===================================================================
75
// ==================================================================
76
//
77
// Public methods.
78
//
79
// ===================================================================
80
/**
81      ** To obtain the context.
82      **
83      ** @return The context that has been previously set by
84      ** the set_session_context operation.
85      **/

86     public CCM_TerminatorServiceProvider_Context
87     getContext()
88     {
89         return the_context_;
90     }
91     // ==================================================================
92
//
93
// Methods for the OMG IDL Components::EnterpriseComponent local interface.
94
//
95
// ==================================================================
96
//
97
// IDL:omg.org/Components/EnterpriseComponent/configuration_complete:1.0
98
//
99
/**
100      ** Completes the component configuration.
101      **
102      ** @throws org.omg.Components.InvalidConfiguration
103      ** Thrown if the configuration is invalid.
104      **/

105     public void
106     configuration_complete()
107     throws org.omg.Components.InvalidConfiguration
108     {
109         //
110
// DONE : implement !!!
111
//
112
if ((c_admin = the_context_.get_connection_containment_admin()) == null)
113             throw new org.omg.Components.InvalidConfiguration();
114
115         if ((c_query = the_context_.get_connection_containment_query()) == null)
116             throw new org.omg.Components.InvalidConfiguration();
117         System.err.println("TerminatorServiceProvider configuration completed...");
118     }
119     // ==================================================================
120
//
121
// Methods for the OMG IDL Components::SessionComponent local interface.
122
//
123
// ==================================================================
124
//
125
// IDL:omg.org/Components/SessionComponent/set_session_context:1.0
126
//
127
/**
128      * Called by the container when the component session context will be fixed.
129      *
130      * @param context The session context.
131      *
132      * @throws org.omg.Components.CCMException
133      * Thrown if a system level error occured.
134      */

135     public void
136     set_session_context(org.omg.Components.SessionContext context)
137     throws org.omg.Components.CCMException
138     {
139         the_context_ = (CCM_TerminatorServiceProvider_Context)context;
140     }
141     //
142
// IDL:omg.org/Components/SessionComponent/ccm_activate:1.0
143
//
144
/**
145      *
146      * Called by the container when the component will be activated.
147      *
148      * @throws org.omg.Components.CCMException
149      * Thrown if a system level error occured.
150      */

151     public void
152     ccm_activate()
153     throws org.omg.Components.CCMException
154     {
155         //
156
// Unused by actual OpenCCM containers
157
//
158
}
159     //
160
// IDL:omg.org/Components/SessionComponent/ccm_passivate:1.0
161
//
162
/**
163      *
164      * Called by the container when the component will be passivated.
165      *
166      * @throws org.omg.Components.CCMException
167      * Thrown if a system level error occured.
168      */

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

187     public void
188     ccm_remove()
189     throws org.omg.Components.CCMException
190     {
191         //
192
// TO DO: implement !!!
193
//
194
}
195     // ==================================================================
196
//
197
// Public methods for the CCM_TerminatorServiceProvider local interface.
198
//
199
// ==================================================================
200
//
201
// IDL:coach.ist/itut_q816Components/CCM_TerminatorServiceProvider/get_terminator:1.0
202
//
203
/**
204      ** Implementation of the ::itut_q816Components::CCM_TerminatorServiceProvider::get_terminator operation.
205      **/

206     public intt.itu.itut_q816.CCM_TerminatorService
207     get_terminator()
208     {
209         return this;
210     }
211     // ==================================================================
212
//
213
// Public methods for the ::itut_q816::CCM_TerminatorService local interface.
214
//
215
// ==================================================================
216
//
217
// IDL:itu.intt/itut_q816/TerminatorService/deleteByName:1.0
218
//
219
/**
220      ** Implementation of the ::itut_q816::TerminatorService::deleteByName operation.
221      **/

222     public void
223     deleteByName(org.omg.CosNaming.NameComponent JavaDoc[] name)
224     throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.DeleteError
225     {
226         //
227
// DONE : implement
228
//
229

230         String JavaDoc name_str = Utils.name2string(name);
231         String JavaDoc facade_name = Utils.name2facade(name_str);
232
233         if (facade_name.length() == 0) {
234             ApplicationErrorInfoTypeImpl error_code =
235                     new ApplicationErrorInfoTypeImpl();
236             error_code.error = new UIDType(
237                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
238                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
239             error_code.details = ExceptionMessages.root_delete_error;
240
241             System.err.println("Terminator: Root Object can not be deleted!");
242             throw new ApplicationError(error_code);
243         }
244         System.err.println("deleteByName called for " + name_str + " of " +
245                 facade_name);
246
247
248 /* HACK: Must have <componentsupportedinterface> in deployment script */
249 /********/
250         ist.coach.itut_q816Components.
251         TerminatorServiceProviderPackage.target_facadesConnection [] facades =
252             the_context_.get_connections_target_facades();
253
254         int i = 0;
255         org.omg.CosNaming.NameComponent JavaDoc[] facade_name_comp;
256         for(i = 0; i < facades.length; i++) {
257             facade_name_comp = facades[i].objref.nameGet();
258             System.err.println("TerminatorService>Examining facade " +
259               Utils.name2string(facade_name_comp));
260
261             int len = facade_name_comp.length;
262             if (len > 0 &&
263                 facade_name_comp[len - 1].kind.equals(facade_name))
264
265                     break;
266         }
267
268         if (i >= facades.length) {
269
270             ApplicationErrorInfoTypeImpl error_code =
271                     new ApplicationErrorInfoTypeImpl();
272             error_code.error = new UIDType(
273                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
274                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
275             error_code.details = ExceptionMessages.facade_not_exists_error;
276
277             System.err.println("Terminator: Could not locate the facade!");
278             throw new ApplicationError(error_code);
279         }
280
281         ManagedObject_F facade = facades[i].objref;
282
283         short objectDeletePolicy = facade.deletePolicyGet(name);
284
285         org.omg.CosNaming.NameComponent JavaDoc[][] contained_objects = null;
286         switch (objectDeletePolicy) {
287
288         case intt.itu.itut_x780.notDeletable.value:
289
290             System.err.println("notDeletable policy holds");
291
292             DeleteErrorInfoTypeImpl error_code =
293                 new DeleteErrorInfoTypeImpl();
294             error_code.error = new UIDType(
295                 intt.itu.itut_x780.DeleteErrorConst.moduleName.value,
296                 intt.itu.itut_x780.DeleteErrorConst.notDeletable.value);
297             error_code.details = name_str + ExceptionMessages.manager_delete_error;
298             throw new DeleteError(error_code);
299
300         case intt.itu.itut_x780.deleteOnlyIfNoContainedObjects.value:
301
302             System.err.println("deleteOnlyIfNoContainedObjects policy holds");
303
304             contained_objects = c_query.getContained(name);
305
306             if (contained_objects.length > 0) {
307
308                 DeleteErrorInfoTypeImpl error_contained =
309                     new DeleteErrorInfoTypeImpl();
310                 error_contained.error = new UIDType(
311                     intt.itu.itut_x780.DeleteErrorConst.moduleName.value,
312                     intt.itu.itut_x780.DeleteErrorConst.containsObjects.value);
313                 error_contained.details = ExceptionMessages.contains_object_error +
314                                 ".\n " + name_str + " contains " +
315                     contained_objects.length + " children";
316                 throw new DeleteError(error_contained);
317             }
318
319             delete(name, facade);
320             //delete(name, facades[i].objref);
321
return;
322
323         case intt.itu.itut_x780.deleteContainedObjects.value:
324
325             System.err.println("deleteContainedObjects policy holds");
326
327             contained_objects = c_query.getContained(name);
328
329             if (contained_objects.length == 0) {
330                 delete(name, facade);
331                 //delete(name, facades[i].objref);
332
return;
333             }
334
335             for(int j = 0; j < contained_objects.length; j++) {
336                 deleteByName(contained_objects[j]);
337             }
338             delete(name, facade);
339             //delete(name, facades[i].objref);
340
return;
341
342         default: // Signifies error in provided deletePolicy
343
return;
344         }
345     }
346
347     public void delete(org.omg.CosNaming.NameComponent JavaDoc[] name,
348                         intt.itu.itut_x780.ManagedObject_F facade)
349     throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.DeleteError
350     {
351
352             // remove object from the facade
353
facade.destroy(name);
354             // remove object from the containment service
355
c_admin.removeName(name);
356             // remove object from the SNMP service
357
System.err.println("delete: Successfully removed object " +
358             Utils.name2string(name) + " from its facade and containment service!");
359     }
360
361 }
362
Popular Tags