blob: 78d1ee1848158faea4e20050cb20691d14fc2675 [file] [log] [blame]
Richard S. Hall930fecc2005-08-16 18:33:34 +00001/*
2 * Copyright 2005 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
Richard S. Hall5a031592005-08-19 19:53:58 +000017package org.apache.felix.moduleloader;
Richard S. Hall930fecc2005-08-16 18:33:34 +000018
19/**
20 * <p>
21 * This interface represents a source for obtaining resources for a
22 * given module via the module's class loader. A resource source is used
23 * for retrieving both classes and resources; at this level, classes are
24 * treated in an identical manner as an ordinary resource. Resource sources
25 * are completely arbitrary and implementations may load resources from a JAR
26 * file, the network, a database, or anywhere.
27 * </p>
28 * <p>
29 * All resource sources are initialized before first usage via a call
30 * to the <a href="#open()"><tt>ResourceSource.open()</tt></a> method and
31 * are also deinitialized via a call to
32 * <a href="#open()"><tt>ResourceSource.close()</tt></a>. Resource sources
33 * should be implemented such that they can be opened, closed, and then
34 * re-opened.
35 * </p>
Richard S. Hall5a031592005-08-19 19:53:58 +000036 * @see org.apache.felix.moduleloader.Module
37 * @see org.apache.felix.moduleloader.ModuleClassLoader
Richard S. Hall930fecc2005-08-16 18:33:34 +000038**/
39public interface ResourceSource
40{
41 /**
42 * <p>
43 * This method initializes the resource source. It is called when
44 * the associated module is added to the <tt>ModuleManager</tt>. It
45 * is acceptable for implementations to ignore duplicate calls to this
46 * method if the resource source is already opened.
47 * </p>
48 **/
49 public void open();
50
51 /**
52 * <p>
53 * This method de-initializes the resource source. It is called when
54 * the associated module is removed from the <tt>ModuleManager</tt> or
55 * when the module is reset by the <tt>ModuleManager</tt>.
56 * </p>
57 **/
58 public void close();
59
60 /**
61 * <p>
62 * This method returns a boolean indicating whether the resource source
63 * contains the specified resource.
64 * </p>
65 * @param name the name of the resource whose existence is being checked.
66 * @param <tt>true</tt> if the resource source has the resource, <tt>false</tt>
67 * otherwise.
68 * @throws java.lang.IllegalStateException if the resource source has not
69 * been opened.
70 **/
71 public boolean hasResource(String name) throws IllegalStateException;
72
73 /**
74 * <p>
75 * This method returns a byte array of the specified resource's contents.
76 * </p>
77 * @param name the name of the resource to retrieve.
78 * @param a byte array of the resource's contents or <tt>null</tt>
79 * if the resource was not found.
80 * @throws java.lang.IllegalStateException if the resource source has not
81 * been opened.
82 **/
83 public byte[] getBytes(String name) throws IllegalStateException;
84}