KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > OpenCCM_DCI > cif > DCIDeploymentSegImpl


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

26
27 package org.objectweb.openccm.OpenCCM_DCI.cif;
28
29 /**
30  * This is the implementation of the DCIDeployment facet provided by the
31  * DCIManager component.
32  * This class inherits from the skeleton
33  * generated by the OpenCCM's CIF to Java mapping generator.
34  *
35  * @author <a HREF="mailto:Frederic.Briclet@lifl.fr">Briclet Frederic</A>
36  */

37 public class DCIDeploymentSegImpl
38      extends org.objectweb.openccm
39             .OpenCCM_DCI.DCIManagerSessionComposition
40             .DCIDeploymentSeg
41 {
42     // ==================================================================
43
//
44
// Internal class.
45
//
46
// ==================================================================
47

48     /**
49      * This class implements the Iterator behavior on the AssemblyManager
50      * Model connections.
51      */

52     private class AssemblyManagerModelIterator
53     {
54         //The current array of AssemblyManagerModelConnection
55
private org.objectweb.openccm.OpenCCM_DCI.
56             DCIManagerPackage.assembly_manager_modelsConnection []
57             connect;
58
59         //The current index on the array;
60
private int index;
61
62         /**
63          * No parameter required only the DCI of the uppon class
64          * is directly used.
65          * At the creation a rewind is automaticaly done.
66          */

67         public AssemblyManagerModelIterator()
68         {
69             rewind();
70         }
71
72         /**
73          * Return the next AssemblyManagerModel
74          * @return the next AssemblyManagerModel
75          */

76         public org.objectweb.openccm.OpenCCM_DCI.AssemblyManagerModel
77         next()
78         throws java.util.NoSuchElementException JavaDoc
79         {
80             if(index==connect.length)
81                 throw new java.util.NoSuchElementException JavaDoc();
82             index++;
83             return connect[index-1].objref;
84         }
85
86         /**
87          * Return the current AssemblyManagerModel
88          * @return the current AssemblyManagerModel
89          */

90         public org.objectweb.openccm.OpenCCM_DCI.AssemblyManagerModel
91         current()
92         {
93             return connect[index-1].objref;
94         }
95
96         /**
97          * Test the end of the iterator
98          * @return the test result
99          */

100         public boolean
101         hasNext()
102         {
103             return index<connect.length;
104         }
105         
106         public void
107         remove()
108         {
109             // Empty implementation
110
}
111
112         /**
113          * Clear the current iterator, initializing it value with the
114          * most recent connection.
115          */

116         public void
117         rewind()
118         {
119             // initialize to the first index
120
index=0;
121             // initialize the array of model
122
connect=DCI.get_connections_assembly_manager_models();
123         }
124
125         /**
126          * Return the iterator length
127          * @return the current iterator length
128          */

129         public int
130         length()
131         {
132             return connect.length;
133         }
134     }
135     
136     // ==================================================================
137
//
138
// Internal state.
139
//
140
// ==================================================================
141

142     // String prefix for clarifying output message
143
private String JavaDoc prefix="DCIDeploymentSeg >> ";
144
145     // Iterator on the AssemblyManagerModel
146
private AssemblyManagerModelIterator ammIterator;
147
148     //The reference on the DCIManager component interface
149
private org.objectweb.openccm.OpenCCM_DCI.DCIManagerCCM DCI;
150
151     // ==================================================================
152
//
153
// Internal methods.
154
//
155
// ==================================================================
156

157     private org.objectweb.openccm.OpenCCM_DCI.AssemblyManagerModel
158     getAssemblyManagerModel(String JavaDoc assemblyUUID)
159     throws org.ist.coach.DCI.UnknownAssembly
160     {
161         for(ammIterator.rewind();
162             ammIterator.hasNext(); )
163         {
164             if(ammIterator.next().assemblyUUID().equals(assemblyUUID))
165             {
166                 // return the AssemblyManagerModel instance
167
return ammIterator.current();
168             }
169         }
170         throw new org.ist.coach.DCI.UnknownAssembly();
171     }
172
173     // ==================================================================
174
//
175
// Constructor.
176
//
177
// ==================================================================
178

179     // ==================================================================
180
//
181
// Public methods.
182
//
183
// ==================================================================
184

185     public void setupDCI()
186     {
187         DCI=(org.objectweb.openccm.OpenCCM_DCI.DCIManagerCCM)get_context();
188         ammIterator=new AssemblyManagerModelIterator();
189     }
190     
191     /**
192      * This methods allows to install a archive given in parameter
193      * the archive to used.
194      * @param archive The archive in a byte array format
195      * @return The assembly uuid.
196      */

197     public String JavaDoc
198     install_with_archive(byte[] archive)
199     throws org.omg.Components.Deployment.InstallationFailure,
200            org.ist.coach.DCI.AlreadyInstalled,
201            org.ist.coach.DCI.InvalidArchive
202     {
203         // Test if the connection to AssemblyFactory
204
if(DCI.get_connection_assembly_factory()==null)
205         {
206             throw new org.omg.Components.Deployment.InstallationFailure();
207         }
208
209         try
210         {
211             // create an AssemblyManagerModel
212
org.objectweb.openccm.OpenCCM_DCI.AssemblyManagerModel amm=
213                 DCI.get_connection_assembly_manager_model_home()
214                 .create_assembly_model_archive(archive);
215             // connect the assemblyfactory to AssemblyManagerModel
216
amm.connect_assembly_factory(DCI.get_connection_assembly_factory());
217             // connect the AssemblyManagerModel to the DCI
218
// DCI.connect_assembly_manager_models(amm);
219
amm.connect_assembly_manager_model_registration
220                 (DCI.provide_assembly_manager_model_registration());
221             // configure complete the AssemblyManagerModel
222
amm.configuration_complete();
223             // return the assembly uuid
224
return amm.assemblyUUID();
225         }
226         catch(Exception JavaDoc exc)
227         {
228             // TODO: Exception trace must be reported in a better way.
229
exc.printStackTrace(System.err);
230             throw new org.omg.Components.Deployment.InstallationFailure();
231         }
232     }
233     
234     /**
235      * This methods allows to install a descriptor giving in parameter
236      * the xml code to use.
237      * @param descriptor The xml code to use.
238      * @return The assembly uuid.
239      */

240     public String JavaDoc
241     install_with_descriptor(String JavaDoc descriptor)
242     throws org.omg.Components.Deployment.InstallationFailure,
243            org.ist.coach.DCI.AlreadyInstalled
244     {
245         // Test if the connection to AssemblyFactory
246
if(DCI.get_connection_assembly_factory()==null)
247         {
248             throw new org.omg.Components.Deployment.InstallationFailure();
249         }
250
251         try
252         {
253             // create an AssemblyManagerModel
254
org.objectweb.openccm.OpenCCM_DCI.AssemblyManagerModel amm=
255                 DCI.get_connection_assembly_manager_model_home()
256                 .create_assembly_model(descriptor);
257             // connect the assemblyfactory to AssemblyManagerModel
258
amm.connect_assembly_factory(DCI.get_connection_assembly_factory());
259             // connect the AssemblyManagerModel to the DCI
260
// DCI.connect_assembly_manager_models(amm);
261
amm.connect_assembly_manager_model_registration
262                 (DCI.provide_assembly_manager_model_registration());
263             // configure complete the AssemblyManagerModel
264
amm.configuration_complete();
265             // return the assembly uuid
266
return amm.assemblyUUID();
267         }
268         catch(Exception JavaDoc exc)
269         {
270             // TODO: Exception trace must be reported in a better way.
271
exc.printStackTrace(System.err);
272
273             throw new org.omg.Components.Deployment.InstallationFailure();
274         }
275     }
276         
277     /**
278      * Update an installed archive.
279      * @param old_assemblyUUID the archive to replace
280      * @param archive The updating archive
281      */

282     public String JavaDoc
283     update_with_archive(String JavaDoc old_assemblyUUID,
284                         byte[] archive)
285     throws org.ist.coach.DCI.UninstallationFailure,
286            org.ist.coach.DCI.UnknownAssembly,
287            org.omg.Components.Deployment.InstallationFailure,
288            org.ist.coach.DCI.AlreadyInstalled,
289            org.ist.coach.DCI.InvalidArchive
290     {
291         // TODO: Must be implemented!
292
throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
293     }
294
295     /**
296      * Update an installed descriptor.
297      * @param old_assemblyUUID the archive to replace
298      * @param archive The updating archive
299      */

300     public String JavaDoc
301     update_with_descriptor(String JavaDoc old_assemblyUUID,
302                            String JavaDoc descriptor)
303     throws org.ist.coach.DCI.UninstallationFailure,
304            org.ist.coach.DCI.UnknownAssembly,
305            org.omg.Components.Deployment.InstallationFailure,
306            org.ist.coach.DCI.AlreadyInstalled
307     {
308         // TODO: Must be implemented!
309
throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
310     }
311    
312     /**
313      * Uninstall a assembly model an destroy all the created instance
314      * @param assemblyUUID the model to uninstall
315      */

316     public void
317     uninstall(String JavaDoc assemblyUUID)
318     throws org.ist.coach.DCI.UninstallationFailure,
319            org.ist.coach.DCI.UnknownAssembly,
320            org.ist.coach.DCI.AssemblyUsed
321     {
322         getAssemblyManagerModel(assemblyUUID)
323             .provide_assembly_instance_management()
324             .uninstall();
325     }
326
327     /**
328      * This method create an assembly manager instance from
329      * the specified AssemblyManagerModel.
330      *
331      * @param assemblyUUID the AssemblyManagerModel identifiant
332      * @return instanceUUID of the AssemblyManager created
333      */

334     public String JavaDoc
335     create_assembly_instance(String JavaDoc assemblyUUID)
336     throws org.ist.coach.DCI.CreationFailure
337     {
338         try
339         {
340             // retrieve the right AssemblyManagerModel and create the instance
341
return
342                 getAssemblyManagerModel(assemblyUUID)
343                 .provide_assembly_instance_management()
344                 .create_assembly_instance();
345         }
346         catch(Exception JavaDoc e)
347         {
348             System.err.println(prefix+
349                            "Problem occured during the creation of instance");
350             System.err.println(prefix+e.getMessage());
351             throw new org.ist.coach.DCI.CreationFailure();
352         }
353     }
354
355     /**
356      * This method all the AssemblyManager which have been
357      * created from the assemblyUUID model
358      *
359      * @param assemblyUUID the AssemblyManagerModel identifiant
360      * @return All the AssemblyManager found
361      */

362     public String JavaDoc[]
363     get_assembly_instances(String JavaDoc assemblyUUID)
364     throws org.ist.coach.DCI.UnknownAssembly
365     {
366         try
367         {
368             // Retrieve all the connection with the AssemblyManagerModel
369
return
370                 getAssemblyManagerModel(assemblyUUID)
371                 .provide_assembly_instance_management()
372                 .get_assembly_instances();
373         }
374         catch(Exception JavaDoc exc)
375         {
376             // TODO: Exception trace must be reported in a better way.
377
exc.printStackTrace(System.err);
378
379             throw new org.ist.coach.DCI.UnknownAssembly();
380         }
381     }
382
383     /**
384      * This method return the AssemblyManager which have
385      * the same instance_id that specified in parameter
386      * @param instance_id the instance_id required
387      * @return the AssemblyManager found.
388      */

389     public org.ist.coach.DCI.AssemblyManager
390     get_assembly_manager(String JavaDoc instance_id)
391     throws org.ist.coach.DCI.UnknownAssembly
392     {
393         // Browse all the model to find the good AssemblyManager
394
for(ammIterator.rewind();
395             ammIterator.hasNext();)
396         {
397             try
398             {
399                 return ammIterator.next()
400                        .provide_assembly_instance_management()
401                        .get_assembly_manager(instance_id);
402             }
403             catch(org.ist.coach.DCI.UnknownAssembly e)
404             {
405             }
406         }
407
408         // The instance_id was not found due to a bas specified instance_id
409
throw new org.ist.coach.DCI.UnknownAssembly();
410     }
411
412     /**
413      * This method destroy the AssemblyManager which have
414      * the same instance_id that specified in parameter
415      * @param instance_id the instance_id required
416      */

417     public void
418     destroy_assembly_instance(String JavaDoc instance_id)
419     throws org.ist.coach.DCI.DestroyError
420     {
421         //Browse all the model to find the good AssemblyManager
422
for(ammIterator.rewind(); ammIterator.hasNext();)
423         {
424             try
425             {
426                 ammIterator.next()
427                     .provide_assembly_instance_management()
428                     .get_assembly_manager(instance_id);
429                 ammIterator.current()
430                     .provide_assembly_instance_management()
431                     .destroy_assembly_instance(instance_id);
432                 return ;
433             }
434             catch(org.ist.coach.DCI.UnknownAssembly ua)
435             {
436             }
437         }
438
439         // The instance_id was not found due to a bas specified instance_id
440
throw new org.ist.coach.DCI.DestroyError() ;
441     }
442
443     /**
444      * This method return an assemblyUUID array
445      * of all the installed archive and descriptor.
446      * @return all the installed assemblyUUID
447      */

448     public String JavaDoc[]
449     get_assemblies()
450     {
451         java.util.LinkedList JavaDoc ll=new java.util.LinkedList JavaDoc();
452         
453         // Fill the array
454
for(ammIterator.rewind();
455             ammIterator.hasNext();)
456             ll.addLast(ammIterator.next().assemblyUUID());
457
458         // return the array
459
return (String JavaDoc[])ll.toArray(new String JavaDoc[ll.size()]);
460     }
461
462     /**
463      * Return the XML code of the assemblyUUID.
464      * @param assemblyUUID The uuid to use
465      * @return The xml code found.
466      */

467     public String JavaDoc
468     lookup_assembly(String JavaDoc assemblyUUID)
469     throws org.ist.coach.DCI.UnknownAssembly
470     {
471         return getAssemblyManagerModel(assemblyUUID).xml_descriptor();
472     }
473 }
474
Popular Tags