KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > descriptor > componentassembly > ccm > deployer > util > FileinarchiveDeployer


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
27
28 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.util;
29
30 //Import all the packages required
31
import org.objectweb.openccm.descriptor.ZipEntryRetriever;
32 import java.io.InputStreamReader JavaDoc;
33 /**
34  *
35  * Fileinarchive is used to read xml file information in the archive.
36  *
37  * @author <a HREF="mailto:Frederic.Briclet@lifl.fr">Briclet Frederic</a>
38  *
39  * @version 0.1
40  */

41 public class FileinarchiveDeployer
42        extends FileinarchiveDeployerContext
43     {
44
45     // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50
private ZipEntryRetriever zer;
51     // ==================================================================
52
//
53
// Internal methods.
54
//
55
// ==================================================================
56

57     // ==================================================================
58
//
59
// Constructor.
60
//
61
// ==================================================================
62

63     // ==================================================================
64
//
65
// Public methods.
66
//
67
// ==================================================================
68

69     /**
70      * Retrieve a reader on the file denote by this fileinarchive
71      * element
72      */

73     public java.io.InputStreamReader JavaDoc
74     getInputStreamReader()
75     throws java.io.IOException JavaDoc
76     {
77         InputStreamReader JavaDoc isr=new InputStreamReader JavaDoc(getInputStream());
78         getRootDeployerContext().connectOpenReader(isr);
79         return isr;
80     }
81     
82     /**
83      * Retrieve a inputstream on the file denote by this fileinarchive
84      * element.
85      */

86     public java.io.InputStream JavaDoc
87     getInputStream()
88     throws java.io.IOException JavaDoc
89     {
90         if(getLinkDeployer()!=null)
91             return getLinkDeployer().getInputStream();
92         return getZipEntryRetriever()
93                 .getZipEntryISIgnoringDelimiterType(getFileinarchive().getName());
94     }
95     
96     /**
97      * getInnerArchive return a ZipEntry wrapper on a zip entry. The considered
98      * entry is saw as a zip file.
99      * @return A ZipEntryRetriever plug on the denote archive in archive
100      * @throws Exception if a problem occured
101      */

102     public ZipEntryRetriever
103     getInnerArchive()
104     throws Exception JavaDoc
105     {
106         if(zer==null){
107             zer=new ZipEntryRetriever(getInputStream());
108             zer.connectStreamManager(getRootDeployerContext());
109         }
110
111         return zer;
112     }
113     /**
114      * Start a specific Http server in charge to upload the specific
115      * file in the archive.
116      * The server will process only one request. This server is started
117      * in another thread.
118      * @return The stringified URL to use to download the file
119      * @throws java.io.IOException if a I/O problem occured
120      */

121     public String JavaDoc
122     startHttpServer()
123     throws java.io.IOException JavaDoc
124     {
125                
126         (new Thread JavaDoc
127             (new org.objectweb.openccm.deploytool.MicroServerHttp
128                 (getServerSocket(),
129                  getInputStream(),
130                  getFileinarchive().getName().trim()))).start();
131         return
132             "http://" +
133             java.net.InetAddress.getLocalHost().getHostAddress() + ':' +
134             getServerSocket().getLocalPort() + '/' +
135             getFileinarchive().getName().trim();
136     }
137
138     /**
139      * Provides the ressource
140      */

141      public String JavaDoc
142      provideRessource()
143      throws java.io.IOException JavaDoc
144      {
145         if(getLinkDeployer()!=null)
146             return getLinkDeployer().getReference();
147         else return startHttpServer();
148      }
149
150 }
151
Popular Tags