org.ungoverned.moduleloader
Interface URLPolicy

All Known Implementing Classes:
DefaultURLPolicy, OSGiURLPolicy

public interface URLPolicy

This interface represents the ModuleLoader's policy for creating URL for resource loading and security purposes. Java requires the use of URLs for resource loading and security. For resource loading, URLs are returned for requested resources. Subsequently, the resource URL is used to create an input stream for reading the resources bytes. With respect to security, URLs are used when defining a class in order to determine where the code came from, this concept is called a CodeSource. This approach enables Java to assign permissions to code that originates from particular locations.

The ModuleManager requires a concrete implementation of this interface in order to function. Whenever the ModuleManager requires a URL for either resource loading or security, it delegates to the policy implementation. A default implementation is provided, called DefaultURLPolicy, but it only supports resource loading, not security.

See Also:
ModuleManager, DefaultURLPolicy

Method Summary
 java.net.URL createCodeSourceURL(ModuleManager mgr, Module module)
           This method should return a URL that represents the location from which the module originated.
 java.net.URL createResourceURL(ModuleManager mgr, Module module, int rsIdx, java.lang.String name)
           This method should return a URL that is suitable for accessing the bytes of the specified resource.
 

Method Detail

createCodeSourceURL

java.net.URL createCodeSourceURL(ModuleManager mgr,
                                 Module module)

This method should return a URL that represents the location from which the module originated. This URL can be used when assigning permissions to the module, such as is done in the Java permissions policy file.

Parameters:
mgr - the ModuleManager of the module.
module - the module for which the URL is to be created.
Returns:
an URL to associate with the module.

createResourceURL

java.net.URL createResourceURL(ModuleManager mgr,
                               Module module,
                               int rsIdx,
                               java.lang.String name)

This method should return a URL that is suitable for accessing the bytes of the specified resource. It must be possible open a connection to this URL, which may require that the implementer of this method also introduce a custom java.net.URLStreamHander when creating the URL.

Parameters:
mgr - the ModuleManager of the module.
module - the module for which the resource is being loaded.
rsIdx - the index of the ResourceSource containing the resource.
name - the name of the resource being loaded.
Returns:
an URL for retrieving the resource.