org.apache.commons.configuration
Class PropertiesConfiguration

java.lang.Object
  extended byorg.apache.commons.configuration.AbstractConfiguration
      extended byorg.apache.commons.configuration.BaseConfiguration
          extended byorg.apache.commons.configuration.BasePathConfiguration
              extended byorg.apache.commons.configuration.BasePropertiesConfiguration
                  extended byorg.apache.commons.configuration.PropertiesConfiguration
All Implemented Interfaces:
BasePathLoader, Configuration

public class PropertiesConfiguration
extends BasePropertiesConfiguration
implements Configuration

This is the "classic" Properties loader which loads the values from a single or multiple files (which can be chained with "include =". All given path references are either absolute or relative to the file name supplied in the Constructor.

In this class, empty PropertyConfigurations can be built, properties added and later saved. include statements are (obviously) not supported if you don't construct a PropertyConfiguration from a file.

If you want to use the getResourceAsStream() trick to load your resources without an absolute path, please take a look at the ClassPropertiesConfiguration which is intended to be used for this.

Version:
$Id: PropertiesConfiguration.java,v 1.1.1.1 2003/12/23 15:09:05 epugh Exp $
Author:
Stefano Mazzocchi, Jon S. Stevens, Dave Bryson, Geir Magnusson Jr., Leon Messerschmidt, Kent Johnson, Daniel Rall, Ilkka Priha, Jason van Zyl, Martin Poeschl, Henning P. Schmiedehausen, Eric Pugh, Oliver Heger

Nested Class Summary
 
Nested classes inherited from class org.apache.commons.configuration.BasePropertiesConfiguration
BasePropertiesConfiguration.PropertiesReader, BasePropertiesConfiguration.PropertiesWriter
 
Nested classes inherited from class org.apache.commons.configuration.AbstractConfiguration
AbstractConfiguration.Container, AbstractConfiguration.PropertiesTokenizer
 
Field Summary
protected  java.lang.String fileName
          The name of the file to be loaded.
protected  java.lang.String fileSeparator
          File separator.
(package private)  org.apache.commons.logging.Log log
          Static logger
 
Fields inherited from class org.apache.commons.configuration.BasePropertiesConfiguration
include
 
Fields inherited from class org.apache.commons.configuration.BasePathConfiguration
 
Fields inherited from class org.apache.commons.configuration.BaseConfiguration
 
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration
defaults, END_TOKEN, START_TOKEN
 
Constructor Summary
PropertiesConfiguration()
          Creates an empty PropertyConfiguration object which can be used to synthesize a new Properties file by adding values and then saving().
PropertiesConfiguration(Configuration defaults)
          Creates an empty PropertyConfiguration object with a Super-Object which is queries for every key.
PropertiesConfiguration(java.lang.String fileName)
          Creates and loads the extended properties from the specified file.
PropertiesConfiguration(java.lang.String file, Configuration defaults)
          Creates and loads the extended properties from the specified file.
PropertiesConfiguration(java.lang.String file, java.lang.String defaultFile)
          Creates and loads the extended properties from the specified file.
 
Method Summary
 java.lang.String getFileName()
          Returns the fileName.
 java.io.InputStream getPropertyStream(java.lang.String resourceName)
          Gets a resource relative to the supplied base path.
 void load()
          Load the properties from the fileName set by setFileName
 void load(java.lang.String fileName)
          Load the properties from the given fileName
 void setBasePath(java.lang.String basePath)
          Extend the setBasePath method to turn includes on and off based on the existence of a base path.
 void setFileName(java.lang.String fileName)
          Sets the fileName.
 
Methods inherited from class org.apache.commons.configuration.BasePropertiesConfiguration
getInclude, getIncludesAllowed, load, load, save, setInclude, setIncludesAllowed
 
Methods inherited from class org.apache.commons.configuration.BasePathConfiguration
getBasePath
 
Methods inherited from class org.apache.commons.configuration.BaseConfiguration
addPropertyDirect, clearProperty, containsKey, getKeys, getPropertyDirect, isEmpty
 
Methods inherited from class org.apache.commons.configuration.AbstractConfiguration
addProperty, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getList, getList, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, interpolate, interpolateHelper, processString, setProperty, subset, testBoolean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.configuration.Configuration
addProperty, clearProperty, containsKey, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getKeys, getList, getList, getLong, getLong, getLong, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, isEmpty, setProperty, subset
 

Field Detail

log

org.apache.commons.logging.Log log
Static logger


fileSeparator

protected java.lang.String fileSeparator
File separator.


fileName

protected java.lang.String fileName
The name of the file to be loaded. This is used in conjuction with the load method.

Constructor Detail

PropertiesConfiguration

public PropertiesConfiguration()
Creates an empty PropertyConfiguration object which can be used to synthesize a new Properties file by adding values and then saving(). An object constructed by this C'tor can not be tickled into loading included files because it cannot supply a base for relative includes.


PropertiesConfiguration

public PropertiesConfiguration(Configuration defaults)
                        throws java.io.IOException
Creates an empty PropertyConfiguration object with a Super-Object which is queries for every key.

Parameters:
defaults - Configuration defaults to use if key not in file
Throws:
java.io.IOException - Error while loading the properties file

PropertiesConfiguration

public PropertiesConfiguration(java.lang.String fileName)
                        throws java.io.IOException
Creates and loads the extended properties from the specified file. The specified file can contain "include = " properties which then are loaded and merged into the properties.

Parameters:
fileName - The name of the Properties File to load.
Throws:
java.io.IOException - Error while loading the properties file

PropertiesConfiguration

public PropertiesConfiguration(java.lang.String file,
                               Configuration defaults)
                        throws java.io.IOException
Creates and loads the extended properties from the specified file.

Parameters:
file - The name of the Properties File to load.
defaults - Configuration defaults to use if key not in file
Throws:
java.io.IOException - Error while loading the properties file

PropertiesConfiguration

public PropertiesConfiguration(java.lang.String file,
                               java.lang.String defaultFile)
                        throws java.io.IOException
Creates and loads the extended properties from the specified file.

Parameters:
file - The name of the Properties File to load.
defaultFile - The name of a properties file whose values should be used if a key is not in the file.
Throws:
java.io.IOException - Error while loading the properties file
Method Detail

load

public void load()
          throws java.io.IOException
Load the properties from the fileName set by setFileName

Throws:
java.io.IOException

load

public void load(java.lang.String fileName)
          throws java.io.IOException
Load the properties from the given fileName

Parameters:
fileName - A properties file to load
Throws:
java.io.IOException

getPropertyStream

public java.io.InputStream getPropertyStream(java.lang.String resourceName)
                                      throws java.io.IOException
Gets a resource relative to the supplied base path. If the passed in resource name is absolute, it is used directly.

Specified by:
getPropertyStream in class BasePropertiesConfiguration
Parameters:
resourceName - The resource Name
Returns:
An Input Stream
Throws:
java.io.IOException - Error while loading the properties file

getFileName

public java.lang.String getFileName()
Returns the fileName.

Returns:
String

setFileName

public void setFileName(java.lang.String fileName)
Sets the fileName.

Parameters:
fileName - The fileName to set

setBasePath

public void setBasePath(java.lang.String basePath)
Extend the setBasePath method to turn includes on and off based on the existence of a base path.

Specified by:
setBasePath in interface BasePathLoader
Overrides:
setBasePath in class BasePathConfiguration
Parameters:
basePath - The new basePath to set.