KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.net.URL JavaDoc;
39
40 /**
41  * <p>
42  * This interface represents the <tt>ModuleLoader</tt>'s policy for creating
43  * <tt>URL</tt> for resource loading and security purposes. Java requires the
44  * use of <tt>URL</tt>s for resource loading and security. For resource loading,
45  * <tt>URL</tt>s are returned for requested resources. Subsequently, the resource
46  * <tt>URL</tt> is used to create an input stream for reading the resources
47  * bytes. With respect to security, <tt>URL</tt>s are used when defining a
48  * class in order to determine where the code came from, this concept is called
49  * a <tt>CodeSource</tt>. This approach enables Java to assign permissions to
50  * code that originates from particular locations.
51  * </p>
52  * <p>
53  * The <tt>ModuleManager</tt> requires a concrete implementation of this
54  * interface in order to function. Whenever the <tt>ModuleManager</tt> requires
55  * a <tt>URL</tt> for either resource loading or security, it delegates to
56  * the policy implementation. A default implementation is provided,
57  * called <a HREF="DefaultURLPolicy.html"><tt>DefaultURLPolicy</tt></a>, but
58  * it only supports resource loading, not security.
59  * </p>
60  * @see org.ungoverned.moduleloader.ModuleManager
61  * @see org.ungoverned.moduleloader.DefaultURLPolicy
62 **/

63 public interface URLPolicy
64 {
65     /**
66      * <p>
67      * This method should return a <tt>URL</tt> that represents the
68      * location from which the module originated. This <tt>URL</tt>
69      * can be used when assigning permissions to the module, such as
70      * is done in the Java permissions policy file.
71      * </p>
72      * @param mgr the <tt>ModuleManager</tt> of the module.
73      * @param module the module for which the <tt>URL</tt> is to be created.
74      * @return an <tt>URL</tt> to associate with the module.
75     **/

76     public URL JavaDoc createCodeSourceURL(ModuleManager mgr, Module module);
77
78     /**
79      * <p>
80      * This method should return a <tt>URL</tt> that is suitable
81      * for accessing the bytes of the specified resource. It must be possible
82      * open a connection to this <tt>URL</tt>, which may require that
83      * the implementer of this method also introduce a custom
84      * <tt>java.net.URLStreamHander</tt> when creating the <tt>URL</tt>.
85      * </p>
86      * @param mgr the <tt>ModuleManager</tt> of the module.
87      * @param module the module for which the resource is being loaded.
88      * @param rsIdx the index of the <tt>ResourceSource</tt> containing the resource.
89      * @param name the name of the resource being loaded.
90      * @return an <tt>URL</tt> for retrieving the resource.
91     **/

92     public URL JavaDoc createResourceURL(ModuleManager mgr, Module module, int rsIdx, String JavaDoc name);
93 }
Popular Tags