View Javadoc

1   /**
2    *
3    * Copyright 2005 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  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;
20  import java.io.InputStream;
21  import java.io.IOException;
22  import java.util.jar.Manifest;
23  import java.util.jar.Attributes;
24  import java.security.cert.Certificate;
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: 410741 $ $Date: 2006-05-31 21:35:48 -0700 (Wed, 31 May 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 getName();
44  
45      /**
46       * Returns the URL of the resource.
47       */
48      URL 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 getCodeSourceUrl();
60  
61      /**
62       * Returns and InputStream for reading this resource data.
63       */
64      InputStream getInputStream() throws IOException;
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;
75  
76      /**
77       * Returns the Manifest of the JAR file from which this resource
78       * was loaded, or null if none.
79       */
80      Manifest getManifest() throws IOException;
81  
82      /**
83       * Return the Certificates of the resource, or null if none.
84       */
85      Certificate[] getCertificates();
86  
87      /**
88       * Return the Attributes of the resource, or null if none.
89       */
90      Attributes getAttributes() throws IOException;
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  }