KickJava   Java API By Example, From Geeks To Geeks.

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


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.util;
27
28
29 /**
30  * The link deployer provide an URL on a ressource
31  *
32  * @author <a HREF="mailto:briclet@lifl.fr">Briclet Frédéric</a>
33  *
34  * @version 0.1
35  */

36 public class LinkDeployer
37        extends LinkDeployerContext
38     {
39     // ==================================================================
40
//
41
// Internal state.
42
//
43
// ==================================================================
44
//temporary file to store the remote ressource
45
private java.io.File JavaDoc tmpFile;
46     // ==================================================================
47
//
48
// Constructors.
49
//
50
// ==================================================================
51
// ==================================================================
52
//
53
// Internal methods.
54
//
55
// ==================================================================
56
private String JavaDoc
57     getValeur()
58     {
59         if(getLink().getHref()!=null)
60             return getLink().getHref().trim();
61         else return getLink().getValue().trim();
62     }
63     
64     private java.io.InputStream JavaDoc
65     getInputStreamInternal()
66     throws java.io.IOException JavaDoc
67     {
68         //The archive is in the current aar
69
if(getValeur().indexOf(":")==-1)
70              return
71                 getRootDeployerContext()
72                 .getZipEntryRetriever()
73                 .getZipEntryISIgnoringDelimiterType(getLink().getHref());
74         
75         java.net.URL JavaDoc url=new java.net.URL JavaDoc(getValeur());
76         
77
78         
79         //The required file is a local file we don't copy it
80
if(getValeur().startsWith("file:"))
81             return url.openStream();
82
83
84        //file is already prensent in the deployer
85
if(tmpFile!=null)
86         return new java.io.FileInputStream JavaDoc(tmpFile);
87
88        //File was already downloaded by an another deployer
89
if(getRootDeployerContext().isAlreadyDownloaded(getValeur()))
90        {
91             tmpFile=getRootDeployerContext().getTemporaryFile(getValeur());
92             return new java.io.FileInputStream JavaDoc(tmpFile);
93        }
94             
95         //file was not yet downloaded
96
tmpFile = java.io.File.createTempFile(
97              /* the url.getFile() value contains too much special characters
98                  like ~, ?, #, etc.
99                  so we change
100                      url.getFile()
101                  into an explicit filename construction
102                      OpenCCM_<the file without its location>_<time in ms>
103                  */

104                  "OpenCCM_tmp_"
105                  +url.getPath().substring(
106                      url.getPath().lastIndexOf('/')+1)
107                  +"_"
108               ,System.currentTimeMillis()+"");
109
110         java.io.FileOutputStream JavaDoc fos=new java.io.FileOutputStream JavaDoc(tmpFile);
111         java.io.InputStream JavaDoc is=url.openStream();
112         byte [] buff=new byte[32000];
113         int readed=is.read(buff,0,32000);
114         while(readed>0)
115         {
116              fos.write(buff,0,readed);
117              readed=is.read(buff,0,32000);
118         }
119         fos.close();
120         getRootDeployerContext().connectTemporaryFile(tmpFile,getValeur());
121         return new java.io.FileInputStream JavaDoc(tmpFile);
122     }
123     // ==================================================================
124
//
125
// Public methods.
126
//
127
// ==================================================================
128
/**
129      * Return the stringified URL to the ressource.
130      */

131     public String JavaDoc
132     getReference()
133     {
134         return getValeur();
135     }
136
137
138
139     public java.io.InputStream JavaDoc
140     getInputStream()
141     throws java.io.IOException JavaDoc
142     {
143         java.io.InputStream JavaDoc is=getInputStreamInternal();
144         getRootDeployerContext().connectOpenInputStream(is);
145         return is;
146     }
147     
148
149     
150
151 }
152
Popular Tags