blob: 452aebcaa7ba037b1f0eb79b7fb28bac2e4bb2bf [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
19import java.net.URL;
20
21/**
22 * <p>
23 * This interface represents the <tt>ModuleLoader</tt>'s policy for creating
24 * <tt>URL</tt> for resource loading and security purposes. Java requires the
25 * use of <tt>URL</tt>s for resource loading and security. For resource loading,
26 * <tt>URL</tt>s are returned for requested resources. Subsequently, the resource
27 * <tt>URL</tt> is used to create an input stream for reading the resources
28 * bytes. With respect to security, <tt>URL</tt>s are used when defining a
29 * class in order to determine where the code came from, this concept is called
30 * a <tt>CodeSource</tt>. This approach enables Java to assign permissions to
31 * code that originates from particular locations.
32 * </p>
33 * <p>
34 * The <tt>ModuleManager</tt> requires a concrete implementation of this
35 * interface in order to function. Whenever the <tt>ModuleManager</tt> requires
36 * a <tt>URL</tt> for either resource loading or security, it delegates to
37 * the policy implementation. A default implementation is provided,
38 * called <a href="DefaultURLPolicy.html"><tt>DefaultURLPolicy</tt></a>, but
39 * it only supports resource loading, not security.
40 * </p>
Richard S. Hall5a031592005-08-19 19:53:58 +000041 * @see org.apache.felix.moduleloader.ModuleManager
42 * @see org.apache.felix.moduleloader.DefaultURLPolicy
Richard S. Hall930fecc2005-08-16 18:33:34 +000043**/
44public interface URLPolicy
45{
46 /**
47 * <p>
48 * This method should return a <tt>URL</tt> that represents the
49 * location from which the module originated. This <tt>URL</tt>
50 * can be used when assigning permissions to the module, such as
51 * is done in the Java permissions policy file.
52 * </p>
53 * @param mgr the <tt>ModuleManager</tt> of the module.
54 * @param module the module for which the <tt>URL</tt> is to be created.
55 * @return an <tt>URL</tt> to associate with the module.
56 **/
57 public URL createCodeSourceURL(ModuleManager mgr, Module module);
58
59 /**
60 * <p>
61 * This method should return a <tt>URL</tt> that is suitable
62 * for accessing the bytes of the specified resource. It must be possible
63 * open a connection to this <tt>URL</tt>, which may require that
64 * the implementer of this method also introduce a custom
65 * <tt>java.net.URLStreamHander</tt> when creating the <tt>URL</tt>.
66 * </p>
67 * @param mgr the <tt>ModuleManager</tt> of the module.
68 * @param module the module for which the resource is being loaded.
69 * @param rsIdx the index of the <tt>ResourceSource</tt> containing the resource.
70 * @param name the name of the resource being loaded.
71 * @return an <tt>URL</tt> for retrieving the resource.
72 **/
73 public URL createResourceURL(ModuleManager mgr, Module module, int rsIdx, String name);
74}