KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > kernel > classloader > DirectoryResourceHandle


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.kernel.classloader;
18
19 import java.io.IOException JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.File JavaDoc;
22 import java.io.FileInputStream JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import java.security.cert.Certificate JavaDoc;
26 import java.util.jar.Attributes JavaDoc;
27 import java.util.jar.Manifest JavaDoc;
28
29 /**
30  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
31  */

32 public class DirectoryResourceHandle extends AbstractResourceHandle {
33     private final String JavaDoc name;
34     private final File JavaDoc file;
35     private final Manifest JavaDoc manifest;
36     private final URL JavaDoc url;
37     private final URL JavaDoc codeSource;
38
39     public DirectoryResourceHandle(String JavaDoc name, File JavaDoc file, File JavaDoc codeSource, Manifest JavaDoc manifest) throws MalformedURLException JavaDoc {
40         this.name = name;
41         this.file = file;
42         this.codeSource = codeSource.toURL();
43         this.manifest = manifest;
44         url = file.toURL();
45     }
46
47     public String JavaDoc getName() {
48         return name;
49     }
50
51     public URL JavaDoc getUrl() {
52         return url;
53     }
54
55     public URL JavaDoc getCodeSourceUrl() {
56         return codeSource;
57     }
58
59     public boolean isDirectory() {
60         return file.isDirectory();
61     }
62
63     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
64         if (file.isDirectory()) {
65             return new IoUtil.EmptyInputStream();
66         }
67         return new FileInputStream JavaDoc(file);
68     }
69
70     public int getContentLength() {
71         if (file.isDirectory() || file.length() > Integer.MAX_VALUE) {
72             return -1;
73         } else {
74             return (int) file.length();
75         }
76     }
77
78     public Manifest JavaDoc getManifest() throws IOException JavaDoc {
79         return manifest;
80     }
81
82     public Attributes JavaDoc getAttributes() throws IOException JavaDoc {
83         if (manifest == null) {
84             return null;
85         }
86         return manifest.getAttributes(getName());
87     }
88
89     /**
90      * Always return null. This could be implementd by verifing the signatures
91      * in the manifest file against the actual file, but we don't need this right now.
92      * @return null
93      */

94     public Certificate JavaDoc[] getCertificates() {
95         return null;
96     }
97 }
98
Popular Tags