Qwylt

java.lang.module.spi
Class Configuration

java.lang.Object
  extended by java.lang.module.spi.Configuration
Direct Known Subclasses:
Configuration.Default

public abstract class Configuration
extends java.lang.Object

Module system configuration service. Configuration proceeds as follows:

The default implementation performs the following sequence:

Instantiating a ModuleRepository from a directory requires the presence of a repository.config file at the root of that directory. This file must be in the form of a properties file, with the following entries:

System property substitution is performed for all values containing embedded ${key} references. For example, the following configuration file will result in the instantiation of the repository defined in the specified subdirectory of the current user's home directory:

     repository.name=example
     module.system=Lyra
     search.sequence=root, ${user.home}/.java/modules, example
 

Each repository instantiated can load and register hosted framework types such as ModuleSystems, LifeCycle and Search listeners.

Since:
Feb 19, 2009
Author:
Bryan Atsatt

Nested Class Summary
static class Configuration.Default
          The default Configuration implementation.
 
Field Summary
static java.lang.String CONFIGURATION_CLASS_KEY
          The system property that may be used to override the default configuration class.
static java.lang.String HOST_ARCHIVE_KEY
          The archive attribute name that, if present, signifies that the archive contains framework types that should be registered at startup.
static java.lang.String REPOSITORY_PATH_KEY
          The system property defining the path to the system repository.
static java.lang.String ROOT_MODULE_NAME
          The name of the java root module that exports packages with the "java." prefix.
static java.lang.String ROOT_MODULE_PREFIX
          The prefix for any module that exports packages with the "java." prefix.
static java.lang.String ROOT_PACKAGE_PREFIX
          The java package prefix.
 
Constructor Summary
Configuration()
           
 
Method Summary
abstract  java.io.File deleteRepositoryConfiguration(java.io.File repositoryDir)
          Delete a repository configuration file.
 ModuleRepository findRepository(java.lang.String nameOrDirPath, java.io.File root)
          Get an existing repository or load one.
static Configuration getConfiguration()
          Get the configuration singleton.
abstract  ConnectionCoordinator getConnectionCoordinator()
          Returns the ConnectionCoordinator.
abstract  ModuleSystem getModuleSystem(ModuleInfo.Term... required)
          Returns the named module system.
 ModuleSystem getModuleSystem(java.lang.String id)
          Returns the named module system.
abstract  java.util.List<ModuleSystem> getModuleSystems()
          Returns a list of the available module systems.
abstract  java.lang.String[] getOSArchNames()
          Returns the value of the os.arch system property and any known aliases of it, with the value of the system property as the first element.
abstract  java.lang.String[] getOSNames()
          Returns the value of the os.name system property and any known aliases of it, with the value of the system property as the first element.
protected static java.lang.String[] getProperties(java.lang.String key, java.util.Properties config, java.lang.String configSource, boolean required)
          Get a property value as a comma separated list
protected static java.lang.String getProperty(java.lang.String key, java.util.Properties config)
          Get a property value.
protected static java.lang.String getProperty(java.lang.String key, java.util.Properties config, java.lang.String defaultValue)
          Get a property value.
protected static java.lang.String getProperty(java.lang.String key, java.util.Properties config, java.lang.String configSource, boolean required)
          Get a property value, or fail if not present.
abstract  java.util.List<ModuleRepository> getRepositories()
          Returns a list of all registered repositories.
abstract  ModuleRepository getRepository(java.lang.String repositoryName)
          Returns the named repository.
abstract  ModuleRepository getRepositoryFor(java.net.URI location)
          Returns the registered repository with the specified location.
abstract  ModuleArchive getRootArchive()
          Returns the root ModuleArchive, which is the sole exporter of packages with the "java." prefix.
abstract  Module getRootModule()
          Returns the root ClassSpace, which is the sole exporter of packages with the "java." prefix.
abstract  ModuleSystem getRootModuleSystem()
          Returns the root ModuleSystem.
abstract  ModuleRepository getRootRepository()
          Returns the root repository.
abstract  java.io.File getRootRepositoryDirectory()
          Get the root repository directory.
abstract  ModuleRepository getSystemRepository()
          Returns the system repository.
abstract  java.io.File getSystemRepositoryDirectory()
          Get the system repository directory.
abstract  void load()
          Load the configuration.
protected static java.util.Properties loadProperties(java.io.File propertiesFile)
          Load a properties file.
abstract  ModuleRepository loadRepository(java.io.File repositoryDir)
          Load a repository from a repository configuration file.
static void main(java.lang.String[] args)
          Print the configuration to System.out.
protected static java.lang.Object newInstance(java.lang.String className)
          Load and instantiate a class.
abstract  void register(ModuleRepository repository)
          Register a repository by location.
abstract  void registerModuleSystem(ModuleSystem moduleSystem)
          Register a module system.
abstract  java.io.File storeRepositoryConfiguration(java.io.File repositoryDir, java.lang.String repositoryName, java.lang.String moduleSystemID, java.lang.String... searchSequence)
          Store a repository configuration file.
abstract  void unregister(ModuleRepository repository)
          Unregister a repository by location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_MODULE_PREFIX

public static final java.lang.String ROOT_MODULE_PREFIX
The prefix for any module that exports packages with the "java." prefix.

See Also:
Constant Field Values

ROOT_MODULE_NAME

public static final java.lang.String ROOT_MODULE_NAME
The name of the java root module that exports packages with the "java." prefix.

See Also:
Constant Field Values

ROOT_PACKAGE_PREFIX

public static final java.lang.String ROOT_PACKAGE_PREFIX
The java package prefix.

See Also:
Constant Field Values

REPOSITORY_PATH_KEY

public static final java.lang.String REPOSITORY_PATH_KEY
The system property defining the path to the system repository.

See Also:
Constant Field Values

CONFIGURATION_CLASS_KEY

public static final java.lang.String CONFIGURATION_CLASS_KEY
The system property that may be used to override the default configuration class.


HOST_ARCHIVE_KEY

public static final java.lang.String HOST_ARCHIVE_KEY
The archive attribute name that, if present, signifies that the archive contains framework types that should be registered at startup.

See Also:
Constant Field Values
Constructor Detail

Configuration

public Configuration()
Method Detail

getConfiguration

public static Configuration getConfiguration()
Get the configuration singleton.

Returns:
The instance.

load

public abstract void load()
                   throws java.lang.Exception
Load the configuration.

Throws:
java.lang.Exception - if a failure occurs.

getRootRepositoryDirectory

public abstract java.io.File getRootRepositoryDirectory()
Get the root repository directory.

Returns:
The directory.

getSystemRepositoryDirectory

public abstract java.io.File getSystemRepositoryDirectory()
Get the system repository directory.

Returns:
The directory.

loadRepository

public abstract ModuleRepository loadRepository(java.io.File repositoryDir)
                                         throws java.lang.Exception
Load a repository from a repository configuration file.

Parameters:
repositoryDir - The repository directory
Returns:
The repository.
Throws:
java.lang.Exception - If a failure occurs.

findRepository

public ModuleRepository findRepository(java.lang.String nameOrDirPath,
                                       java.io.File root)
                                throws java.lang.Exception
Get an existing repository or load one.

Parameters:
nameOrDirPath - The name of an existing repository or the path to one to load.
root - The root directory to use if nameOrDirPath is a path and is relative.
Returns:
The repository.
Throws:
java.lang.Exception - If a failure occurs.

storeRepositoryConfiguration

public abstract java.io.File storeRepositoryConfiguration(java.io.File repositoryDir,
                                                          java.lang.String repositoryName,
                                                          java.lang.String moduleSystemID,
                                                          java.lang.String... searchSequence)
                                                   throws java.io.IOException
Store a repository configuration file.

Parameters:
repositoryDir - The directory in which to store the configuration.
repositoryName - The repository name.
moduleSystemID - The module system id.
searchSequence - The repository search sequence. Each element is either a path to a repository directory, or a repository name. The sequence must contain repositoryName.
Returns:
The stored configuration file.
Throws:
java.io.IOException - If a failure occurs.

deleteRepositoryConfiguration

public abstract java.io.File deleteRepositoryConfiguration(java.io.File repositoryDir)
                                                    throws java.io.IOException
Delete a repository configuration file.

Parameters:
repositoryDir - The repository directory.
Returns:
File the deleted file.
Throws:
java.io.IOException - If a failure occurs.

registerModuleSystem

public abstract void registerModuleSystem(ModuleSystem moduleSystem)
Register a module system.

Parameters:
moduleSystem - T

getRootModuleSystem

public abstract ModuleSystem getRootModuleSystem()
Returns the root ModuleSystem.

Returns:
The root ModuleSystem.

getModuleSystem

public ModuleSystem getModuleSystem(java.lang.String id)
Returns the named module system.

Parameters:
id - The id, in name[@ver] format.
Returns:
The ModuleSystem or null if not found.

getModuleSystem

public abstract ModuleSystem getModuleSystem(ModuleInfo.Term... required)
Returns the named module system.

Parameters:
required - The required module system terms. Each term must either exactly match one provided by a candidate module system or the names must match; exact match is checked first.
Returns:
The module system or null if not found.

getModuleSystems

public abstract java.util.List<ModuleSystem> getModuleSystems()
Returns a list of the available module systems.

Returns:
The available module systems.

register

public abstract void register(ModuleRepository repository)
Register a repository by location.

Parameters:
repository - The repository.
Throws:
java.lang.IllegalArgumentException - if repository name already registered.

unregister

public abstract void unregister(ModuleRepository repository)
Unregister a repository by location.

Parameters:
repository - The repository.

getRootRepository

public abstract ModuleRepository getRootRepository()
Returns the root repository.

Returns:
The root repository.

getSystemRepository

public abstract ModuleRepository getSystemRepository()
Returns the system repository.

Returns:
The system repository.

getRepository

public abstract ModuleRepository getRepository(java.lang.String repositoryName)
Returns the named repository.

Parameters:
repositoryName - The repository name.
Returns:
The repository or null if not found.

getRepositoryFor

public abstract ModuleRepository getRepositoryFor(java.net.URI location)
Returns the registered repository with the specified location.

Parameters:
location - The location.
Returns:
The repository or null if not found.

getRepositories

public abstract java.util.List<ModuleRepository> getRepositories()
Returns a list of all registered repositories.

Returns:
The list.

getRootArchive

public abstract ModuleArchive getRootArchive()
Returns the root ModuleArchive, which is the sole exporter of packages with the "java." prefix.

Returns:
The root ModuleArchive.

getRootModule

public abstract Module getRootModule()
Returns the root ClassSpace, which is the sole exporter of packages with the "java." prefix.

Returns:
The root ClassSpace.

getConnectionCoordinator

public abstract ConnectionCoordinator getConnectionCoordinator()
Returns the ConnectionCoordinator.

Returns:
The coordinator.

getOSNames

public abstract java.lang.String[] getOSNames()
Returns the value of the os.name system property and any known aliases of it, with the value of the system property as the first element.

Returns:
The names.

getOSArchNames

public abstract java.lang.String[] getOSArchNames()
Returns the value of the os.arch system property and any known aliases of it, with the value of the system property as the first element.

Returns:
The names.

main

public static void main(java.lang.String[] args)
Print the configuration to System.out.

Parameters:
args - Arguments (ignored).

getProperty

protected static java.lang.String getProperty(java.lang.String key,
                                              java.util.Properties config)
Get a property value.

Parameters:
key - The key.
config - The configuration properties.
Returns:
The value or null if not found.

getProperty

protected static java.lang.String getProperty(java.lang.String key,
                                              java.util.Properties config,
                                              java.lang.String configSource,
                                              boolean required)
Get a property value, or fail if not present.

Parameters:
key - The key.
config - The configuration properties.
configSource - The configuration source.
required - true if should fail if property not found.
Returns:
The value.
Throws:
java.lang.IllegalArgumentException - If property not found.

getProperties

protected static java.lang.String[] getProperties(java.lang.String key,
                                                  java.util.Properties config,
                                                  java.lang.String configSource,
                                                  boolean required)
Get a property value as a comma separated list

Parameters:
key - The key.
config - The configuration properties.
configSource - The configuration source.
required - true if should fail if property not found.
Returns:
The list.
Throws:
java.lang.IllegalArgumentException - If required and property not found.

newInstance

protected static java.lang.Object newInstance(java.lang.String className)
                                       throws java.lang.Exception
Load and instantiate a class.

Parameters:
className - The class name.
Returns:
The instance.
Throws:
java.lang.Exception - If a failure occurs.

getProperty

protected static java.lang.String getProperty(java.lang.String key,
                                              java.util.Properties config,
                                              java.lang.String defaultValue)
Get a property value.

Parameters:
key - The key.
config - The configuration properties.
defaultValue - The default value if property not found.
Returns:
The value or defaultValue if property not found.

loadProperties

protected static java.util.Properties loadProperties(java.io.File propertiesFile)
Load a properties file.

Parameters:
propertiesFile - The file.
Returns:
The properties instance.

Qwylt

Send comments or questions to Bryan Atsatt