KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > classloader > RemoteDirResource


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: RemoteDirResource.java,v 1.2 2005/03/24 10:51:25 slobodan Exp $
23  */

24
25
26
27
28
29 package com.lutris.classloader;
30
31 // lutris packages
32
// v. strahinja, 27 sep 2002
33
import java.io.FileNotFoundException JavaDoc;
34 import java.io.IOException JavaDoc;
35 import java.io.InputStream JavaDoc;
36 import java.net.MalformedURLException JavaDoc;
37 import java.net.URL JavaDoc;
38 import java.net.URLConnection JavaDoc;
39
40 import com.lutris.logging.LogChannel;
41
42 /**
43  * <P>A <CODE>Resource</CODE> that is a file on a remote machine in
44  * a specified directory. The directory is represented by a
45  * <CODE>ClassPathEntry</CODE>, and the filename is specified by a String.
46  *
47  * @author Kristen Pol, Lutris Technologies
48  * @version $Revision : 1.1 $
49  * @see com.lutris.classloader.MultiClassLoader
50  * @see com.lutris.classloader.ClassPathEntry
51  * @see com.lutris.classloader.Resource
52  * @see java.io.File
53  */

54 public class RemoteDirResource extends Resource {
55
56     // data members
57

58     private URL JavaDoc url = null;
59
60     // constructors
61

62     // FIXME: Test and change to protected and add javadoc. (kp)
63
private RemoteDirResource(String JavaDoc name, ClassPathEntry location,
64 // v. strahinja, 27 sep 2002
65
LogChannel loadLogChannel)
66 // Logger loadLogger)
67
throws FileNotFoundException JavaDoc {
68 // v. strahinja, 27 sep 2002
69
super(name, location, loadLogChannel);
70 // super(name, location, loadLogger);
71

72     // Get location's URL
73
URL JavaDoc locURL = location.getURL();
74         if (locURL == null) {
75             throw new FileNotFoundException JavaDoc( "The URL for location, "
76                                              + location + ", is null");
77         }
78
79     // Create a new URL from location's URL and resource name
80
try {
81         url = new URL JavaDoc(locURL.toString() + name);
82     } catch (MalformedURLException JavaDoc mue) {
83             throw new FileNotFoundException JavaDoc("The URL can not be created from the name "
84                                             + name + ", and location " + locURL
85                                             + ": " +mue.getMessage());
86     }
87
88     // Get the URLConnection so size and time can be determined
89
URLConnection JavaDoc connection;
90     try {
91         connection = url.openConnection();
92     } catch (IOException JavaDoc ioe) {
93             throw new FileNotFoundException JavaDoc("URL, " + url
94                                             + ", does not exist or can not be reached");
95         }
96         size = connection.getContentLength();
97         lastModifiedTime = connection.getLastModified();
98         //FIXME: Connection must be closed
99
}
100
101     // public methods
102

103     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
104     return url.openStream();
105     }
106
107     /**
108      * Get current last-modification time of resource. This is the
109      * time on the disk file the resource is associated with.
110      *
111      * @return the last-modified time of the permanent copy of the resource
112      * in milliseconds.
113      */

114     public long getCurrentLastModifiedTime() {
115         return -1; //FIXME: IMPLEMENT
116
}
117 }
118
Popular Tags