KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > descriptor > componentassembly > ccm > deployer > base > RootDeployerContext


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 Frédéric.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base;
27
28 import java.net.ServerSocket JavaDoc;
29 import java.util.LinkedList JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Enumeration JavaDoc;
33 import java.io.File JavaDoc;
34 import java.io.InputStream JavaDoc;
35 import java.io.Reader JavaDoc;
36 import java.io.IOException JavaDoc;
37 import java.util.zip.ZipFile JavaDoc;
38 import org.ist.coach.DCI.DCIInformation;
39 import org.objectweb.openccm.descriptor.ZipEntryRetriever;
40 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.installer.DestinationDeployerFactory;
41 import org.objectweb.openccm.descriptor.StreamManager;
42 import org.ist.coach.DCI.AssemblyManager;
43 import org.omg.Components.CCMObject;
44 import org.omg.Components.HomeFinder;
45 import org.omg.Components.HomeRegistration;
46 import org.omg.CosNaming.NamingContextExt JavaDoc;
47
48 /**
49  * This class represent the root context of the current deployer tree. It provides
50  * all the services required by the deployer.
51  *
52  * @author <a HREF="mailto:briclet@lifl.fr">Briclet Frédéric</a>
53  *
54  * @version 0.1
55  */

56 public abstract class RootDeployerContext
57        extends DeployerContext
58        implements StreamManager{
59     // ==================================================================
60
//
61
// Internal state.
62
//
63
// ==================================================================
64
/*All the service provides by the root context*/
65     
66     //The current name service to use
67
private NamingContextExt JavaDoc naming;
68     //all the component created by the deployer
69
private LinkedList JavaDoc components;
70     //The symbol conversion tool
71
private SymbolConvertion sc;
72     //The home finder service
73
private HomeFinder homefinder;
74     //The home registration service
75
private HomeRegistration homeregistration;
76     //The dci information service to found node
77
private DCIInformation dciInfo;
78     //The current zip entry retriever use to find file
79
private ZipEntryRetriever zipRetriever;
80     //The current server socket used to install archive
81
private ServerSocket JavaDoc ssocket;
82     //The current deployment logger
83
private DeploymentLogger deploymentLogger;
84     //The upper assembly manager
85
private AssemblyManager assemblyManager;
86     //The factory use to produce the right destination deployer
87
private DestinationDeployerFactory destinationDeployerFactory;
88     //The current error manager
89
private ErrorManager errorManager;
90     //The current workdirectory
91
private String JavaDoc workDir;
92     //All the temporary file create for deployment purpose
93
private Hashtable JavaDoc temporaryFiles;
94     //All the input stream open for deployment
95
private LinkedList JavaDoc openInputStreams;
96     //All the reader open for deployment
97
private LinkedList JavaDoc openReaders;
98     //All the open zip file
99
private LinkedList JavaDoc openZipFiles;
100     // ==================================================================
101
//
102
// Constructors.
103
//
104
// ==================================================================
105

106     public RootDeployerContext(){
107         components=new LinkedList JavaDoc();
108         temporaryFiles=new Hashtable JavaDoc();
109         openInputStreams=new LinkedList JavaDoc();
110         openReaders=new LinkedList JavaDoc();
111         openZipFiles=new LinkedList JavaDoc();
112     }
113     // ==================================================================
114
//
115
// Internal methods.
116
//
117
// ==================================================================
118

119     // ==================================================================
120
//
121
// Public accessor methods
122
//
123
// ==================================================================
124

125     public void
126     connectNamingContextExt(NamingContextExt JavaDoc naming)
127     {
128         this.naming=naming;
129     }
130     
131     public NamingContextExt JavaDoc
132     getNamingContextExt()
133     {
134         return naming;
135     }
136     
137     public void
138     connectHomeFinder(HomeFinder homefinder)
139     {
140         this.homefinder=homefinder;
141     }
142     
143     public HomeFinder
144     getHomefinder()
145     {
146         return homefinder;
147     }
148     
149     
150     public void
151     connectHomeregistration(HomeRegistration homeregistration)
152     {
153         this.homeregistration=homeregistration;
154     }
155     
156     public HomeRegistration
157     getHomeRegistration()
158     {
159         return homeregistration;
160     }
161     
162     public void
163     connectDCIInformation(DCIInformation dciInfo)
164     {
165         this.dciInfo=dciInfo;
166     }
167     
168     public DCIInformation
169     getDCIInformation()
170     {
171         return dciInfo;
172     }
173     
174     public void
175     connectZipEntryRetriever(ZipEntryRetriever zipRetriever)
176     {
177         this.zipRetriever=zipRetriever;
178     }
179     
180     public ZipEntryRetriever
181     getZipEntryRetriever()
182     {
183         return zipRetriever;
184     }
185     
186     public void
187     connectServerSocket(ServerSocket JavaDoc ssocket)
188     {
189         this.ssocket=ssocket;
190     }
191     
192     public ServerSocket JavaDoc
193     getServerSocket()
194     {
195         return ssocket;
196     }
197     
198     public void
199     connectComponent(CCMObject comp)
200     {
201         components.addLast(comp);
202     }
203     
204     public void
205     disconnectComponent(CCMObject comp)
206     {
207         components.remove(comp);
208     }
209     public CCMObject []
210     getComponents()
211     {
212         return (CCMObject[])components.toArray(new CCMObject[components.size()]);
213     }
214     
215     public void
216     connectConvertTool(SymbolConvertion sc)
217     {
218         this.sc=sc;
219     }
220     
221     public String JavaDoc
222     convertSymbol(String JavaDoc ch)
223     {
224         return sc.convertSymbol(ch);
225     }
226     
227     public RootDeployerContext
228     getRootDeployerContext()
229     {
230         return this;
231     }
232     
233     
234     /**
235      * @return
236      */

237     public DeploymentLogger
238     getDeploymentLogger()
239     {
240         return deploymentLogger;
241     }
242
243     /**
244      * @param logger
245      */

246     public void
247     connectDeploymentLogger(DeploymentLogger logger)
248     {
249         deploymentLogger = logger;
250     }
251
252     /**
253      * @return
254      */

255     public AssemblyManager
256     getAssemblyManager()
257     {
258         return assemblyManager;
259     }
260
261     /**
262      * @param manager
263      */

264     public void
265     connectAssemblyManager(AssemblyManager manager)
266     {
267         assemblyManager = manager;
268     }
269
270     /**
271      * @return
272      */

273     public DestinationDeployerFactory
274     getDestinationDeployerFactory()
275     {
276         return destinationDeployerFactory;
277     }
278
279     /**
280      * @param factory
281      */

282     public void
283     connectDestinationDeployerFactory(DestinationDeployerFactory factory)
284     {
285         destinationDeployerFactory = factory;
286     }
287
288     /**
289      * @return
290      */

291     public ErrorManager
292     getErrorManager()
293     {
294         return errorManager;
295     }
296
297     /**
298      * @param manager
299      */

300     public void
301     connectErrorManager(ErrorManager manager)
302     {
303         errorManager = manager;
304     }
305     
306     public void
307     setWorkDir(String JavaDoc workDir)
308     {
309         this.workDir=workDir;
310     }
311     
312     public String JavaDoc
313     getWorkDir()
314     {
315         return workDir;
316     }
317     
318     public void
319     connectTemporaryFile(File JavaDoc file)
320     {
321         temporaryFiles.put(System.currentTimeMillis()+"",file);
322     }
323
324     public void
325     connectTemporaryFile(File JavaDoc file, String JavaDoc identifier)
326     {
327         temporaryFiles.put(identifier,file);
328     }
329     
330     public boolean
331     isAlreadyDownloaded(String JavaDoc identifier)
332     {
333         return temporaryFiles.containsKey(identifier);
334     }
335
336     public File JavaDoc
337     getTemporaryFile(String JavaDoc identifier)
338     {
339         return (File JavaDoc)temporaryFiles.get(identifier);
340     }
341     
342     public void
343     deleteAllTemporaryFiles()
344     {
345         if(temporaryFiles.size()<1)return;
346
347         for(Enumeration JavaDoc keys=temporaryFiles.keys();keys.hasMoreElements();){
348             String JavaDoc key=(String JavaDoc)keys.nextElement();
349             File JavaDoc f=(File JavaDoc)temporaryFiles.remove(key);
350             if(!f.delete())
351                 f.deleteOnExit();
352             }
353     }
354     
355     public void
356     connectOpenInputStream(InputStream JavaDoc isr)
357     {
358         openInputStreams.add(isr);
359     }
360     
361     public void
362     closeAllOpenInputStreams()
363     throws IOException JavaDoc
364     {
365        if(openInputStreams.size()>0)
366         for(InputStream JavaDoc r=(InputStream JavaDoc)openInputStreams.removeFirst();
367             openInputStreams.size()>0;
368             r=(InputStream JavaDoc)openInputStreams.removeFirst())
369                 r.close();
370     }
371     
372     public void
373     connectOpenReader(Reader JavaDoc reader)
374     {
375         openReaders.add(reader);
376     }
377     public void
378     closeAllOpenReaders()
379     throws IOException JavaDoc
380     {
381       if(openReaders.size()>0)
382         for(Reader JavaDoc r=(Reader JavaDoc)openReaders.removeFirst();
383             openReaders.size()>0;
384             r=(Reader JavaDoc)openReaders.removeFirst())
385                 r.close();
386     }
387
388     public void
389     connectOpenZipFile(ZipFile JavaDoc zf)
390     {
391         openZipFiles.add(zf);
392     }
393     
394     public void
395     closeAllOpenZipFile()
396     throws IOException JavaDoc
397     {
398       if(openZipFiles.size()>0)
399         for(ZipFile JavaDoc r=(ZipFile JavaDoc)openZipFiles.removeFirst();
400             openZipFiles.size()>0;
401             r=(ZipFile JavaDoc)openZipFiles.removeFirst())
402                 r.close();
403     }
404     public void
405     clearAllStream()
406     throws IOException JavaDoc
407     {
408         closeAllOpenReaders();
409         closeAllOpenInputStreams();
410         closeAllOpenZipFile();
411         deleteAllTemporaryFiles();
412     }
413 }
414
Popular Tags