Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/lutris/classloader/RemoteDirResource.java


1   /*
2    * Enhydra Java Application Server Project
3    * 
4    * The contents of this file are subject to the Enhydra Public License
5    * Version 1.1 (the "License"); you may not use this file except in
6    * compliance with the License. You may obtain a copy of the License on
7    * the Enhydra web site ( http://www.enhydra.org/ ).
8    * 
9    * Software distributed under the License is distributed on an "AS IS"
10   * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
11   * the License for the specific terms governing rights and limitations
12   * under the License.
13   * 
14   * The Initial Developer of the Enhydra Application Server is Lutris
15   * Technologies, Inc. The Enhydra Application Server and portions created
16   * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17   * All Rights Reserved.
18   * 
19   * Contributor(s):
20   * 
21   * $Id: RemoteDirResource.java,v 1.13.12.1 2000/10/19 17:58:53 jasona Exp $
22   */
23  
24  
25  
26  
27  
28  package com.lutris.classloader;
29  
30  // lutris packages
31  import com.lutris.logging.LogChannel;
32  
33  // io packages
34  import java.net.URL;
35  import java.net.URLConnection;
36  
37  // io exceptions
38  import java.net.MalformedURLException;
39  
40  // io packages
41  import java.io.File;
42  import java.io.InputStream;
43  import java.io.FileInputStream;
44  
45  // io exceptions
46  import java.io.IOException;
47  import java.io.FileNotFoundException;
48  
49  /**
50   * <P>A <CODE>Resource</CODE> that is a file on a remote machine in 
51   * a specified directory.  The directory is represented by a 
52   * <CODE>ClassPathEntry</CODE>, and the filename is specified by a String.
53   *
54   * @author Kristen Pol, Lutris Technologies
55   * @version $Revision : 1.1 $
56   * @see com.lutris.classloader.MultiClassLoader
57   * @see com.lutris.classloader.ClassPathEntry
58   * @see com.lutris.classloader.Resource
59   * @see java.io.File
60   */
61  public class RemoteDirResource extends Resource {
62  
63      // data members
64  
65      private URL url = null;
66  
67      // constructors
68  
69      // FIXME: Test and change to protected and add javadoc. (kp)
70      private RemoteDirResource(String name, ClassPathEntry location,
71                                LogChannel loadLogChannel) 
72        throws FileNotFoundException {
73    super(name, location, loadLogChannel);
74    
75    // Get location's URL
76          URL locURL = location.getURL();
77          if (locURL == null) {
78              throw new FileNotFoundException( "The URL for location, "
79                                               + location + ", is null");
80          }
81  
82    // Create a new URL from location's URL and resource name
83    try {
84        url = new URL(locURL.toString() + name);
85    } catch (MalformedURLException mue) {
86              throw new FileNotFoundException("The URL can not be created from the name "
87                                              + name + ", and location " + locURL
88                                              + ": " +mue.getMessage());
89    }
90  
91    // Get the URLConnection so size and time can be determined
92    URLConnection connection;
93    try {
94        connection = url.openConnection();
95    } catch (IOException ioe) {
96              throw new FileNotFoundException("URL, " + url
97                                              + ", does not exist or can not be reached");
98          }
99          size = connection.getContentLength();
100         lastModifiedTime = connection.getLastModified();
101         //FIXME: Connection must be closed
102     }
103 
104     // public methods
105 
106     public InputStream getInputStream() throws IOException {
107   return url.openStream();
108     }
109 
110     /**
111      * Get current last-modification time of resource.  This is the
112      * time on the disk file the resource is associated with.
113      *
114      * @return the last-modified time of the permanent copy of the resource
115      * in milliseconds.
116      */
117     public long getCurrentLastModifiedTime() {
118         return -1; //FIXME: IMPLEMENT
119     }
120 }