KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ungoverned > moduleloader > ResourceSource


1 /*
2  * ModuleLoader - A generic, policy-driven class loader.
3  * Copyright (c) 2004, Richard S. Hall
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of the ungoverned.org nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * Contact: Richard S. Hall (heavy@ungoverned.org)
33  * Contributor(s):
34  *
35 **/

36 package org.ungoverned.moduleloader;
37
38 /**
39  * <p>
40  * This interface represents a source for obtaining resources for a
41  * given module via the module's class loader. A resource source is used
42  * for retrieving both classes and resources; at this level, classes are
43  * treated in an identical manner as an ordinary resource. Resource sources
44  * are completely arbitrary and implementations may load resources from a JAR
45  * file, the network, a database, or anywhere.
46  * </p>
47  * <p>
48  * All resource sources are initialized before first usage via a call
49  * to the <a HREF="#open()"><tt>ResourceSource.open()</tt></a> method and
50  * are also deinitialized via a call to
51  * <a HREF="#open()"><tt>ResourceSource.close()</tt></a>. Resource sources
52  * should be implemented such that they can be opened, closed, and then
53  * re-opened.
54  * </p>
55  * @see org.ungoverned.moduleloader.Module
56  * @see org.ungoverned.moduleloader.ModuleClassLoader
57 **/

58 public interface ResourceSource
59 {
60     /**
61      * <p>
62      * This method initializes the resource source. It is called when
63      * the associated module is added to the <tt>ModuleManager</tt>. It
64      * is acceptable for implementations to ignore duplicate calls to this
65      * method if the resource source is already opened.
66      * </p>
67     **/

68     public void open();
69
70     /**
71      * <p>
72      * This method de-initializes the resource source. It is called when
73      * the associated module is removed from the <tt>ModuleManager</tt> or
74      * when the module is reset by the <tt>ModuleManager</tt>.
75      * </p>
76     **/

77     public void close();
78
79     /**
80      * <p>
81      * This method returns a boolean indicating whether the resource source
82      * contains the specified resource.
83      * </p>
84      * @param name the name of the resource whose existence is being checked.
85      * @param <tt>true</tt> if the resource source has the resource, <tt>false</tt>
86      * otherwise.
87      * @throws java.lang.IllegalStateException if the resource source has not
88      * been opened.
89     **/

90     public boolean hasResource(String JavaDoc name) throws IllegalStateException JavaDoc;
91
92     /**
93      * <p>
94      * This method returns a byte array of the specified resource's contents.
95      * </p>
96      * @param name the name of the resource to retrieve.
97      * @param a byte array of the resource's contents or <tt>null</tt>
98      * if the resource was not found.
99      * @throws java.lang.IllegalStateException if the resource source has not
100      * been opened.
101     **/

102     public byte[] getBytes(String JavaDoc name) throws IllegalStateException JavaDoc;
103 }
Popular Tags