com.arsdigita.packaging
Class ConfigRegistry

java.lang.Object
  extended bycom.arsdigita.packaging.ConfigRegistry

public class ConfigRegistry
extends Object

The ConfigRegistry class maps between config classes (subclasses of AbstractConfig), and a location used for persisting the values in a config class. The ConfigRegistry also stores the set of configured packages for a particular CCM instance, and a list of URLs for parent configurations that are used for defaulting values not present in the local configuration. This mapping is maintained and extended by CCM developers through the use of an XML configuration file placed in the src tree for a particular package. If a particular package is configured, the ConfigRegistry class will look in the classpath for a registry configuration file named package-key.config, and parse the file according to the following specification:

 <?xml version="1.0" encoding="utf-8"?>
 <registry>
   ...
   <config class="CLASSNAME"
           storage="FILENAME"/>
   ...
 </registry>
 
The mappings stored by this ConfigRegistry will then be extended to include the classes and storage locations specified in the configuration file. These mappings are then used by the ConfigRegistry instance to load config objects.

Version:
$Revision: #14 $ $Date: 2004/04/07 $
Author:
Rafael H. Schloming <rhs@mit.edu>

Field Summary
static String versionId
           
 
Constructor Summary
ConfigRegistry()
          Invokes ConfigRegistry(URL) defaulting the URL to new File(System.getProperty("ccm.conf")).toURL().
ConfigRegistry(ClassLoader loader)
          Invokes ConfigRegistry(URL, ClassLoader) defaulting the URL to new File(System.getProperty("ccm.conf")).toURL().
ConfigRegistry(URL url)
          Invokes ConfigRegistry(URL, ClassLoader) defaulting the loader to the context class loader.
ConfigRegistry(URL url, ClassLoader loader)
          Constructs a new config registry that will resolve all locations relative to url, and use loader when searching the classpath for registry configuration files.
 
Method Summary
 List getContexts()
          Returns a list of config classes for this ConfigRegistry.
 List getPackages()
          Returns the list of configured packages for this ConfigRegistry.
 String getStorage(Class context)
          Returns the relative location used to store values for the given config class.
 void initialize(String key)
          This method is not supported API.
 boolean isConfigured(Class context)
          Returns true if this ConfigRegistry contains a mapping for context
 void load(ParameterContext ctx, ErrorList errs)
          Loads the given config object from the correct location based on its class.
 InputStream load(String resource)
          Searches through this ConfigRegistry and its parents for the given resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

ConfigRegistry

public ConfigRegistry(URL url,
                      ClassLoader loader)
Constructs a new config registry that will resolve all locations relative to url, and use loader when searching the classpath for registry configuration files.

Parameters:
url - The base url for registry locations.
loader - The ClassLoader to use for retrieving registry configuration files.

ConfigRegistry

public ConfigRegistry(URL url)
Invokes ConfigRegistry(URL, ClassLoader) defaulting the loader to the context class loader.

Parameters:
url - The base url for registry locations.
See Also:
Thread.getContextClassLoader()

ConfigRegistry

public ConfigRegistry(ClassLoader loader)
Invokes ConfigRegistry(URL, ClassLoader) defaulting the URL to new File(System.getProperty("ccm.conf")).toURL(). The value of the ccm.conf system property may or may not include a trailing slash.

Parameters:
loader - The ClassLoader to use when searching for registry configuration files.

ConfigRegistry

public ConfigRegistry()
Invokes ConfigRegistry(URL) defaulting the URL to new File(System.getProperty("ccm.conf")).toURL(). The value of the ccm.conf system property may or may not include a trailing slash.

Method Detail

initialize

public final void initialize(String key)
This method is not supported API.


getPackages

public List getPackages()
Returns the list of configured packages for this ConfigRegistry.

Returns:
A list of package keys represented as Strings.

getContexts

public List getContexts()
Returns a list of config classes for this ConfigRegistry.

Returns:
A list of Class objects.

getStorage

public String getStorage(Class context)
Returns the relative location used to store values for the given config class.

Parameters:
context - a subclass of AbstractConfig
Returns:
the relative storage location for context
Throws:
IllegalArgumentException - if this ConfigRegistry does not contain a mapping for context

isConfigured

public boolean isConfigured(Class context)
Returns true if this ConfigRegistry contains a mapping for context

Parameters:
context - a subclass of AbstractConfig
Returns:
true iff this ConfigRegistry contains a mapping for context

load

public void load(ParameterContext ctx,
                 ErrorList errs)
Loads the given config object from the correct location based on its class. Defaults all values based on the value of the waf.config.parents parameter. Any errors encountered during loading are reported in the given ErrorList.

Parameters:
ctx - the config object to load
errs - used to accumulate errors during loading
Throws:
IllegalArgumentException - if this ConfigRegistry does not contain a mapping for ctx.getClass()

load

public InputStream load(String resource)
Searches through this ConfigRegistry and its parents for the given resource. If it is not found it is also searched for in the classpath specified by the loader passed to this ConfigRegistry on construction. This may be used to load configuration information that is not stored in a config object.

Parameters:
resource - the path to the resource
Returns:
an input stream containing the contents of the resource or null if the resource is not found


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC