KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.URL JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.util.jar.Manifest JavaDoc;
23 import java.util.jar.Attributes JavaDoc;
24 import java.security.cert.Certificate JavaDoc;
25
26 /**
27  * This is a handle (a connection) to some resource, which may
28  * be a class, native library, text file, image, etc. Handles are returned
29  * by a ResourceFinder. A resource handle allows easy access to the resource data
30  * (using methods {@link #getInputStream} or {@link #getBytes}) as well as
31  * access resource metadata, such as attributes, certificates, etc.
32  * <p/>
33  * As soon as the handle is no longer in use, it should be explicitly
34  * {@link #close}d, similarly to I/O streams.
35  *
36  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
37  */

38 public interface ResourceHandle {
39     /**
40      * Return the name of the resource. The name is a "/"-separated path
41      * name that identifies the resource.
42      */

43     String JavaDoc getName();
44
45     /**
46      * Returns the URL of the resource.
47      */

48     URL JavaDoc getUrl();
49
50     /**
51      * Does this resource refer to a directory. Directory resources are commly used
52      * as the basis for a URL in client application. A directory resource has 0 bytes for it's content.
53      */

54     boolean isDirectory();
55
56     /**
57      * Returns the CodeSource URL for the class or resource.
58      */

59     URL JavaDoc getCodeSourceUrl();
60
61     /**
62      * Returns and InputStream for reading this resource data.
63      */

64     InputStream JavaDoc getInputStream() throws IOException JavaDoc;
65
66     /**
67      * Returns the length of this resource data, or -1 if unknown.
68      */

69     int getContentLength();
70
71     /**
72      * Returns this resource data as an array of bytes.
73      */

74     byte[] getBytes() throws IOException JavaDoc;
75
76     /**
77      * Returns the Manifest of the JAR file from which this resource
78      * was loaded, or null if none.
79      */

80     Manifest JavaDoc getManifest() throws IOException JavaDoc;
81
82     /**
83      * Return the Certificates of the resource, or null if none.
84      */

85     Certificate JavaDoc[] getCertificates();
86
87     /**
88      * Return the Attributes of the resource, or null if none.
89      */

90     Attributes JavaDoc getAttributes() throws IOException JavaDoc;
91
92     /**
93      * Closes a connection to the resource indentified by this handle. Releases
94      * any I/O objects associated with the handle.
95      */

96     void close();
97 }
98
Popular Tags