org.aselect.system.configmanager.handler
Class XMLConfigHandler

java.lang.Object
  extended by org.aselect.system.configmanager.handler.XMLConfigHandler
All Implemented Interfaces:
IConfigHandler

public class XMLConfigHandler
extends java.lang.Object
implements IConfigHandler

ConfigHandler that reads and writes configuration items as XML data.

Description:
ConfigHandler that reads and writes configuration files located on harddisk or JDBC database. This class can handle XML configuration files that are located in a file or a JDBC database, like:
table_name -> [id][XML data] where id is unique within the table.

Concurrency issues:
This IConfigHandler is threadsafe.

Author:
Alfa & Ariss

Constructor Summary
XMLConfigHandler(SystemLogger oSystemLogger)
          Default constructor.
 
Method Summary
 java.lang.Object getNextSection(java.lang.Object oSection)
          Resolve the next section (XML tag) which has the same type as the supplied section, it will be the follow-up tag.
 java.lang.String getParam(java.lang.Object oSection, java.lang.String sConfigItem)
          Retrieves the value of the config parameter from the config section that is supplied.
 java.lang.Object getSection(java.lang.Object oRootSection, java.lang.String sSectionType)
          Retrieves a config section by it's type.
 java.lang.Object getSection(java.lang.Object oRootSection, java.lang.String sSectionType, java.lang.String sSectionID)
          Retrieves a config section by it's type and id.
 void importConfig(java.io.File configFile)
          Deprecated. All config should be stored in only one config file.
 void init(java.io.File fConfig)
          Parses an XML config File to an XML DOM Object.
 void init(java.lang.String sUser, java.lang.String sPassword, java.lang.String sDatabaseURL, java.lang.String sDatabaseTable, java.lang.String sDriverName, java.lang.String sConfigId)
          Parses the XML configuration located in a JDBC database to an XML Dom object.
 boolean removeSection(java.lang.Object oRootSection, java.lang.String sSectionType)
          Removes the section (XML tag) from the supplied root section which has the type that is supplied.
 boolean removeSection(java.lang.Object oRootSection, java.lang.String sSectionType, java.lang.String sSectionID)
          Removes the section (XML tag) from the supplied root section which has the type and the ID that is supplied.
 void saveConfig()
          Saves the configuration to the physical storage from which it is retrieved.
 boolean setParam(java.lang.Object oRootSection, java.lang.String sConfigItem, java.lang.String sConfigValue, boolean bMandatory)
          Puts a new parameter into the given section like value .
 java.lang.Object setSection(java.lang.Object oRootSection, java.lang.String sSectionType)
          Adds a config section (empty tag) with section type as it's name (tagname) and returns the new section.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLConfigHandler

public XMLConfigHandler(SystemLogger oSystemLogger)
Default constructor.

Description:
Default constructor for XMLConfigHandler.

Concurrency issues:
-

Preconditions:
oSystemLogger should be initialized.

Postconditions:
The system logger is set.

Parameters:
oSystemLogger - The system logger that should be used.
Method Detail

init

public void init(java.io.File fConfig)
          throws ASelectConfigException
Parses an XML config File to an XML DOM Object.

Specified by:
init in interface IConfigHandler
Parameters:
fConfig - The File that contains the configuration
Throws:
ASelectConfigException - If initialization fails.
See Also:
IConfigHandler.init(java.io.File)

init

public void init(java.lang.String sUser,
                 java.lang.String sPassword,
                 java.lang.String sDatabaseURL,
                 java.lang.String sDatabaseTable,
                 java.lang.String sDriverName,
                 java.lang.String sConfigId)
          throws ASelectConfigException
Parses the XML configuration located in a JDBC database to an XML Dom object.

Specified by:
init in interface IConfigHandler
Parameters:
sUser - Username that must be used to coneect to the database
sPassword - Password for the user that must be used to connect to the database
sDatabaseURL - URL to the database
sDatabaseTable - Database table in which the configuration is stored
sDriverName - The name of the driver that will be used to connect to the database
sConfigId - The ID of the configuration in which the specific configuration is located
Throws:
ASelectConfigException - If initialization fails.
See Also:
IConfigHandler.init(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)

getSection

public java.lang.Object getSection(java.lang.Object oRootSection,
                                   java.lang.String sSectionType,
                                   java.lang.String sSectionID)
                            throws ASelectConfigException
Retrieves a config section by it's type and id.

Specified by:
getSection in interface IConfigHandler
Parameters:
oRootSection - The section in which the requested section is located.
sSectionType - The type of the section, in XML the XML tag name.
sSectionID - The id of a section (syntax: [param]=[value])
Returns:
Object that indicates a specific section within the configuration.
Throws:
ASelectConfigException - If retrieving fails.
See Also:
IConfigHandler.getSection(java.lang.Object, java.lang.String, java.lang.String)

getSection

public java.lang.Object getSection(java.lang.Object oRootSection,
                                   java.lang.String sSectionType)
                            throws ASelectConfigException
Retrieves a config section by it's type.

Specified by:
getSection in interface IConfigHandler
Parameters:
oRootSection - The root section.
sSectionType - The type of section.
Returns:
First configuration section of the specified sectionType
Throws:
ASelectConfigException - If retrieving fails.
See Also:
IConfigHandler.getSection(java.lang.Object, java.lang.String)

setSection

public java.lang.Object setSection(java.lang.Object oRootSection,
                                   java.lang.String sSectionType)
                            throws ASelectConfigException
Adds a config section (empty tag) with section type as it's name (tagname) and returns the new section.

Specified by:
setSection in interface IConfigHandler
Parameters:
oRootSection - Section that is used to resulve the subsection
sSectionType - Type of the subsection that should be returned
Returns:
Object containing the subsection
Throws:
ASelectConfigException - Is setting session fails.
See Also:
IConfigHandler.setSection(java.lang.Object, java.lang.String)

getParam

public java.lang.String getParam(java.lang.Object oSection,
                                 java.lang.String sConfigItem)
                          throws ASelectConfigException
Retrieves the value of the config parameter from the config section that is supplied.

Specified by:
getParam in interface IConfigHandler
Parameters:
oSection - Section from which contains the parameter
sConfigItem - The name of the config parameter
Returns:
String containing the requested config parameter
Throws:
ASelectConfigException - If retrieving fails.
See Also:
IConfigHandler.getParam(java.lang.Object, java.lang.String)

setParam

public boolean setParam(java.lang.Object oRootSection,
                        java.lang.String sConfigItem,
                        java.lang.String sConfigValue,
                        boolean bMandatory)
                 throws ASelectConfigException
Puts a new parameter into the given section like value .

Specified by:
setParam in interface IConfigHandler
Parameters:
oRootSection - The config section to which the parameter will be added
sConfigItem - Name of the config parameter that will be added
sConfigValue - Value of the config parameter that will be added
bMandatory - TRUE if config parameter is requered in the section
Returns:
TRUE if parameter is successfully added
Throws:
ASelectConfigException - If setting fails.
See Also:
IConfigHandler.setParam(java.lang.Object, java.lang.String, java.lang.String, boolean)

getNextSection

public java.lang.Object getNextSection(java.lang.Object oSection)
                                throws ASelectConfigException
Resolve the next section (XML tag) which has the same type as the supplied section, it will be the follow-up tag. The sections must be located in the same root section (root tag). It returns the next section or null if their is no next section.

Specified by:
getNextSection in interface IConfigHandler
Parameters:
oSection - Section that has the same type as the section that must be returned
Returns:
Object That contains the next section
Throws:
ASelectConfigException - If retrieving fails
See Also:
IConfigHandler.getNextSection(java.lang.Object)

removeSection

public boolean removeSection(java.lang.Object oRootSection,
                             java.lang.String sSectionType)
                      throws ASelectConfigException
Removes the section (XML tag) from the supplied root section which has the type that is supplied.

Specified by:
removeSection in interface IConfigHandler
Parameters:
oRootSection - Section containing the section that must be removed
sSectionType - Type of the section that must be removed
Returns:
TRUE if section is successfully removed, otherwise false.
Throws:
ASelectConfigException - If removinf fails.
See Also:
IConfigHandler.removeSection(java.lang.Object, java.lang.String)

removeSection

public boolean removeSection(java.lang.Object oRootSection,
                             java.lang.String sSectionType,
                             java.lang.String sSectionID)
                      throws ASelectConfigException
Removes the section (XML tag) from the supplied root section which has the type and the ID that is supplied. The ID must be an XML attribute like:
should be supplied as id=id

Specified by:
removeSection in interface IConfigHandler
Parameters:
oRootSection - Section containing the section that must be removed
sSectionType - Type of the section that must be removed
sSectionID - ID of section that must be removed (syntax: [name]=[value])
Returns:
TRUE if section is successfully removed
Throws:
ASelectConfigException - If removing fails.
See Also:
IConfigHandler.removeSection(java.lang.Object, java.lang.String, java.lang.String)

saveConfig

public void saveConfig()
                throws ASelectConfigException
Saves the configuration to the physical storage from which it is retrieved. It supports file and JDBC database.

Specified by:
saveConfig in interface IConfigHandler
Throws:
ASelectConfigException - If saving fails
See Also:
IConfigHandler.saveConfig()

importConfig

public void importConfig(java.io.File configFile)
                  throws ASelectConfigException
Deprecated. All config should be stored in only one config file.

Import configuration items into this configuration.

Specified by:
importConfig in interface IConfigHandler
Parameters:
configFile - The configuration File that will be imported in the configuration that is known in the memory of the ConfigHandler
Throws:
ASelectConfigException - If importing fails.
See Also:
IConfigHandler.importConfig(java.io.File)


Copyright © 2008 SURFnet BV. All Rights Reserved.