sun.module.repository
Class URLRepository

java.lang.Object
  extended by java.module.Repository
      extended by sun.module.repository.URLRepository

public final class URLRepository
extends Repository

This class represents a repository that loads module definitions from a codebase URL.

Information about the module definitions available from the codebase URL must be published in a repository metadata file. The contents of the file must follow the schema of the URL Repository metadata for the Java Module System.

{codebase}/repository-metadata.xml

When the repository is initialized, the repository metadata file (i.e. repository-metadata.xml) would be downloaded from the codebase URL.

In the repository metadata file, each module definition is described with a name, a version, a platform binding, and a path (relative to the codebase URL where the module file, the module archive, and/or the packed module archive are located). If no path and no platform binding is specified, the default path is "{name}/{version}". If the path is not specified and the module definition has platform binding, the default path is "{name}/{version}/{platform}-{arch}".

After the URL repository instance successfully downloads the repository metadata file, the module file of each module definition (i.e. MODULE.METADATA file) in the repository is downloaded based on the information in the repository metadata file:

{codebase}/{path}/MODULE.METADATA

If a module definition is platform-specific, its module file is downloaded if and only if the platform binding described in the repository metadata file matches the platform and the architecture of the system.

Module definitions are available for searches after the URL repository instance is initialized. If a module instance is instantiated from a module definition that has no platform binding, the module archive is downloaded by probing in the following order:

{codebase}/{path}/{name}-{version}.jam.pack.gz

{codebase}/{path}/{name}-{version}.jam

On the other hand, if a module instance is instantiated from a platform-specific module definition, the module archive is downloaded by probing in the following order:

{codebase}/{path}/{name}-{version}-{platform}-{arch}.jam.pack.gz

{codebase}/{path}/{name}-{version}-{platform}-{arch}.jam

To ensure the integrity of the separately-hosted module file is in sync with that in the module archive of the same module definition, they are compared bit-wise against each other after the module archive is downloaded.

Since:
1.7.0
Author:
Stanley M. Ho
See Also:
ModuleDefinition, ModuleSystemPermission, Query

Constructor Summary
URLRepository(Repository parent, String name, URL codebase)
          Creates a new URLRepository instance.
URLRepository(String name, URL codebase)
          Creates a new URLRepository instance using the Repository returned by the method getSystemRepository() as the parent repository.
 
Method Summary
 List<ModuleDefinition> findModuleDefinitions(Query constraint)
          Finds all matching module definitions in this repository.
 void initialize()
          Initializes the repository instance using the default configuration.
 void initialize(Map<String,String> config)
          Initializes the repository instance using the supplied configuration.
 ModuleArchiveInfo install(URL u)
          Install a module archive with the module definition into the repository.
 boolean isActive()
          Returns whether or not the repository instance is active.
 boolean isReadOnly()
          Always returns true, since the URLRepository cannot be modified via install, uninstall, etc..
 List<ModuleArchiveInfo> list()
          Returns an unmodifiable list of the installed module archives' information in the repository.
 void reload()
          Reload the repository.
 void shutdown()
          Shutdown the repository.
 boolean uninstall(ModuleArchiveInfo m)
          Uninstall a module archive from the repository.
 
Methods inherited from class java.module.Repository
equals, find, find, find, findAll, getBootstrapRepository, getModuleSystem, getName, getParent, getSourceLocation, getSystemRepository, hashCode, shutdownOnExit, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URLRepository

public URLRepository(Repository parent,
                     String name,
                     URL codebase)
Creates a new URLRepository instance.

If a security manager is present, this method calls the security manager's checkPermission method with a ModuleSystemPermission("createRepository") permission to ensure it's ok to create a repository.

Parameters:
parent - the parent repository for delegation.
name - the repository name.
codebase - the source location.
Throws:
SecurityException - if a security manager exists and its checkPermission method denies access to create a new instance of repository.

URLRepository

public URLRepository(String name,
                     URL codebase)
Creates a new URLRepository instance using the Repository returned by the method getSystemRepository() as the parent repository.

If a security manager is present, this method calls the security manager's checkPermission method with a ModuleSystemPermission("createRepository") permission to ensure it's ok to create a repository.

Parameters:
name - the repository name.
codebase - the source location.
Throws:
SecurityException - if a security manager exists and its checkPermission method denies access to create a new instance of repository.
Method Detail

initialize

public void initialize()
                throws IOException
Initializes the repository instance using the default configuration. The directory to which MODULE.METADATA and .jam files are downloaded are the metadata and modules subdirectories of a directory named URLRepository which is in the system's temporary directory. The directories are created if needed. IOExceptions may occur if they already exist and are not writeable, etc.

See Repository.initialize().

Overrides:
initialize in class Repository
Throws:
IOException - if an I/O error occurs.

initialize

public void initialize(Map<String,String> config)
                throws IOException
Initializes the repository instance using the supplied configuration. Loads configuration information from the given Map. Only examines entries that start with sun.module.repository.URLRepository.. These keys are checked for in the Map: In those cases, the directory must be created by the caller.

See Repository.initialize(Map).

Specified by:
initialize in class Repository
Parameters:
config - - config used to initialize the repository instance.
Throws:
IOException - if an I/O error occurs.

shutdown

public void shutdown()
              throws IOException
Shutdown the repository.

Specified by:
shutdown in class Repository
Throws:
IOException - if an I/O error occurs.
See Also:
Repository.shutdown().

findModuleDefinitions

public List<ModuleDefinition> findModuleDefinitions(Query constraint)
Finds all matching module definitions in this repository.

Specified by:
findModuleDefinitions in class Repository
Parameters:
constraint - the constraint.
Returns:
the collection of matching module definitions.

isReadOnly

public boolean isReadOnly()
Always returns true, since the URLRepository cannot be modified via install, uninstall, etc..

Specified by:
isReadOnly in class Repository
Returns:
true See Repository.initialize().

reload

public void reload()
            throws IOException
Description copied from class: Repository
Reload the repository. The behavior of this method depends on the implementation.

If a security manager is present, this method calls the security manager's checkPermission method with a ModuleSystemPermission("reloadRepository") permission to ensure it's ok to reload module definitions in a repository.

Specified by:
reload in class Repository
Throws:
IOException - If an error occurs while reloading the module definitions.

install

public ModuleArchiveInfo install(URL u)
                          throws IOException
Description copied from class: Repository
Install a module archive with the module definition into the repository.

If a security manager is present, this method calls the security manager's checkPermission method with a ModuleSystemPermission("installModuleArchive") permission to ensure it's ok to install a module archive into a repository.

Specified by:
install in class Repository
Parameters:
u - the URL to the module archive.
Returns:
the ModuleArchiveInfo object that represents the installed module archive.
Throws:
IOException - if an error occurs while installing the module archive.
ModuleFormatException - if the module archive format is not supported by this implementation.

uninstall

public boolean uninstall(ModuleArchiveInfo m)
                  throws IOException
Description copied from class: Repository
Uninstall a module archive from the repository.

If a security manager is present, this method calls the security manager's checkPermission method with a ModuleSystemPermission("uninstallModuleArchive") permission to ensure it's ok to uninstall a module archive from a repository.

Specified by:
uninstall in class Repository
Parameters:
m - the module archive to be uninstalled.
Returns:
true if the module archive is found and uninstalled, returns false otherwise.
Throws:
IOException - If an error occurs while uninstalling the module archive.

list

public List<ModuleArchiveInfo> list()
Description copied from class: Repository
Returns an unmodifiable list of the installed module archives' information in the repository. The list will contain a snapshot of the installed module archives in the repository at the time of the given invocation of this method.

If a security manager is present, this method calls the security manager's checkPermission method with a ModuleSystemPermission("listModuleArchive") permission to ensure it's ok to return the information of the installed module archives in a repository.

Specified by:
list in class Repository
Returns:
an unmodifiable list of the installed module archives' information.

isActive

public boolean isActive()
Description copied from class: Repository
Returns whether or not the repository instance is active.

A repository instance is active if it has been initialized but has not been shutdown.

Specified by:
isActive in class Repository
Returns:
true if this repository instance is active.