com.tomgibara.pronto.config
Interface Config


public interface Config

Author:
Tom Gibara

Method Summary
<T> T
adaptSettings(java.lang.String domain, boolean inherit, java.lang.Class<T> iface)
          This method creates a live mapping of this config's source properties to a specified interface.
 Config clone()
          Returns a config object which is supported by the same properties and which uses the same class loader.
 Config forClassLoader(java.lang.ClassLoader classLoader)
          Returns a config object which is supported by the same properties as this one but using the specified class loader.
 java.lang.ClassLoader getClassLoader()
          The classloader with which this config was constructed.
 ConfigPolicy getPolicy()
          Returns the policy which is currently in effect for this config.
 java.lang.String getProperty(java.lang.String name)
          Obtains current value of a specfied propery.
 ConfigSource getSource()
           
 void setPolicy(ConfigPolicy policy)
          Sets the policy.
 

Method Detail

setPolicy

void setPolicy(ConfigPolicy policy)
Sets the policy. If a null policy is supplied, an instance of the default policy is used. The timeliness with which calls change the policy take effect for live settings objects is not specified. For this reason, it is recommended that the appropriate policy be set before calls to the adaptSettings method.

Parameters:
policy - the policy to use for this config, or null for a default policy

getPolicy

ConfigPolicy getPolicy()
Returns the policy which is currently in effect for this config.

Returns:
the current policy, never null

getClassLoader

java.lang.ClassLoader getClassLoader()
The classloader with which this config was constructed. If the class loader is null, then the context classloader (or failing that, this class's classloader) will be used to create new settings objects.

Returns:
the class loader used by this object

getSource

ConfigSource getSource()
Returns:
The configuration source for this object.

adaptSettings

<T> T adaptSettings(java.lang.String domain,
                    boolean inherit,
                    java.lang.Class<T> iface)
                throws java.lang.IllegalArgumentException
This method creates a live mapping of this config's source properties to a specified interface. Properties for the interface may be drawn from a subset of all properties by specifying a domain that effectively namespaces the properties mapped to the interface. If no domain is specified then all properties will be available for mapping to the interface In addition, if the inherit argument is true, parent domains will be searched for values to satisfy interface methods. The same interface may be implemented with various different combinations of domain and inheritence by calling this method multiple times with different values.

Type Parameters:
T - the interface type being implemented
Parameters:
domain - a dot separated prefix which identifies the values which should support the interface's implementation, may be null
inherit - true if values should be inherited from parent domains, false otherwise
iface - the interface to implement
Returns:
an implementation of the supplied interface which draws live values from this config
Throws:
java.lang.IllegalArgumentException - if the supplied class is not an interface

getProperty

java.lang.String getProperty(java.lang.String name)
                             throws ProntoConfigException
Obtains current value of a specfied propery.

Parameters:
name - the name of the property to be returned, not null
Returns:
the property currently associated with the specified name
Throws:
ProntoConfigException - if the properties could not be accessed and the policy is to throw exceptions

forClassLoader

Config forClassLoader(java.lang.ClassLoader classLoader)
Returns a config object which is supported by the same properties as this one but using the specified class loader. If the class loader matches the one specified on this instance, this is returned.

Parameters:
classLoader - the class loader to be used to load settings classes.
Returns:
a new configuration object, or this if a new object is not necessary

clone

Config clone()
Returns a config object which is supported by the same properties and which uses the same class loader. This method may be used to create multiple instances to reduce lock contention during property retrieval (at the possible expense of duplicated effort by clones). For correctness, this method requires that the source supplied to a cloned config support concurrent use.

Returns:
a clone of this object.


Copyright © 2006-2007 Tom Gibara. All Rights Reserved.