KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > itut_q816Components > TerminatorServiceProviderComposition > terminatorSegImpl


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

28
29 package ist.coach.itut_q816Components.TerminatorServiceProviderComposition;
30
31 import ist.coach.coachEmfCommon.Utils;
32 import ist.coach.coachEmfCommon.ExceptionMessages;
33 import ist.coach.coachEmfCommon.DeleteErrorInfoTypeImpl;
34 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl;
35
36 import intt.itu.itut_x780.UIDType;
37 import intt.itu.itut_x780.ApplicationError;
38 import intt.itu.itut_x780.DeleteError;
39 import intt.itu.itut_x780.ManagedObject_F;
40
41 /**
42  * This is the CIDL-based implementation of the
43  * OMG IDL3 CIDL:coach.ist/itut_q816Components/TerminatorServiceProviderComposition/TerminatorServiceProviderHome_impl/TerminatorServiceProvider_impl/terminatorSeg:1.0 segment type.
44  *
45  * @author OpenCCM CIF_Jimpl Compiler.
46  */

47 public class terminatorSegImpl
48      extends ist.coach.itut_q816Components.TerminatorServiceProviderComposition.terminatorSeg
49 {
50     // ==================================================================
51
//
52
// Internal states.
53
//
54
// ==================================================================
55
// ==================================================================
56
//
57
// Constructors.
58
//
59
// ==================================================================
60

61     public terminatorSegImpl()
62     {
63
64     }
65
66     // ==================================================================
67
//
68
// Methods.
69
//
70
// ==================================================================
71

72     /**
73      * Implementation of the ::itut_q816::TerminatorService::deleteByName operation.
74      */

75     public void
76     deleteByName(org.omg.CosNaming.NameComponent JavaDoc[] name)
77     throws intt.itu.itut_x780.ApplicationError,
78     intt.itu.itut_x780.DeleteError
79     {
80         //
81
// DONE : implement
82
//
83

84         String JavaDoc name_str = Utils.name2string(name);
85         String JavaDoc facade_name = Utils.name2facade(name_str);
86
87         if (facade_name.length() == 0) {
88             ApplicationErrorInfoTypeImpl error_code =
89                     new ApplicationErrorInfoTypeImpl();
90             error_code.error = new UIDType(
91                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
92                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
93             error_code.details = ExceptionMessages.root_delete_error;
94
95             System.err.println("Terminator: Root Object can not be deleted!");
96             throw new ApplicationError(error_code);
97         }
98         System.err.println("Terminator>deleteByName called for " + name_str + " of " +
99                 facade_name);
100
101       intt.itu.itut_q816.Containment c_query = null;
102
103       if ((c_query = get_context().get_connection_containment_query()) == null) {
104           ApplicationErrorInfoTypeImpl error_code =
105                     new ApplicationErrorInfoTypeImpl();
106             error_code.error = new UIDType(
107                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
108                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
109             error_code.details = ExceptionMessages.components_connect_error;
110
111             System.err.println("Terminator:ContainmentQuery can not be located!!");
112             throw new ApplicationError(error_code);
113       }
114
115 /* HACK: Must have <componentsupportedinterface> in deployment script */
116 /********/
117         ist.coach.itut_q816Components.
118         TerminatorServiceProviderPackage.target_facadesConnection [] facades =
119             get_context().get_connections_target_facades();
120
121         int i = 0;
122         org.omg.CosNaming.NameComponent JavaDoc[] facade_name_comp;
123         for(i = 0; i < facades.length; i++) {
124             facade_name_comp = facades[i].objref.nameGet();
125             //System.err.println("TerminatorService>Examining facade " +
126
// Utils.name2string(facade_name_comp));
127

128             int len = facade_name_comp.length;
129             if (len > 0 &&
130                 facade_name_comp[len - 1].kind.equals(facade_name))
131
132                     break;
133         }
134
135         if (i >= facades.length) {
136
137             ApplicationErrorInfoTypeImpl error_code =
138                     new ApplicationErrorInfoTypeImpl();
139             error_code.error = new UIDType(
140                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
141                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
142             error_code.details = ExceptionMessages.facade_not_exists_error;
143
144             System.err.println("Terminator: Could not locate the facade!");
145             throw new ApplicationError(error_code);
146         }
147
148         ManagedObject_F facade = facades[i].objref;
149
150         short objectDeletePolicy = facade.deletePolicyGet(name);
151
152         org.omg.CosNaming.NameComponent JavaDoc[][] contained_objects = null;
153         switch (objectDeletePolicy) {
154
155         case intt.itu.itut_x780.notDeletable.value:
156
157             //System.err.println("notDeletable policy holds");
158

159             DeleteErrorInfoTypeImpl error_code =
160                 new DeleteErrorInfoTypeImpl();
161             error_code.error = new UIDType(
162                 intt.itu.itut_x780.DeleteErrorConst.moduleName.value,
163                 intt.itu.itut_x780.DeleteErrorConst.notDeletable.value);
164             error_code.details = name_str + ExceptionMessages.manager_delete_error;
165             throw new DeleteError(error_code);
166
167         case intt.itu.itut_x780.deleteOnlyIfNoContainedObjects.value:
168
169             //System.err.println("deleteOnlyIfNoContainedObjects policy holds");
170

171             contained_objects = c_query.getContained(name);
172
173             if (contained_objects.length > 0) {
174
175                 DeleteErrorInfoTypeImpl error_contained =
176                     new DeleteErrorInfoTypeImpl();
177                 error_contained.error = new UIDType(
178                     intt.itu.itut_x780.DeleteErrorConst.moduleName.value,
179                     intt.itu.itut_x780.DeleteErrorConst.containsObjects.value);
180                 error_contained.details = ExceptionMessages.contains_object_error +
181                                 ".\n " + name_str + " contains " +
182                     contained_objects.length + " children";
183                 throw new DeleteError(error_contained);
184             }
185
186             delete(name, facade);
187             //delete(name, facades[i].objref);
188
return;
189
190         case intt.itu.itut_x780.deleteContainedObjects.value:
191
192             //System.err.println("deleteContainedObjects policy holds");
193

194             contained_objects = c_query.getContained(name);
195
196             if (contained_objects.length == 0) {
197                 delete(name, facade);
198                 //delete(name, facades[i].objref);
199
return;
200             }
201
202             for(int j = 0; j < contained_objects.length; j++) {
203                 deleteByName(contained_objects[j]);
204             }
205             delete(name, facade);
206             //delete(name, facades[i].objref);
207
return;
208
209         default: // Signifies error in provided deletePolicy
210
return;
211         }
212     }
213
214     public void delete(org.omg.CosNaming.NameComponent JavaDoc[] name,
215                         intt.itu.itut_x780.ManagedObject_F facade)
216     throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.DeleteError
217     {
218
219             // remove object from the facade
220
facade.destroy(name);
221             // remove object from the containment service
222
intt.itu.itut_q816.ContainmentComponent c_admin = null;
223
224         if ((c_admin = get_context().get_connection_containment_admin()) == null) {
225             ApplicationErrorInfoTypeImpl error_code =
226                     new ApplicationErrorInfoTypeImpl();
227             error_code.error = new UIDType(
228                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
229                 intt.itu.itut_x780.ApplicationErrorConst.invalidParameter.value);
230             error_code.details = ExceptionMessages.components_connect_error;
231             System.err.println("Terminator:ContainmentAdmin can not be located!!");
232             throw new ApplicationError(error_code);
233         }
234
235         c_admin.removeName(name);
236         System.err.println("delete: Successfully removed object " +
237             Utils.name2string(name) + " from its facade and containment service!");
238     }
239
240 }
241
Popular Tags