com.sibvisions.rad.server.config
Class UpToDateConfigFile

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

public class UpToDateConfigFile
extends Object
implements Cloneable

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 pDirectory, String pConfig)
          Creates a new instance of UpToDateConfigFile for a xml configuration file.
 
Method Summary
 Object clone()
          
protected  XmlWorker createXmlWorker()
          Creates the default XmlWorker for reading the file.
 File getFile()
          Gets the configuration file.
 XmlNode getNode(String pName)
          Gets the value for a property as xml representation.
 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 isSaveImmediate()
          Gets it immediate save of changes is enabled.
 boolean isUpdateEnabled()
          Gets whether the up-to-date option is enabled.
 boolean isValid()
          Checks if the configuration file exists.
 void reload()
          Discards all changes and loads the configuration file.
 void save()
          Saves the changes to the file.
protected  void setContent(XmlNode pNode)
          Sets the internal data node.
 void setNode(String pName, XmlNode pNode)
          Sets a specific node to the application configuration file.
 void setProperty(String pName, String pValue)
          Sets the value ofa protperty to the application configuration file.
 void setSaveImmediate(boolean pEnabled)
          Sets the save immediate option.
 void setUpdateEnabled(boolean pEnabled)
          Sets the up-to-date option of the configuration.
protected  void update()
          Loads the configuration from the filesystem.
 
Methods inherited from class java.lang.Object
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 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
Method Detail

clone

public Object clone()
             throws CloneNotSupportedException

Overrides:
clone in class Object
Throws:
CloneNotSupportedException

getFile

public File getFile()
Gets the configuration file.

Returns:
the configuration file

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

setProperty

public void setProperty(String pName,
                        String pValue)
                 throws Exception
Sets the value ofa protperty to the application configuration file.

Parameters:
pName - the property name (e.g. /application/securitymanager/class)
pValue - the value
Throws:
Exception - if the configuration is invalid

setNode

public void setNode(String pName,
                    XmlNode pNode)
             throws Exception
Sets a specific node to the application configuration file.

Parameters:
pName - the property name
pNode - the new node or null to remove the property
Throws:
Exception - if the configuration is invalid

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

getNode

public XmlNode getNode(String pName)
                throws Exception
Gets the value for a property as xml representation.

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

setUpdateEnabled

public void setUpdateEnabled(boolean pEnabled)
Sets the up-to-date option of the configuration.

Parameters:
pEnabled - true doesn't update the configuration when next accessing; false always keeps the configuration up-to-date

isUpdateEnabled

public boolean isUpdateEnabled()
Gets whether the up-to-date option is enabled.

Returns:
true if the current configuration will be read before accessing a property, false if the configuration won't be read again

setSaveImmediate

public void setSaveImmediate(boolean pEnabled)
Sets the save immediate option. If save immediate is enabled, then changes will be written automatically.

Parameters:
pEnabled - true to enable immediate save changes, false otherwise

isSaveImmediate

public boolean isSaveImmediate()
Gets it immediate save of changes is enabled.

Returns:
true if changes will saved immediate, false otherwise

save

public void save()
          throws IOException
Saves the changes to the file.

Throws:
IOException - if the file access failed

reload

public void reload()
            throws Exception
Discards all changes and loads the configuration file.

Throws:
Exception - if an exception occurs during loading

createXmlWorker

protected XmlWorker createXmlWorker()
Creates the default XmlWorker for reading the file.

Returns:
the xml worker

setContent

protected void setContent(XmlNode pNode)
Sets the internal data node.

Parameters:
pNode - the data node


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.