KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2005 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 $Id: ExtComponentInstallationImpl.java,v 1.3 2005/06/07 14:23:35 merle Exp $
27 ====================================================================*/

28
29 package org.objectweb.openccm.OpenCCM_DCI.cif;
30
31 import java.io.File JavaDoc;
32 import java.io.FileDescriptor JavaDoc;
33 import java.io.FileInputStream JavaDoc;
34 import java.io.FileOutputStream JavaDoc;
35 import java.io.FileReader JavaDoc;
36 import java.io.InputStream JavaDoc;
37 import java.io.InputStreamReader JavaDoc;
38 import java.net.ServerSocket JavaDoc;
39 import java.net.URL JavaDoc;
40 import java.util.zip.ZipEntry JavaDoc;
41
42 import org.objectweb.openccm.descriptor.ZipEntryRetriever;
43 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.BaseHandlerResolver;
44 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.HandlerContext;
45 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.managers.DefaultDeploymentLogger;
46 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.managers.DefaultErrorManager;
47 import org.objectweb.openccm.descriptor.deployerconfig.Deployerconfig;
48 import org.objectweb.openccm.descriptor.deployerconfig.DeployerconfigImpl;
49 import org.objectweb.openccm.descriptor.deployerconfig.beans.DeployerconfigBeanImpl;
50 import org.objectweb.openccm.descriptor.softpkg.Softpkg;
51 import org.objectweb.openccm.descriptor.softpkg.beans.SoftpkgBean;
52 import org.objectweb.openccm.descriptor.softpkg.beans.SoftpkgBeanImpl;
53 import org.objectweb.openccm.descriptor.softpkg.ccm.ImplementationDeployer;
54 import org.objectweb.openccm.descriptor.softpkg.ccm.SoftpkgDeployer;
55 import org.objectweb.openccm.descriptor.softpkg.ccm.SoftpkgDeployerHandler;
56 import org.objectweb.openccm.descriptor.softpkg.ccm.SoftpkgRootDeployerContext;
57 /**
58  * This is the implementation of the ExtComponentInstallation facet
59  * provided by the NodeManager component.
60  * This class inherits from the skeleton
61  * generated by the OpenCCM's CIF to Java mapping generator.
62  *
63  * @author <a HREF="mailto:Frederic.Briclet@lifl.fr">Briclet Frederic</A>
64  */

65
66 public class ExtComponentInstallationImpl
67             extends org.objectweb.openccm
68                     .OpenCCM_DCI.NodeManagerSessionComposition
69                     .ComponentInstallationSeg
70 {
71      
72     // ==================================================================
73
//
74
// Internal state.
75
//
76
// ==================================================================
77

78     /**
79      ** To store the loaded archives.
80      **/

81     protected org.objectweb.ccm.util.Table implementations_;
82
83     /**
84      ** The path where the archives are stored.
85      **/

86     protected java.io.File JavaDoc path_;
87
88     // ==================================================================
89
//
90
// Constructor.
91
//
92
// ==================================================================
93

94     /**
95      ** The constructor.
96      **
97      ** @param path The path where the archives are stored.
98      ** @param classLoader The class loader used to load home classes.
99      **/

100     public
101     ExtComponentInstallationImpl()
102     { // super();
103
implementations_ = new org.objectweb.ccm.util.Table();
104     
105                 
106     }
107     
108    
109         
110     
111     // ==================================================================
112
//
113
// Internal methods.
114
//
115
// ==================================================================
116

117     // ==================================================================
118
//
119
// Public methods.
120
//
121
// ==================================================================
122

123     public void
124     setComponentInstallationDir(String JavaDoc path )
125     {
126         path_ = new java.io.File JavaDoc(path);
127     }
128     // ==================================================================
129
//
130
// Methods for the Components::Deployment::ComponentInstallation interface.
131
//
132
// ==================================================================
133

134     //
135
// IDL:omg.org/Components/Deployment/ComponentInstallation/install:1.0
136
//
137
/**
138      ** Install a component archive.
139      **
140      ** @param implUUID The implementation identifier.
141      ** @param component_loc The location of the component archive.
142      **
143      ** @return True for success.
144      **
145      ** @exception org.omg.Components.Deployment.InvalidLocation
146      ** Thrown if the location is invalid.
147      **/

148     public void
149     install(String JavaDoc implUUID,
150             String JavaDoc component_loc)
151     throws org.omg.Components.Deployment.InvalidLocation,
152            org.omg.Components.Deployment.InstallationFailure
153     {
154         // TODO: Must be fully rewritten!!!!
155

156         //
157
if(implementations_.contains(implUUID))
158             return ;
159         
160         java.io.DataInputStream JavaDoc br= null;
161         java.io.InputStream JavaDoc bis = null;
162         FileOutputStream JavaDoc bos = null;
163         java.net.URL JavaDoc url = null;
164         java.io.File JavaDoc output;
165
166         
167         // extraire le nom du fichier ou de l'archive pour le nom du fichier
168
// de sortie.
169
String JavaDoc filename ;
170         //System.err.println("EXII>> location:"+component_loc);
171
try{
172             
173             filename=(new java.net.URL JavaDoc(component_loc)).getFile();
174             filename=filename.substring(filename.lastIndexOf("/"));
175             
176         }
177         catch(Exception JavaDoc e0){
178             e0.printStackTrace();
179             throw new org.omg.Components.Deployment.InstallationFailure();
180         }
181         output = new java.io.File JavaDoc (path_, filename);
182         try
183             {
184                 path_.mkdirs();
185                 bos = new java.io.FileOutputStream JavaDoc (output);
186             }
187         catch (java.io.FileNotFoundException JavaDoc e)
188             {
189                 // System.err.println("Fichier de sortie:"+path_+filename);
190
throw new org.omg.Components.Deployment.InvalidLocation();
191             }
192         catch (java.io.IOException JavaDoc e1)
193             {
194                 //
195
// TODO : which value to set ??
196
//
197
e1.printStackTrace();
198                 throw new org.omg.Components.Deployment.InstallationFailure();
199             }
200         
201         try
202             {
203                 url = new java.net.URL JavaDoc(component_loc);
204                 bis = url.openStream();
205                 
206             }
207         catch (java.net.MalformedURLException JavaDoc e)
208             {
209                 e.printStackTrace();
210                 throw new org.omg.Components.Deployment.InvalidLocation ();
211             }
212         catch (java.io.FileNotFoundException JavaDoc e)
213             {
214                 e.printStackTrace();
215                 throw new org.omg.Components.Deployment.InvalidLocation();
216             }
217         catch (java.io.IOException JavaDoc e)
218             {
219                 //
220
// TODO : which value to set ??
221
//
222
e.printStackTrace();
223                                 
224                 throw new org.omg.Components.Deployment.InstallationFailure();
225             }
226         
227         // fetching the file
228
try
229         {
230
231             byte [] byteArray= new byte[32000];
232             int readed=readed=bis.read(byteArray,0,32000);
233             
234             while(readed>0)
235                 {
236                     bos.write(byteArray,0,readed);
237                     readed=bis.read(byteArray,0,32000);
238                 }
239
240             bis.close();
241             bos.flush();
242             bos.close();
243         }
244         catch (java.io.IOException JavaDoc e)
245             {
246                 e.printStackTrace();
247                                 
248                 //
249
// TODO : which value to set ??
250
//
251
throw new org.omg.Components.Deployment.InstallationFailure();
252             }
253         
254         try{
255             implementations_.put(implUUID,output.toURL().toString());
256              if(component_loc.endsWith(".car")||component_loc.endsWith(".zip"))
257              {
258                    processComponentArchive(output);
259              }
260
261         }
262         catch(Exception JavaDoc ei)
263             {
264                 ei.printStackTrace();
265                 System.err.println("Problem occurs during the adding of the output URL");
266                 throw new org.omg.Components.Deployment.InstallationFailure();
267             }
268         //try
269
//{
270
// TheURLClassLoader.getURLClassLoader().addURL(output.toURL());
271
// }
272
// catch (java.net.MalformedURLException e)
273
// {
274
//throw new org.omg.Components.Deployment.InstallationFailure();
275
// }
276
}
277      /**
278      * @param stream
279      */

280     private void
281     processComponentArchive(File JavaDoc stream)
282     throws Exception JavaDoc
283     {
284
285         ZipEntryRetriever ze=new ZipEntryRetriever(stream);
286         SoftpkgRootDeployerContext sprd=new SoftpkgRootDeployerContext();
287         ze.connectStreamManager(sprd);
288         sprd.connectZipEntryRetriever(ze);
289         DefaultDeploymentLogger ddl=new DefaultDeploymentLogger
290                                             (System.getProperty("WorkDir")
291                                              +"/ComponentInstalltionLog.log");
292         sprd.connectDeploymentLogger(ddl);
293         sprd.connectServerSocket(new ServerSocket JavaDoc(0));
294         //To correct adding a valid ErrorManager correctly setup
295

296         FileReader JavaDoc fr=new FileReader JavaDoc(System.getProperty("DeployerConfigFile"));
297
298         Deployerconfig depl_conf=(Deployerconfig)
299                                     DeployerconfigBeanImpl.unmarshal(fr,false);
300
301         DefaultErrorManager erm=new DefaultErrorManager(depl_conf);
302         erm.connectDeploymentLogger(ddl);
303         sprd.connectErrorManager(erm);
304         
305         String JavaDoc csdEntryNames[]=ze.getZipEntriesEndingBy(".csd");
306         InputStream JavaDoc is=ze.getZipEntryISIgnoringDelimiterType(csdEntryNames[0]);
307
308         SoftpkgBeanImpl sbi=(SoftpkgBeanImpl) SoftpkgBeanImpl
309                                                 .unmarshalBean(new InputStreamReader JavaDoc(is),true);
310
311         SoftpkgDeployerHandler softHandler=//new SoftpkgDeployerHandler();
312
((SoftpkgDeployerHandler)
313                                        sbi
314                                        .getExtensionManager()
315                                        .getExtensionByName("ccm.Deployer"));
316         
317         HandlerContext dc=new HandlerContext();
318         dc.connectHandlerResolver(new BaseHandlerResolver());
319         softHandler.connectHandlerContext(dc);
320
321         softHandler.connectRootDeployerContext(sprd);
322         
323         //connections to do
324

325
326         SoftpkgDeployer sfpkgDeployer=(SoftpkgDeployer)softHandler.getInstance(sbi);
327
328         sfpkgDeployer.processDependencies(this);
329
330         ImplementationDeployer implDeployers[]=sfpkgDeployer.getImplementationDeployers();
331         for(int i=0;i<implDeployers.length;i++)
332             implDeployers[i].install(this);
333            
334         sprd.clearAllStream();
335                     
336     }
337     //
338
// IDL:omg.org/Components/Deployment/ComponentInstallation/replace:1.0
339
//
340
/**
341      ** Replace a component archive.
342      **
343      ** @param implUUID The implementation identifier.
344      ** @param component_loc The location of the component archive.
345      **
346      ** @return True for success.
347      **
348      ** @exception org.omg.Components.Deployment.InvalidLocation
349      ** Thrown if the location is invalid.
350      **/

351     public void
352     replace(String JavaDoc implUUID,
353             String JavaDoc component_loc)
354     throws org.omg.Components.Deployment.InvalidLocation,
355            org.omg.Components.Deployment.InstallationFailure
356     {
357         install(implUUID, component_loc);
358     }
359
360     //
361
// IDL:omg.org/Components/Deployment/ComponentInstallation/remove:1.0
362
//
363
/**
364      ** Remove a component archive.
365      **
366      ** @param implUUID The implementation identifier.
367      **
368      ** @return True for success.
369      **
370      ** @exception org.omg.Components.Deployment.UnknownImplId
371      ** Thrown if the implementation identifier is unknown.
372      **/

373     public void
374     remove(String JavaDoc implUUID)
375     throws org.omg.Components.Deployment.UnknownImplId,
376            org.omg.Components.RemoveFailure
377     {
378         //
379
Object JavaDoc o = implementations_.remove(implUUID);
380                 
381         //
382
if(o == null)
383             {
384                 throw new org.omg.Components.Deployment.UnknownImplId();
385             }
386         
387         // TODO: remove the file from the disk
388
}
389     
390     //
391
// IDL:omg.org/Components/Deployment/ComponentInstallation/get_implementation:1.0
392
//
393
/**
394      ** Get the implementation location on the local disk.
395      **
396      ** @param implUUID The implementation identifier.
397      **
398      ** @return The location of the implementation.
399      **
400      ** @exception org.omg.Components.Deployment.UnknownImplId
401      ** Thrown if the implementation identifier is unknown.
402      **/

403     public String JavaDoc
404     get_implementation(String JavaDoc implUUID)
405     throws org.omg.Components.Deployment.UnknownImplId,
406            org.omg.Components.Deployment.InstallationFailure
407     {
408         //
409
String JavaDoc impl = (String JavaDoc)implementations_.get(implUUID);
410         
411         //
412
if(impl == null)
413             {
414                 throw new org.omg.Components.Deployment.UnknownImplId();
415             }
416         
417         //
418
return impl;
419     }
420     
421     public String JavaDoc []
422     get_all_implUUIDs()
423     {
424      String JavaDoc [] result= new String JavaDoc [implementations_.size()];
425      int i=0;
426      
427      for(java.util.Enumeration JavaDoc keys=implementations_.keys();
428          keys.hasMoreElements();){
429          result[i]=(String JavaDoc)keys.nextElement();
430          i++;
431         }
432                     
433         return result;
434     }
435     
436     public String JavaDoc
437     upload( String JavaDoc name,byte[] data){
438         // TO COMPLETE
439
return "to implement";
440     }
441 }
442
Popular Tags