KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > itut_x780Components > ManagedObjectFactoryProviderMonolithicImpl


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_x780Components;
22
23 import ist.coach.coachEmfCommon.Utils;
24 import ist.coach.coachEmfCommon.ExceptionMessages;
25 import intt.itu.itut_x780.UIDType;
26 import intt.itu.itut_x780.CreateError;
27 import intt.itu.itut_x780.ApplicationError;
28
29 import intt.itu.itut_x780.ManagedObjectFactory;
30 import intt.itu.itut_x780.ManagedObjectFactoryHelper;
31 import ist.coach.coachEmfCommon.CreateErrorInfoTypeImpl;
32 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl;
33
34
35 /**
36  ** Implementation class for the ::itut_x780Components::ManagedObjectFactoryProvider component.
37  **/

38 public class ManagedObjectFactoryProviderMonolithicImpl
39        extends org.omg.CORBA.LocalObject JavaDoc
40        implements CCM_ManagedObjectFactoryProvider,
41                   org.omg.Components.SessionComponent
42 {
43     // ==================================================================
44
//
45
// Internal State.
46
//
47
// ===================================================================
48
/**
49      ** Context reference.
50      **/

51     private CCM_ManagedObjectFactoryProvider_Context the_context_;
52     /* Business logic **/
53     intt.itu.itut_q816.ContainmentComponent c_admin = null;
54     intt.itu.itut_q816.Containment c_query = null;
55
56     private static final String JavaDoc FACTORY_CLASS = "ManagedObjectFactory";
57     ManagedObjectMgmt facade = null;
58     // ==================================================================
59
//
60
// Constructor.
61
//
62
// ===================================================================
63
/**
64      ** The default constructor.
65      **/

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

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

106     public void
107     configuration_complete()
108     throws org.omg.Components.InvalidConfiguration
109     {
110         //
111
// DONE : implement !!!
112
//
113
if ((facade = the_context_.get_connection_facade()) == null)
114             throw new org.omg.Components.InvalidConfiguration();
115
116         if ((c_admin = the_context_.get_connection_containment_admin()) == null)
117             throw new org.omg.Components.InvalidConfiguration();
118
119         if ((c_query = the_context_.get_connection_containment_query()) == null)
120             throw new org.omg.Components.InvalidConfiguration();
121
122             // If managers may create, then the factory must register to the
123
// factory finder service
124
intt.itu.itut_q816.FactoryFinderComponent factoryfinder_admin =
125             the_context_.get_connection_factoryfinder_admin();
126
127         org.omg.CORBA.Object JavaDoc myself_o;
128         ManagedObjectFactory myself = null;
129
130         try {
131             myself_o = ((org.omg.Components.SessionContext) the_context_).get_CCM_object();
132             myself = ManagedObjectFactoryHelper.narrow(myself_o);
133
134             factoryfinder_admin.register(FACTORY_CLASS, myself);
135             //factoryfinder_admin.register(FACTORY_CLASS, this);
136
}
137         catch(intt.itu.itut_x780.ApplicationError ex) {
138             throw new org.omg.Components.InvalidConfiguration();
139         }
140         catch(Exception JavaDoc e) {
141             System.err.println("ManagedObjectFactory has problems retrieving CCM component");
142         }
143
144
145         System.err.println("ManagedObjectFactoryProvider configuration completed...");
146     }
147     // ==================================================================
148
//
149
// Methods for the OMG IDL Components::SessionComponent local interface.
150
//
151
// ==================================================================
152
//
153
// IDL:omg.org/Components/SessionComponent/set_session_context:1.0
154
//
155
/**
156      * Called by the container when the component session context will be fixed.
157      *
158      * @param context The session context.
159      *
160      * @throws org.omg.Components.CCMException
161      * Thrown if a system level error occured.
162      */

163     public void
164     set_session_context(org.omg.Components.SessionContext context)
165     throws org.omg.Components.CCMException
166     {
167         the_context_ = (CCM_ManagedObjectFactoryProvider_Context)context;
168     }
169     //
170
// IDL:omg.org/Components/SessionComponent/ccm_activate:1.0
171
//
172
/**
173      *
174      * Called by the container when the component will be activated.
175      *
176      * @throws org.omg.Components.CCMException
177      * Thrown if a system level error occured.
178      */

179     public void
180     ccm_activate()
181     throws org.omg.Components.CCMException
182     {
183         //
184
// Unused by actual OpenCCM containers
185
//
186
}
187     //
188
// IDL:omg.org/Components/SessionComponent/ccm_passivate:1.0
189
//
190
/**
191      *
192      * Called by the container when the component will be passivated.
193      *
194      * @throws org.omg.Components.CCMException
195      * Thrown if a system level error occured.
196      */

197     public void
198     ccm_passivate()
199     throws org.omg.Components.CCMException
200     {
201         //
202
// Unused by actual OpenCCM containers
203
//
204
}
205     //
206
// IDL:omg.org/Components/SessionComponent/ccm_remove:1.0
207
//
208
/**
209      *
210      * Called by the container when the component will be removed.
211      *
212      * @throws org.omg.Components.CCMException
213      * Thrown if a system level error occured.
214      */

215     public void
216     ccm_remove()
217     throws org.omg.Components.CCMException
218     {
219         //
220
// TO DO: implement !!!
221
//
222
}
223     // ==================================================================
224
//
225
// Public methods for the CCM_ManagedObjectFactoryProvider local interface.
226
//
227
// ==================================================================
228
public org.omg.CosNaming.NameComponent JavaDoc[]
229     create_base(String JavaDoc nameBinding,
230                 org.omg.CosNaming.NameComponent JavaDoc[] superior,
231                 String JavaDoc reqId)
232     throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.CreateError {
233
234         short deletePolicy = -1;
235         boolean managerMayCreatePolicy = false;
236         String JavaDoc objectKind = new String JavaDoc();
237         String JavaDoc nameBinding_str = "intt.itu.itut_x780.NameBindings." +
238                 nameBinding;
239         try {
240             Class JavaDoc deletePolicyClass =
241                 Class.forName(nameBinding_str + ".deletePolicy");
242
243             deletePolicy =
244                 deletePolicyClass.getDeclaredField("value").getShort(null);
245
246             Class JavaDoc managerMayCreatePolicyClass =
247                     Class.forName(nameBinding_str + ".managersMayCreate");
248             managerMayCreatePolicy =
249                 managerMayCreatePolicyClass.getDeclaredField("value").getBoolean(null);
250
251             Class JavaDoc objectKindClass =
252                      Class.forName(nameBinding_str + ".kind");
253             objectKind = (String JavaDoc) objectKindClass.getDeclaredField("value").get(null);
254
255     /*
256             System.err.println("deletePolicy = " + deletePolicy +
257                                 "managerMayCreatePolicy = " + managerMayCreatePolicy +
258                                 "objectKind = " + objectKind);
259     */

260
261         }
262         catch(java.lang.ClassNotFoundException JavaDoc ex) {
263             System.err.println(nameBinding_str + " can not be found!" + ex.getMessage());
264             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
265             error_code.error = new UIDType(
266                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
267                 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value);
268
269             error_code.details = ExceptionMessages.namebinding_exists_error;
270             throw new CreateError(error_code);
271
272         }
273         catch(java.lang.NoSuchFieldException JavaDoc ex_field) {
274             System.err.println("java.lang.NoSuchFieldException caught " +
275                     ex_field.getMessage());
276             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
277             error_code.error = new UIDType(
278                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
279                 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value);
280
281             error_code.details = ExceptionMessages.namebinding_field_error;
282             throw new CreateError(error_code);
283
284         }
285         catch(java.lang.IllegalAccessException JavaDoc ex_acc) {
286             System.err.println("java.lang.IllegalAccessException caught " +
287                     ex_acc.getMessage());
288             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
289             error_code.error = new UIDType(
290                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
291                 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value);
292
293             error_code.details = ExceptionMessages.namebinding_field_error;
294             throw new CreateError(error_code);
295
296         }
297         // Check if managers are allowed to create the object.
298
if (!managerMayCreatePolicy) {
299             CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl();
300             error_code.error = new UIDType(
301                 intt.itu.itut_x780.CreateErrorConst.moduleName.value,
302                 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value);
303
304             error_code.details = ExceptionMessages.manager_create_error;
305             throw new CreateError(error_code);
306         }
307
308         // Check if the parent exists
309
if (! c_query.exists(superior)) {
310             ApplicationErrorInfoTypeImpl error_code = new ApplicationErrorInfoTypeImpl();
311             error_code.error = new UIDType(
312                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
313                 intt.itu.itut_x780.ApplicationErrorConst.objectNotFound.value);
314
315             error_code.details = Utils.name2string(superior) +
316                             ExceptionMessages.parent_object_error;
317         
318             throw new ApplicationError(error_code);
319         }
320
321         // The system must have th capability of auto-naming objects
322
String JavaDoc allocatedId = reqId;
323         if (reqId == null || reqId.length() == 0) {
324
325             System.err.println("Auto-naming gets activated..");
326             org.omg.CosNaming.NameComponent JavaDoc[][] siblings =
327                 c_query.getContained(superior);
328             System.err.println("Parent has " + siblings.length +
329                     " children");
330
331             boolean idFound = false;
332             int id = 0, name_length = 0;
333             while(! idFound) {
334                 id++;
335                 int i = 0;
336                 for(i = 0; i < siblings.length; i++) {
337                     if (siblings[i] !=null && (name_length=siblings[i].length) > 0) {
338                         if (siblings[i][name_length -2].id.equals(Integer.toString(id))) {
339                             break;
340                         }
341                     }
342                 }
343                 if (i >= siblings.length) {
344                     idFound = true;
345                 }
346             }
347             allocatedId = Integer.toString(id);
348         }
349     
350         // Construct the name of the new object
351
org.omg.CosNaming.NameComponent JavaDoc[] name;
352
353         int index = 0;
354         if (superior.length == 1) {
355             name = new org.omg.CosNaming.NameComponent JavaDoc[superior.length + 2];
356                 index = 1;
357         }
358         else {
359             name = new org.omg.CosNaming.NameComponent JavaDoc[superior.length + 1];
360                 index = superior.length - 1;
361         }
362         int i = 0;
363         for(i = 0; i < index; i++)
364             name[i] = superior[i];
365
366             // the before-last name component, contains the element's id info
367
name[i++] = new org.omg.CosNaming.NameComponent JavaDoc(allocatedId, objectKind);
368             
369             // the last component contains the facade's info;
370
name[i] = new org.omg.CosNaming.NameComponent JavaDoc("", Utils.name2facade(facade.facade_name()));
371         
372         System.err.println("Before invoking the facade " +
373                     Utils.name2facade(facade.facade_name()) + " to create " + Utils.name2string(name));
374         facade.create(name, objectKind, new String JavaDoc[0], deletePolicy,
375                     intt.itu.itut_x780.SourceIndicatorType.managementOperation);
376
377         c_admin.addName(name, superior);
378
379         System.err.println("create_base returns for " + Utils.name2string(name));
380         return name;
381     }
382 }
383
Popular Tags