uk.ac.cam.cl.ijam
Class Repository

java.lang.Object
  extended by uk.ac.cam.cl.ijam.Repository

 class Repository
extends java.lang.Object

Repository contains module definitions installed in it, and their module instances. At the moment, we are using modeling the system with a single (bootstrap) repository.


Field Summary
(package private) static Repository bootstrap_r
           
private  java.util.Map<java.lang.String,ModuleDefinition> mds
           
private  java.util.Map<ModuleDefinition,java.util.Map<ImportDependency,Module>> mis
           
private  java.lang.String name
           
private  Repository parent
           
 
Constructor Summary
private Repository()
          Only used for the bootstrap_r.
 
Method Summary
private  ImportDependency adjustImportDependency(ImportDependency dep, ModuleFile.Repl repl)
          This function adjusts the import dependency's type according to the preferences in both the importing and the imported module definition.
private  Repository findOwner(java.lang.String mn)
          This function finds the repository, which has a module definition with name mn installed.
private  java.util.Map<Module,java.util.Map<java.lang.String,java.lang.String>> getImportInstances(ModuleDefinition md)
          This function gets the module instances of module definitions that the specified module definition depends on.
(package private)  Module getInstance(ModuleDefinition md)
          This function gets an instance of a given module definition assuming it has the default import dependency, i.e.
private  Module getInstance(ModuleDefinition md, ImportDependency dep)
          This function gets an instance of a given module definition with respect to its (also specified) import dependency.
(package private)  Module getInstance(java.lang.String mn)
          This function gets a module instance of a module definition with the specified module name.
(package private)  void install(ModuleDefinition md)
          Installs a module definition, making it findable.
(package private)  void uninstall(ModuleDefinition md)
          Uninstalls a module definition, making it non-findable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bootstrap_r

static final Repository bootstrap_r

parent

private final Repository parent

name

private final java.lang.String name

mds

private final java.util.Map<java.lang.String,ModuleDefinition> mds

mis

private final java.util.Map<ModuleDefinition,java.util.Map<ImportDependency,Module>> mis
Constructor Detail

Repository

private Repository()
Only used for the bootstrap_r. Currently, creating child repositories is not supported.

Method Detail

install

void install(ModuleDefinition md)
Installs a module definition, making it findable.

Parameters:
md - Module definition to install.

uninstall

void uninstall(ModuleDefinition md)
Uninstalls a module definition, making it non-findable.

Parameters:
md - Module definition to uninstall.

getInstance

Module getInstance(java.lang.String mn)
This function gets a module instance of a module definition with the specified module name. This function simply locates which repository holds a module definition with the specified name, gets that definition, then calls the same-named function to get an instance.

Parameters:
mn - Name of a module definition to get an instance of.
Returns:
Module instance of module definition with name mn.
See Also:
getInstance(ModuleDefinition)

getInstance

Module getInstance(ModuleDefinition md)
This function gets an instance of a given module definition assuming it has the default import dependency, i.e. its module instance is shared. The function also assumes that the specified module definition is installed in this Repository.

Parameters:
md - Module definition to get an instance of.
Returns:
Module instance of md.
See Also:
getInstance(ModuleDefinition, ImportDependency)

getInstance

private Module getInstance(ModuleDefinition md,
                           ImportDependency dep)

This function gets an instance of a given module definition with respect to its (also specified) import dependency. The function also assumes that this Repository has the specified module definition installed. If a module instance has already been created with the given parameters, that module instance will be returned. Otherwise, the function first gets instances of the module definitions this module definition depends on, links all module instances together, and returns the top one.

Deciding whether to create a new module instance or not is not visible in this function. It is done via specifying the hashCode function of the ImportDependency class. Basically, if the mapping for that hash code already exists, it will get the existing mapping, otherwise it will create a new instance and map it in.

Deciding the final type of the import dependency is determined by the adjustImportDependency function.

Parameters:
md - Module definition to get an instance of.
dep - Import dependency for md.
Returns:
Module instance of md.
See Also:
getImportInstances(ModuleDefinition), adjustImportDependency(ImportDependency,ModuleFile.Repl), ImportDependency

getImportInstances

private java.util.Map<Module,java.util.Map<java.lang.String,java.lang.String>> getImportInstances(ModuleDefinition md)
This function gets the module instances of module definitions that the specified module definition depends on. Module instance is always stored in the repository, which holds the corresponding module definition. Each import is also tagged with the class renaming map specified in the module file. Note that the function is only called if the required module instance of the given module definition does not already exist.

Parameters:
md - The module definition.
Returns:
List of module instances of imported module definitions.
See Also:
getInstance(ModuleDefinition, ImportDependency), findOwner(String)

findOwner

private Repository findOwner(java.lang.String mn)
This function finds the repository, which has a module definition with name mn installed. The search performs a depth-first search, not a reverse depth-first search as done in the Java Module System, on the repository hierarchy.

Parameters:
mn - The name of the module definition.
Returns:
The repository found.

adjustImportDependency

private ImportDependency adjustImportDependency(ImportDependency dep,
                                                ModuleFile.Repl repl)

This function adjusts the import dependency's type according to the preferences in both the importing and the imported module definition.

If the imported superpackage's replication modifier is SINGLETON, then the final import dependency is "shared". If it is REPLICATION instead, and the import dependency is of the default type, then the final import dependency is of the "own" type. Otherwise, the import dependency remains unchanged.

The function also clones the import dependency object. This is important, because the independence of an imported module instance specified with "own" depends on uniqueness of the associated import dependency.

Parameters:
dep - Import dependency of the importing module definition.
repl - Replication modifier of the imported module definition.