com.sibvisions.rad.server.config
Class UpToDateConfigFile

java.lang.Object
  extended by com.sibvisions.rad.server.config.UpToDateConfigFile
Direct Known Subclasses:
Zone

public class UpToDateConfigFile
extends Object

The UpToDateConfigFile encapsulates the access to a xml configuration file. It's guaranteed that the access to the properties of the file is up-to-date. That means that changes will be detected automatically.


Constructor Summary
UpToDateConfigFile(File pConfig)
          Creates a new instance of UpToDateConfigFile for a xml configuration file.
UpToDateConfigFile(File pConfig, boolean pLazyLoading)
          Creates a new instance of UpToDateConfigFile for a xml configuration file.
UpToDateConfigFile(File pDirectory, String pConfig)
          Creates a new instance of UpToDateConfigFile for a xml configuration file.
UpToDateConfigFile(File pDirectory, String pConfig, boolean pLazyLoading)
          Creates a new instance of UpToDateConfigFile for a xml configuration file.
 
Method Summary
protected  XmlNode getContent()
          Gets the current configuration xml content.
 File getFile()
          Gets the configuration file.
 List<XmlNode> getNodes(String pName)
          Gets the value for a property as xml representation.
 List<String> getProperties(String pName)
          Gets a list of values for a property which exists more than once.
 String getProperty(String pName)
          Gets the value of a property from the application configuration file.
 String getProperty(String pName, String pDefault)
          Gets the value of a property from the application configuration file.
 boolean isValid()
          Checks if the configuration file exists.
protected  void setContent(XmlNode pConfig)
          Sets the current configuration xml content.
protected  void update()
          Loads the configuration from the filesystem.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UpToDateConfigFile

public UpToDateConfigFile(File pDirectory,
                          String pConfig)
                   throws Exception
Creates a new instance of UpToDateConfigFile for a xml configuration file. The configuration will read immediately.

Parameters:
pDirectory - the directory where to find the configuration file
pConfig - the configuration file name
Throws:
Exception - if it is not possible to read the configuration from the filesystem or the xml content is not valid

UpToDateConfigFile

public UpToDateConfigFile(File pDirectory,
                          String pConfig,
                          boolean pLazyLoading)
                   throws Exception
Creates a new instance of UpToDateConfigFile for a xml configuration file.

Parameters:
pDirectory - the directory where to find the configuration file
pConfig - the configuration file name
pLazyLoading - true to load the configuration immediate, false to load the configuration when used the first time
Throws:
Exception - if it is not possible to read the configuration from the filesystem or the xml content is not valid

UpToDateConfigFile

public UpToDateConfigFile(File pConfig)
                   throws Exception
Creates a new instance of UpToDateConfigFile for a xml configuration file. The configuration will read immediately.

Parameters:
pConfig - the configuration file
Throws:
Exception - if it is not possible to read the configuration from the filesystem or the xml content is not valid

UpToDateConfigFile

public UpToDateConfigFile(File pConfig,
                          boolean pLazyLoading)
                   throws Exception
Creates a new instance of UpToDateConfigFile for a xml configuration file.

Parameters:
pConfig - the configuration file
pLazyLoading - true to load the configuration immediate, false to load the configuration when used the first time
Throws:
Exception - if it is not possible to read the configuration from the filesystem or the xml content is not valid
Method Detail

getFile

public File getFile()
Gets the configuration file.

Returns:
the configuration file

getContent

protected XmlNode getContent()
                      throws Exception
Gets the current configuration xml content.

Returns:
the current XmlNode
Throws:
Exception - if the configuration is invalid or it's not possible to create a clone of the content

setContent

protected void setContent(XmlNode pConfig)
Sets the current configuration xml content.

Parameters:
pConfig - the XmlNode for the content

isValid

public boolean isValid()
Checks if the configuration file exists.

Returns:
true if the configuration file exists otherwise false

update

protected void update()
               throws Exception
Loads the configuration from the filesystem.

Throws:
Exception - if it is not possible to read the configuration from the filesystem or the xml content is not valid

getProperty

public String getProperty(String pName)
                   throws Exception
Gets the value of a property from the application configuration file.

Parameters:
pName - the property name (e.g /application/securitymanager/class)
Returns:
the value for the property or null if the property is not available
Throws:
Exception - if the configuration is invalid

getProperty

public String getProperty(String pName,
                          String pDefault)
                   throws Exception
Gets the value of a property from the application configuration file.

Parameters:
pName - the property name (e.g /application/securitymanager/class)
pDefault - the default value if the property is not available
Returns:
the value for the property or pDefault if the property is not available
Throws:
Exception - if the configuration is invalid

getProperties

public List<String> getProperties(String pName)
                           throws Exception
Gets a list of values for a property which exists more than once.

Parameters:
pName - the property name
Returns:
the list of values or null if the property is not available
Throws:
Exception - if the configuration is invalid

getNodes

public List<XmlNode> getNodes(String pName)
                       throws Exception
Gets the value for a property as xml representation.

Parameters:
pName - the property name
Returns:
the available xml node(s) or null if the property is not available
Throws:
Exception - if the configuration is invalid


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.