KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Deployment > ComponentInstallationImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@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): Raphael Marvie, Philippe Merle.
23 Contributor(s): Mathieu Vadet, Briclet Frederic______________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.Deployment;
28
29 /**
30  * This class implements the OMG IDL
31  * Components::Deployment::ComponentInstallation interface.
32  *
33  * @author <a HREF="mailto:Raphael.Marvie@lifl.fr">Raphael Marvie</a>
34  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
35  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
36  * <a HREF="mailto:Frederic.Briclet@lifl.fr">Fr?d?ric Briclet</a>
37  *
38  * @version 0.3
39  */

40
41 public class ComponentInstallationImpl
42        extends org.omg.Components.Deployment.ComponentInstallationPOA
43 {
44     // ==================================================================
45
//
46
// Internal state.
47
//
48
// ==================================================================
49

50     /**
51      ** To store the loaded archives.
52      **/

53     protected org.objectweb.ccm.util.Table implementations_;
54
55     /**
56      ** The path where the archives are stored.
57      **/

58     protected java.io.File JavaDoc path_;
59
60     // ==================================================================
61
//
62
// Constructor.
63
//
64
// ==================================================================
65

66     /**
67      ** The constructor.
68      **
69      ** @param path The path where the archives are stored.
70      ** @param classLoader The class loader used to load home classes.
71      **/

72     public
73     ComponentInstallationImpl(String JavaDoc path)
74     {
75                 implementations_ = new org.objectweb.ccm.util.Table();
76                 path_ = new java.io.File JavaDoc(path);
77                 //----> fred adding
78
// create the path if it doesn't exist
79
if(!path_.exists())
80                     path_.mkdirs();
81     }
82     
83     // ==================================================================
84
//
85
// Internal methods.
86
//
87
// ==================================================================
88

89     // ==================================================================
90
//
91
// Public methods.
92
//
93
// ==================================================================
94

95     // ==================================================================
96
//
97
// Methods for the Components::Deployment::ComponentInstallation interface.
98
//
99
// ==================================================================
100

101     //
102
// IDL:omg.org/Components/Deployment/ComponentInstallation/install:1.0
103
//
104
/**
105      ** Install a component archive.
106      **
107      ** @param implUUID The implementation identifier.
108      ** @param component_loc The location of the component archive.
109      **
110      ** @return True for success.
111      **
112      ** @exception org.omg.Components.Deployment.InvalidLocation
113      ** Thrown if the location is invalid.
114      **/

115     public void
116     install(String JavaDoc implUUID,
117             String JavaDoc component_loc)
118         throws org.omg.Components.Deployment.InvalidLocation,
119                    org.omg.Components.Deployment.InstallationFailure
120     {
121         // TODO: Must be fully rewritten!!!!
122

123         //
124
if(implementations_.contains(implUUID))
125             return ;
126         
127         java.io.InputStream JavaDoc bis = null;
128         java.io.OutputStream JavaDoc bos = null;
129         java.net.URL JavaDoc url = null;
130         String JavaDoc filename;
131         // extraire le nom du fichier ou de l'archive pour le nom du fichier
132
// de sortie.
133

134         try{
135             filename=(new java.net.URL JavaDoc(component_loc)).getFile();
136             filename=filename.substring(filename.lastIndexOf("/"));
137         }
138         catch(Exception JavaDoc e0){
139             //e0.printStackTrace();
140
throw new org.omg.Components.Deployment.InstallationFailure();
141         }
142         java.io.File JavaDoc output = new java.io.File JavaDoc (path_, filename);
143         try
144             {
145                 path_.mkdirs();
146                 bos = new java.io.FileOutputStream JavaDoc (output);
147             }
148         catch (java.io.FileNotFoundException JavaDoc e)
149             {
150                 throw new org.omg.Components.Deployment.InvalidLocation();
151             }
152         catch (java.io.IOException JavaDoc e1)
153             {
154                 //
155
// TODO : which value to set ??
156
//
157
throw new org.omg.Components.Deployment.InstallationFailure();
158             }
159         
160         try
161             {
162                 url = new java.net.URL JavaDoc (component_loc);
163                 bis = (java.io.InputStream JavaDoc) url.openStream();
164             }
165         catch (java.net.MalformedURLException JavaDoc e)
166             {
167                 throw new org.omg.Components.Deployment.InvalidLocation ();
168             }
169         catch (java.io.FileNotFoundException JavaDoc e)
170             {
171                 throw new org.omg.Components.Deployment.InvalidLocation();
172             }
173         catch (java.io.IOException JavaDoc e)
174             {
175                 //
176
// TODO : which value to set ??
177
//
178
throw new org.omg.Components.Deployment.InstallationFailure();
179             }
180         
181         // fetching the file
182
try
183             {
184                 int length;
185                 byte b[] = new byte[2048];
186                 while (true)
187                     {
188                         length = bis.read(b, 0, 2048);
189                         if (length == -1)
190                             break;
191                         bos.write(b, 0, length);
192                     }
193                 bis.close();
194                 bos.close();
195             }
196         catch (java.io.IOException JavaDoc e)
197             {
198                 //
199
// TODO : which value to set ??
200
//
201
throw new org.omg.Components.Deployment.InstallationFailure();
202             }
203         
204         //--> Fred modification on the archive name to store
205
try{
206             implementations_.put(implUUID, output.toURL().toString());
207         }
208         catch(Exception JavaDoc ei)
209             {
210                 System.err.println("Problem occurs during the adding of the URL");
211                 throw new org.omg.Components.Deployment.InstallationFailure();
212             }
213         //----->Fred modification :
214
// the loading treatment is done now by Container
215
/* try
216             {
217             TheURLClassLoader.getURLClassLoader().addURL(output.toURL());
218             }
219             catch (java.net.MalformedURLException e)
220             {
221             throw new org.omg.Components.Deployment.InstallationFailure();
222             }*/

223     }
224  
225     //
226
// IDL:omg.org/Components/Deployment/ComponentInstallation/replace:1.0
227
//
228
/**
229      ** Replace a component archive.
230      **
231      ** @param implUUID The implementation identifier.
232      ** @param component_loc The location of the component archive.
233      **
234      ** @return True for success.
235      **
236      ** @exception org.omg.Components.Deployment.InvalidLocation
237      ** Thrown if the location is invalid.
238      **/

239     public void
240     replace(String JavaDoc implUUID,
241             String JavaDoc component_loc)
242     throws org.omg.Components.Deployment.InvalidLocation,
243            org.omg.Components.Deployment.InstallationFailure
244     {
245         install(implUUID, component_loc);
246     }
247
248     //
249
// IDL:omg.org/Components/Deployment/ComponentInstallation/remove:1.0
250
//
251
/**
252      ** Remove a component archive.
253      **
254      ** @param implUUID The implementation identifier.
255      **
256      ** @return True for success.
257      **
258      ** @exception org.omg.Components.Deployment.UnknownImplId
259      ** Thrown if the implementation identifier is unknown.
260      **/

261     public void
262     remove(String JavaDoc implUUID)
263         throws org.omg.Components.Deployment.UnknownImplId,
264            org.omg.Components.RemoveFailure
265     {
266         //
267
Object JavaDoc o = implementations_.remove(implUUID);
268                 
269                 //
270
if(o == null)
271                 {
272                         throw new org.omg.Components.Deployment.UnknownImplId();
273                 }
274
275                 // TODO: remove the file from the disk
276
}
277         
278     //
279
// IDL:omg.org/Components/Deployment/ComponentInstallation/get_implementation:1.0
280
//
281
/**
282      ** Get the implementation location on the local disk.
283      **
284      ** @param implUUID The implementation identifier.
285      **
286      ** @return The location of the implementation.
287      **
288      ** @exception org.omg.Components.Deployment.UnknownImplId
289      ** Thrown if the implementation identifier is unknown.
290      **/

291     public String JavaDoc
292     get_implementation(String JavaDoc implUUID)
293     throws org.omg.Components.Deployment.UnknownImplId,
294            org.omg.Components.Deployment.InstallationFailure
295     {
296         //
297
String JavaDoc impl = (String JavaDoc)implementations_.get(implUUID);
298                 
299                 //
300
if(impl == null)
301                 {
302                         throw new org.omg.Components.Deployment.UnknownImplId();
303                 }
304
305                 //
306
return impl;
307     }
308 }
309
310
311
312
Popular Tags