KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > itut_x780Components > ManagedObjectFactoryProviderComposition > ManagedObjectFactoryProviderImpl


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_x780Components.ManagedObjectFactoryProviderComposition;
30
31 import ist.coach.coachEmfCommon.Utils;
32 import ist.coach.coachEmfCommon.ExceptionMessages;
33 import intt.itu.itut_x780.UIDType;
34 import intt.itu.itut_x780.CreateError;
35 import intt.itu.itut_x780.ApplicationError;
36
37 import intt.itu.itut_x780.ManagedObjectFactory;
38 import intt.itu.itut_x780.ManagedObjectFactoryHelper;
39 import ist.coach.coachEmfCommon.CreateErrorInfoTypeImpl;
40 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl;
41
42 import ist.coach.itut_x780Components.CCM_ManagedObjectFactoryProvider_Context;
43 import ist.coach.itut_x780Components.ManagedObjectMgmt;
44 import ist.coach.coachEmfServices.EmfBasicLog.*;
45
46
47 /**
48  * This is the CIDL-based implementation of the
49  * OMG IDL3 IDL:coach.ist/itut_x780Components/ManagedObjectFactoryProvider:1.0 component type.
50  *
51  * @author OpenCCM CIF_Jimpl Compiler.
52  */

53 public class ManagedObjectFactoryProviderImpl
54      extends ist.coach.itut_x780Components.ManagedObjectFactoryProviderComposition.ManagedObjectFactoryProvider_impl
55 {
56     // ==================================================================
57
//
58
// Internal states.
59
//
60
// ==================================================================
61

62     /* Business logic **/
63     intt.itu.itut_q816.ContainmentComponent c_admin = null;
64     intt.itu.itut_q816.Containment c_query = null;
65
66     private static final String JavaDoc FACTORY_CLASS = "ManagedObjectFactory";
67     ManagedObjectMgmt facade = null;
68     private BasicLog logSupport;
69     // ==================================================================
70
//
71
// Constructors.
72
//
73
// ==================================================================
74

75     public ManagedObjectFactoryProviderImpl()
76     {
77
78     }
79
80     // ==================================================================
81
//
82
// Methods for the OMG IDL Components::EnterpriseComponent local interface.
83
//
84
// ==================================================================
85
//
86
// IDL:omg.org/Components/EnterpriseComponent/configuration_complete:1.0
87
//
88
/**
89      ** Completes the component configuration.
90      **
91      ** @throws org.omg.Components.InvalidConfiguration
92      ** Thrown if the configuration is invalid.
93      **/

94     public void
95     configuration_complete()
96     throws org.omg.Components.InvalidConfiguration
97     {
98         //
99
// DONE : implement !!!
100
//
101
if ((facade = get_context().get_connection_facade()) == null)
102             throw new org.omg.Components.InvalidConfiguration();
103
104         if ((c_admin = get_context().get_connection_containment_admin()) == null)
105             throw new org.omg.Components.InvalidConfiguration();
106
107         if ((c_query = get_context().get_connection_containment_query()) == null)
108             throw new org.omg.Components.InvalidConfiguration();
109
110         if ((logSupport = get_context().get_connection_basic_log()) == null)
111             throw new org.omg.Components.InvalidConfiguration();
112
113             // If managers may create, then the factory must register to the
114
// factory finder service
115
intt.itu.itut_q816.FactoryFinderComponent factoryfinder_admin =
116             get_context().get_connection_factoryfinder_admin();
117
118         org.omg.CORBA.Object JavaDoc myself_o;
119         ManagedObjectFactory myself = null;
120
121         try {
122             myself_o = ((org.omg.Components.SessionContext) get_context()).get_CCM_object();
123             myself = ManagedObjectFactoryHelper.narrow(myself_o);
124
125             factoryfinder_admin.register(FACTORY_CLASS, myself);
126             //factoryfinder_admin.register(FACTORY_CLASS, this);
127
}
128         catch(intt.itu.itut_x780.ApplicationError ex) {
129
130             throw new org.omg.Components.InvalidConfiguration();
131         }
132         catch(Exception JavaDoc e) {
133            // System.err.println("ManagedObjectFactory has problems retrieving CCM component");
134
}
135
136
137         System.err.println("ManagedObjectFactoryProvider configuration completed...");
138     }
139
140     //
141
// IDL:omg.org/Components/SessionComponent/ccm_remove:1.0
142
//
143
/**
144      *
145      * Called by the container when the component will be removed.
146      *
147      * @throws org.omg.Components.CCMException
148      * Thrown if a system level error occured.
149      */

150     public void
151     ccm_remove()
152     throws org.omg.Components.CCMException
153     {
154         //
155
// TO DO: implement !!!
156
//
157
}
158     // ==================================================================
159
//
160
// Methods.
161
//
162
// ==================================================================
163

164     /**
165      * Implementation of the ::itut_x780::ManagedObjectFactory::create_base operation.
166      */

167     public org.omg.CosNaming.NameComponent JavaDoc[]
168     create_base(String JavaDoc nameBinding, org.omg.CosNaming.NameComponent JavaDoc[] superior, String JavaDoc reqId)
169     throws intt.itu.itut_x780.CreateError,
170
171            intt.itu.itut_x780.ApplicationError
172     {
173                 short deletePolicy = -1;
174         boolean managerMayCreatePolicy = false;
175         String JavaDoc objectKind = new String JavaDoc();
176         String JavaDoc nameBinding_str = "intt.itu.itut_x780.NameBindings." +
177                 nameBinding;
178         try {
179             Class JavaDoc deletePolicyClass =
180                 Class.forName(nameBinding_str + ".deletePolicy");
181
182             deletePolicy =
183                 deletePolicyClass.getDeclaredField("value").getShort(null);
184
185             Class JavaDoc managerMayCreatePolicyClass =
186                     Class.forName(nameBinding_str + ".managersMayCreate");
187             managerMayCreatePolicy =
188                 managerMayCreatePolicyClass.getDeclaredField("value").getBoolean(null);
189
190             Class JavaDoc objectKindClass =
191                      Class.forName(nameBinding_str + ".kind");
192             objectKind = (String JavaDoc) objectKindClass.getDeclaredField("value").get(null);
193
194     /*
195             System.err.println("deletePolicy = " + deletePolicy +
196                                 "managerMayCreatePolicy = " + managerMayCreatePolicy +
197                                 "objectKind = " + objectKind);
198     */

199
200         }
201         catch(java.lang.ClassNotFoundException JavaDoc ex) {
202             System.err.println(nameBinding_str + " can not be found!" + ex.getMessage());
203             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
204             error_code.error = new UIDType(
205                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
206                 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value);
207
208             error_code.details = ExceptionMessages.namebinding_exists_error;
209             throw new CreateError(error_code);
210
211         }
212         catch(java.lang.NoSuchFieldException JavaDoc ex_field) {
213             System.err.println("java.lang.NoSuchFieldException caught " +
214                     ex_field.getMessage());
215             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
216             error_code.error = new UIDType(
217                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
218                 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value);
219
220             error_code.details = ExceptionMessages.namebinding_field_error;
221             throw new CreateError(error_code);
222
223         }
224         catch(java.lang.IllegalAccessException JavaDoc ex_acc) {
225             System.err.println("java.lang.IllegalAccessException caught " +
226                     ex_acc.getMessage());
227             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
228             error_code.error = new UIDType(
229                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
230                 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value);
231
232             error_code.details = ExceptionMessages.namebinding_field_error;
233             throw new CreateError(error_code);
234
235         }
236         // Check if managers are allowed to create the object.
237
if (!managerMayCreatePolicy) {
238             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
239             error_code.error = new UIDType(
240                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
241                 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value);
242
243             error_code.details = ExceptionMessages.manager_create_error;
244             throw new CreateError(error_code);
245         }
246
247         // Check if the parent exists
248
if (! c_query.exists(superior)) {
249             ApplicationErrorInfoTypeImpl error_code = new ApplicationErrorInfoTypeImpl();
250             error_code.error = new UIDType(
251                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
252                 intt.itu.itut_x780.ApplicationErrorConst.objectNotFound.value);
253
254             error_code.details = Utils.name2string(superior) +
255                             ExceptionMessages.parent_object_error;
256
257             throw new ApplicationError(error_code);
258         }
259
260         // The system must have th capability of auto-naming objects
261
String JavaDoc allocatedId = reqId;
262         if (reqId == null || reqId.length() == 0) {
263
264             System.err.println("Auto-naming gets activated..");
265             org.omg.CosNaming.NameComponent JavaDoc[][] siblings =
266                 c_query.getContained(superior);
267             System.err.println("Parent has " + siblings.length +
268                     " children");
269
270             boolean idFound = false;
271             int id = 0, name_length = 0;
272             while(! idFound) {
273                 id++;
274                 int i = 0;
275                 for(i = 0; i < siblings.length; i++) {
276                     if (siblings[i] !=null && (name_length=siblings[i].length) > 0) {
277                         if (siblings[i][name_length -2].id.equals(Integer.toString(id))) {
278                             break;
279                         }
280                     }
281                 }
282                 if (i >= siblings.length) {
283                     idFound = true;
284                 }
285             }
286             allocatedId = Integer.toString(id);
287         }
288
289         // Construct the name of the new object
290
org.omg.CosNaming.NameComponent JavaDoc[] name;
291
292         int index = 0;
293         if (superior.length == 1) {
294             name = new org.omg.CosNaming.NameComponent JavaDoc[superior.length + 2];
295                 index = 1;
296         }
297         else {
298             name = new org.omg.CosNaming.NameComponent JavaDoc[superior.length + 1];
299                 index = superior.length - 1;
300         }
301         int i = 0;
302         for(i = 0; i < index; i++)
303             name[i] = superior[i];
304
305             // the before-last name component, contains the element's id info
306
name[i++] = new org.omg.CosNaming.NameComponent JavaDoc(allocatedId, objectKind);
307
308             // the last component contains the facade's info;
309
name[i] = new org.omg.CosNaming.NameComponent JavaDoc("", Utils.name2facade(facade.facade_name()));
310         Utils.pretty_log(logSupport, FACTORY_CLASS, "Factory", (short) LogSeverity._Info,
311           "proceed to create " + Utils.name2string(name));
312         //System.err.println("Before invoking the facade " +
313
// Utils.name2facade(facade.facade_name()) + " to create " + Utils.name2string(name));
314
facade.create(name, objectKind, new String JavaDoc[0], deletePolicy,
315                     intt.itu.itut_x780.SourceIndicatorType.managementOperation);
316         //System.err.println("Before invoking the containment_service...");
317
c_admin.addName(name, superior);
318         Utils.pretty_log(logSupport, FACTORY_CLASS, "Factory", (short) LogSeverity._Info,
319           "successfully created " + Utils.name2string(name));
320         //System.err.println("create_base returns for " + Utils.name2string(name));
321
return name;
322     }
323
324 }
325
Popular Tags