java.module
Class Repository

java.lang.Object
  extended by java.module.Repository
Direct Known Subclasses:
BootstrapRepository, ExpandedJamRepository, LocalRepository, URLRepository

public abstract class Repository
extends Object

This class represents the repository in the module system.

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

Constructor Summary
protected Repository(Repository parent, String name, URL source, ModuleSystem system)
          Creates a repository instance.
protected Repository(String name, URL source, ModuleSystem system)
          Creates a repository instance.
 
Method Summary
 boolean equals(Object obj)
          Compares the specified object with this Repository for equality.
 List<ModuleDefinition> find(Query constraint)
          Find all matching module definitions that match the specified constraint.
 ModuleDefinition find(String name)
          Find a module definition.
 ModuleDefinition find(String name, VersionConstraint versionConstraint)
          Find a module definition.
 List<ModuleDefinition> findAll()
          Find all module definitions.
protected abstract  List<ModuleDefinition> findModuleDefinitions(Query constraint)
          Find all matching module definitions in the repository.
static Repository getBootstrapRepository()
          Returns the bootstrap repository for delegation.
 ModuleSystem getModuleSystem()
          Returns this Repository's ModuleSystem.
 String getName()
          Returns the name of this repository.
 Repository getParent()
          Returns the parent repository for delegation.
 URL getSourceLocation()
          Returns the source location of this repository.
static Repository getSystemRepository()
          Returns the system repository for delegation.
 int hashCode()
          Returns a hash code for this Repository.
 void initialize()
          Initializes the repository using the default configuration.
abstract  void initialize(Map<String,String> config)
          Initializes the repository instance using the supplied configuration.
abstract  ModuleArchiveInfo install(URL u)
          Install a module archive with the module definition into the repository.
abstract  boolean isActive()
          Returns whether or not the repository instance is active.
abstract  boolean isReadOnly()
          Returns whether or not this repository is read-only.
abstract  List<ModuleArchiveInfo> list()
          Returns an unmodifiable list of the installed module archives' information in the repository.
abstract  void reload()
          Reload the repository.
abstract  void shutdown()
          Shutdown the repository.
 void shutdownOnExit(boolean value)
          Enable or disable that the repository is shutdown when the module system terminates.
 String toString()
           
abstract  boolean uninstall(ModuleArchiveInfo m)
          Uninstall a module archive from the repository.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Repository

protected Repository(Repository parent,
                     String name,
                     URL source,
                     ModuleSystem system)
Creates a repository instance.

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

Parameters:
parent - the parent repository for delegation.
name - the repository name.
source - the source location.
Throws:
SecurityException - if a security manager exists and its checkPermission method denies access to create a new instance of repository.
NullPointerException - if parent is null, name is null, source is null, or system is null.
IllegalArgumentException - if a circularity is detected.

Repository

protected Repository(String name,
                     URL source,
                     ModuleSystem system)
Creates a repository instance.

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

Parameters:
name - the repository name.
source - the source location.
Throws:
SecurityException - if a security manager exists and its checkPermission method denies access to create a new instance of repository.
NullPointerException - if name is null, source is null, or system is null.
IllegalArgumentException - if a circularity is detected.
Method Detail

getName

public final String getName()
Returns the name of this repository.

Returns:
the name.

getSourceLocation

public final URL getSourceLocation()
Returns the source location of this repository.

Returns:
the source location.

getParent

public final Repository getParent()
Returns the parent repository for delegation. If this is the bootstrap repository, its parent is null.

Returns:
the parent Repository..

getModuleSystem

public final ModuleSystem getModuleSystem()
Returns this Repository's ModuleSystem.

Returns:
this repository's ModuleSystem

getBootstrapRepository

public static Repository getBootstrapRepository()
Returns the bootstrap repository for delegation. This the repository provided by the Java Runtime.


getSystemRepository

public static Repository getSystemRepository()
Returns the system repository for delegation. This is the default delegation parent for new Repository instances.


initialize

public void initialize()
                throws IOException
Initializes the repository using the default configuration.

Throws:
IOException - if an I/O error occurs.
IllegalStateException - if the repository instance has been initialized or has been shutdown.

initialize

public abstract void initialize(Map<String,String> config)
                         throws IOException
Initializes the repository instance using the supplied configuration. Configuration properties are described in the class description.

This method will not modify config or save a reference to it, but may save a clone.

Parameters:
config - - config used to initialize the repository instance.
Throws:
IOException - if an I/O error occurs.
IllegalStateException - if the repository instance has been initialized or has been shutdown.
NullPointerException - if config is null.

shutdown

public abstract void shutdown()
                       throws IOException
Shutdown the repository. If a security manager is present, this method calls the security manager's checkPermission method with a ModuleSystemPermission("shutdownRepository") permission to ensure it's ok to shutdown a repository.

Throws:
SecurityException - if a security manager exists and its checkPermission method denies access to shutdown the repository.
IOException - if an I/O error occurs.
IllegalStateException - if the repository instance has not been initialized or has been shutdown.

shutdownOnExit

public void shutdownOnExit(boolean value)
Enable or disable that the repository is shutdown when the module system terminates. Shutdown will be attempted only during the normal termination of the virtual machine, as defined by the Java Language Specification. By default, shutdown on exit is disabled. If a security manager is present, this method calls the security manager's checkPermission method with a ModuleSystemPermission("shutdownRepository") permission to ensure it's ok to shutdown a repository.

Parameters:
value - indicating enabling or disabling of shutdown.
Throws:
SecurityException - if a security manager exists and its checkPermission method denies access to shutdown the repository.

isActive

public abstract boolean isActive()
Returns whether or not the repository instance is active.

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

Returns:
true if this repository instance is active.

isReadOnly

public abstract boolean isReadOnly()
Returns whether or not this repository is read-only.

Returns:
true if this repository is read-only.

find

public final ModuleDefinition find(String name)
Find a module definition. Equivalent to:
      find(moduleName, VersionConstraint.DEFAULT);
 
If this repository instance has not been initialized when this method is called, it will be initialized automatically by calling the initialize method with no argument.

Parameters:
name - the module definition's name.
Returns:
the module definition or null if not found. If more than one module definition matches the specified name, the latest version is returned.
Throws:
IllegalStateException - if the repository instance has been shutdown.

find

public final ModuleDefinition find(String name,
                                   VersionConstraint versionConstraint)
Find a module definition. If this repository instance has not been initialized when this method is called, it will be initialized automatically by calling the initialize method with no argument.

Parameters:
name - the module definition's name.
versionConstraint - the version constraint.
Returns:
the module definition or null if not found. If more than one module definition matches the specified name and version constraint, the latest version is returned.
Throws:
IllegalStateException - if the repository instance has been shutdown.

findAll

public final List<ModuleDefinition> findAll()
Find all module definitions. Equivalent to:
      find(Query.ANY);
 
If this repository instance has not been initialized when this method is called, it will be initialized automatically by calling the initialize method with no argument.

Returns:
the result list.
Throws:
IllegalStateException - if the repository instance has been shutdown.

find

public final List<ModuleDefinition> find(Query constraint)
Find all matching module definitions that match the specified constraint. If this repository instance has not been initialized when this method is called, it will be initialized automatically by calling the initialize method with no argument.

Parameters:
constraint - the constraint.
Returns:
the result list.
Throws:
IllegalStateException - if the repository instance has been shutdown.

findModuleDefinitions

protected abstract List<ModuleDefinition> findModuleDefinitions(Query constraint)
Find all matching module definitions in the repository. This method should be overridden by repository implementations for finding matching module definitions, and will be invoked by the find method after checking the parent repository for the requested module definitions.

If this repository instance has not been initialized when this method is called, it will be initialized automatically by calling the initialize method with no argument.

Parameters:
constraint - the constraint.
Returns:
the collection of matching module definitions.
Throws:
IllegalStateException - if the repository instance has not been initialized or has been shutdown.

list

public abstract List<ModuleArchiveInfo> list()
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.

Returns:
an unmodifiable list of the installed module archives' information.
Throws:
SecurityException - if a security manager exists and its checkPermission method denies access to return the the information of the installed module archives.
IllegalStateException - if the repository instance has not been initialized or it has been shutdown.

install

public abstract ModuleArchiveInfo install(URL u)
                                   throws IOException
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.

Parameters:
u - the URL to the module archive.
Returns:
the ModuleArchiveInfo object that represents the installed module archive.
Throws:
SecurityException - if a security manager exists and its checkPermission method denies access to install a module archive in the repository.
IOException - if an error occurs while installing the module archive.
ModuleFormatException - if the module archive format is not supported by this implementation.
UnsupportedOperationException - if the repositoryis read-only.
IllegalStateException - if a module definition with the same name, version and platform binding is already installed, or if the repository instance has not been initialized or it has been shutdown.

uninstall

public abstract boolean uninstall(ModuleArchiveInfo m)
                           throws IOException
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.

Parameters:
m - the module archive to be uninstalled.
Returns:
true if the module archive is found and uninstalled, returns false otherwise.
Throws:
SecurityException - if a security manager exists and its checkPermission method denies access to uninstall the module archive in the repository.
IllegalStateException - if the module definition in the specified specified module archive is in use, or if the repository instance has not been initialized or it has been shutdown.
UnsupportedOperationException - if the repository is read-only.
IOException - If an error occurs while uninstalling the module archive.

reload

public abstract void reload()
                     throws IOException
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.

Throws:
SecurityException - if a security manager exists and its checkPermission method denies access to reload module definitions in the repository.
UnsupportedOperationException - if the repository does not support reload.
IllegalStateException - if a module definition is in use thus cannot be reloaded.
IOException - If an error occurs while reloading the module definitions.

equals

public final boolean equals(Object obj)
Compares the specified object with this Repository for equality. Returns true if and only if obj is the same object as this object.

Overrides:
equals in class Object
Parameters:
obj - the object to be compared for equality with this repository.
Returns:
true if the specified object is equal to this repository

hashCode

public final int hashCode()
Returns a hash code for this Repository.

Overrides:
hashCode in class Object
Returns:
a hash code value for this object.

toString

public String toString()
Overrides:
toString in class Object