com.tomgibara.pronto.config.source
Class FileConfigSource

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

public class FileConfigSource
extends java.lang.Object
implements ConfigSource

Parses a file into configuration properties. Instances of this class are safe for concurrent use.

Author:
Tom Gibara

Constructor Summary
FileConfigSource(java.io.File file)
          Constructs a source which reads its properties from a file using a DefaultPropertiesReader.
FileConfigSource(java.io.File file, PropertiesReader reader)
          Constructs a source which reads its properties from a file using the supplied properties reader.
 
Method Summary
 java.io.File getFile()
          The file from which the properties are loaded.
 java.util.Map<java.lang.String,java.lang.String> getProperties()
          The properties read from this source's file.
 PropertiesReader getReader()
          The reader which converts this source's file into properties.
 long lastModified()
          The date on which the file was last modified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileConfigSource

public FileConfigSource(java.io.File file)
Constructs a source which reads its properties from a file using a DefaultPropertiesReader.

Parameters:
file - the file from which the properties are to be loaded, not null

FileConfigSource

public FileConfigSource(java.io.File file,
                        PropertiesReader reader)
Constructs a source which reads its properties from a file using the supplied properties reader. If a null reader is supplied to this constructor, a DefaultPropertiesReader is used.

Parameters:
file - the file from which the properties will be read
reader - a properties reader which can convert the file into a set of properties, may be null
Method Detail

getFile

public java.io.File getFile()
The file from which the properties are loaded.

Returns:
the file for this source, never null

getReader

public PropertiesReader getReader()
The reader which converts this source's file into properties.

Returns:
the properties reader for this source

lastModified

public long lastModified()
                  throws java.lang.RuntimeException
The date on which the file was last modified. Note that this value is not monotonically increasing since file dates may adjusted arbitrarily.

Specified by:
lastModified in interface ConfigSource
Returns:
the date this source's file was last modified
Throws:
java.lang.RuntimeException - if the file's last modified time may not be read

getProperties

public java.util.Map<java.lang.String,java.lang.String> getProperties()
                                                               throws java.lang.RuntimeException
The properties read from this source's file. Note that each call to this method reads the file to obtain the properties so if this method is being called very frequently (possibly due to a ConfigPolicy with a very low maximum read time) consider wrapping it in a CachingConfigSource.

Specified by:
getProperties in interface ConfigSource
Returns:
the properties for this source
Throws:
java.lang.RuntimeException - if an IOException occurs reading the file


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