org.ungoverned.moduleloader
Class DefaultURLPolicy

java.lang.Object
  extended byorg.ungoverned.moduleloader.DefaultURLPolicy
All Implemented Interfaces:
URLPolicy

public class DefaultURLPolicy
extends java.lang.Object
implements URLPolicy

This class implements a simple URLPolicy that the ModuleManager uses if the application does not specify one. This implementation always returns null for CodeSource URLs, which means that security is simply ignored. For resource URLs, it returns an URL in the form of:

     module://<module-id>/<resource-path>
 

In order to properly handle the "module:" protocol, this policy also defines a custom java.net.URLStreamHandler that it assigns to each URL as it is created. This custom handler is used to return a custom java.net.URLConnection that will correctly parse the above URL and retrieve the associated resource bytes using methods from ModuleManager and Module.

See Also:
ModuleManager, Module, URLPolicy

Constructor Summary
DefaultURLPolicy()
           
 
Method Summary
 java.net.URL createCodeSourceURL(ModuleManager mgr, Module module)
           This method is a stub and always returns null.
 java.net.URL createResourceURL(ModuleManager mgr, Module module, int rsIdx, java.lang.String name)
           This method returns a URL that is suitable for accessing the bytes of the specified resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultURLPolicy

public DefaultURLPolicy()
Method Detail

createCodeSourceURL

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

This method is a stub and always returns null.

Specified by:
createCodeSourceURL in interface URLPolicy
Parameters:
mgr - the ModuleManager of the module.
module - the module for which the URL is to be created.
Returns:
null.

createResourceURL

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

This method returns a URL that is suitable for accessing the bytes of the specified resource.

Specified by:
createResourceURL in interface URLPolicy
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.