com.tomgibara.pronto.config.source
Class CompositeConfigSource

java.lang.Object
  extended by com.tomgibara.pronto.config.source.CompositeConfigSource
All Implemented Interfaces:
ConfigSource

public class CompositeConfigSource
extends java.lang.Object
implements ConfigSource

This class provides a simple way of combining the properties from two configuration sources into one. This implementation is thread-safe iff both original sources are threadsafe. Changes to the properties of either original source will be immediately reflected in the properties returned by this source.

To combine more than two configuration sources consider chaining multiple instances of this class.

Author:
Tom Gibara.

Constructor Summary
CompositeConfigSource(ConfigSource primarySource, ConfigSource secondarySource)
          Constructs a new composite configuration source from two existing sources.
 
Method Summary
 ConfigSource getPrimarySource()
           
 java.util.Map<java.lang.String,java.lang.String> getProperties()
          Returns the union of the properties from both underlying sources.
 ConfigSource getSecondarySource()
           
 long lastModified()
          Returns the latest time at which either of the underlying configuration sources was last modified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeConfigSource

public CompositeConfigSource(ConfigSource primarySource,
                             ConfigSource secondarySource)
Constructs a new composite configuration source from two existing sources. Where the same property is defined by both sources, the value provided by the primary source dominates.

Parameters:
primarySource - the primary source of configuration properties, not null
secondarySource - the secondary source of configuration properties, not null
Method Detail

getPrimarySource

public ConfigSource getPrimarySource()
Returns:
the primary source with which this object was constructed, never null

getSecondarySource

public ConfigSource getSecondarySource()
Returns:
the secondary source with which this object was constructed, never null

lastModified

public long lastModified()
                  throws java.lang.RuntimeException
Returns the latest time at which either of the underlying configuration sources was last modified.

Specified by:
lastModified in interface ConfigSource
Returns:
the time this source's properties were last modified
Throws:
java.lang.RuntimeException - if either underlying source throws a RuntimeException

getProperties

public java.util.Map<java.lang.String,java.lang.String> getProperties()
                                                               throws java.lang.RuntimeException
Returns the union of the properties from both underlying sources. Where the same property is defined by both sources, the value provided by the primary source dominates.

Specified by:
getProperties in interface ConfigSource
Returns:
the current properties for this source
Throws:
java.lang.RuntimeException - if either underlying source throws a RuntimeException


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