com.ls.util.xml
Class XMLConfigLoader

java.lang.Object
  |
  +--com.ls.util.xml.XMLConfigLoader
Direct Known Subclasses:
ConfigLoader

public class XMLConfigLoader
extends Object

This class loads a XML config file into a map. The config file can be either an URL or a file on the harddisk.

Version:
$Revision: 1.5 $
Author:
Last modified by $Author: MFehrenbach $

Field Summary
static String ARCHIVE_STRING
          constant for the String 'archive'
static String FILE_STRING
          constant for the String 'file'
static String IP_ADDRESS_STRING
          constant for the String 'ipAddress'
protected  ILogger logger
          the reference to the owning agent's log file (initally set to SystemLogger.getLogger())
static String NAME_STRING
          constant for the String 'name'
static String PATH_STRING
          constant for the String 'path'
static String PORT_STRING
          constant for the String 'port'
static String PROTOCOL_STRING
          constant for the String 'protocol'
 
Constructor Summary
XMLConfigLoader()
          constructor that initializes a XMLHandler to be used for reading config files
XMLConfigLoader(String protocol)
          constructor that initializes a XMLHandler as the ConfigHandler to be used for reading config files
XMLConfigLoader(String protocol, IXMLHandler iXMLHandler)
          constructor that takes an IXMLHandler as the ConfigHandler to be used for reading config files
 
Method Summary
static String getGlobalConfigPath()
          Returns the path where the config files, that are not addressed via an absolute path, will be found.
 Map parseFile(List configFileNames)
          Reads the XML data from the config file and parses it to an hash object.
 Map parseFile(Map configFileName)
          Reads the XML data from the config file and parses it to an hash object.
 Map parseFile(String configFileName)
          Reads the XML data from the config file and parses it to an hash object.
static void setGlobalConfigPath(Map configPath)
          Sets the path where the config files, that are not addressed via an absolute path, will be found.
static void setGlobalConfigPath(String path)
          Sets the path where the config files, that are not addressed via an absolute path, will be found.
 void setLog(ILogger logger)
          Sets the ILogger for the ConfigLoader.
 void setProtocol(String protocol)
          sets the protocol for the URL to read the config file from.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_STRING

public static final String FILE_STRING
constant for the String 'file'

PROTOCOL_STRING

public static final String PROTOCOL_STRING
constant for the String 'protocol'

IP_ADDRESS_STRING

public static final String IP_ADDRESS_STRING
constant for the String 'ipAddress'

PATH_STRING

public static final String PATH_STRING
constant for the String 'path'

ARCHIVE_STRING

public static final String ARCHIVE_STRING
constant for the String 'archive'

NAME_STRING

public static final String NAME_STRING
constant for the String 'name'

PORT_STRING

public static final String PORT_STRING
constant for the String 'port'

logger

protected ILogger logger
the reference to the owning agent's log file (initally set to SystemLogger.getLogger())
Constructor Detail

XMLConfigLoader

public XMLConfigLoader()
constructor that initializes a XMLHandler to be used for reading config files
See Also:
XMLHandler

XMLConfigLoader

public XMLConfigLoader(String protocol)
constructor that initializes a XMLHandler as the ConfigHandler to be used for reading config files
Parameters:
protocol - the protocol to use for loading the config file
See Also:
XMLHandler

XMLConfigLoader

public XMLConfigLoader(String protocol,
                       IXMLHandler iXMLHandler)
constructor that takes an IXMLHandler as the ConfigHandler to be used for reading config files
Parameters:
protocol - the protocol to use for loading the config file
See Also:
XMLHandler
Method Detail

setLog

public void setLog(ILogger logger)
Sets the ILogger for the ConfigLoader. Should be called directly after creating the ConfigLoader.
Parameters:
logger - reference to the ILogger of the owning agent

getGlobalConfigPath

public static String getGlobalConfigPath()
Returns the path where the config files, that are not addressed via an absolute path, will be found.
Returns:
config file path (empty string, if none is configured)

setGlobalConfigPath

public static void setGlobalConfigPath(String path)
                                throws ProgrammingException
Sets the path where the config files, that are not addressed via an absolute path, will be found.
Parameters:
path - config file path
Throws:
ProgrammingException - If global config path was already set before

setGlobalConfigPath

public static void setGlobalConfigPath(Map configPath)
                                throws ProgrammingException
Sets the path where the config files, that are not addressed via an absolute path, will be found.
Parameters:
configPath - config file path
Throws:
ProgrammingException - If global config path was already set before

parseFile

public Map parseFile(String configFileName)
Reads the XML data from the config file and parses it to an hash object. The config file can be either a file on a harddisk or an URL.
Parameters:
configFileName - one file names specifying the config file to be read
Returns:
map with the data of the config file or null in case of an error

parseFile

public Map parseFile(List configFileNames)
Reads the XML data from the config file and parses it to an hash object. The config file can be either a file on a harddisk or an URL.
Parameters:
configFileNames - one or more file names specifying the config file(s) to be read
Returns:
map with the data of the config file or null in case of an error

parseFile

public Map parseFile(Map configFileName)
Reads the XML data from the config file and parses it to an hash object. The config file can be either a file on a harddisk or an URL.
Parameters:
configFileName - one file name specifying the config file to be read
Returns:
map with the data of the config file or null in case of an error

setProtocol

public void setProtocol(String protocol)
sets the protocol for the URL to read the config file from.
Parameters:
protocol - the protocol to read from (e.g.: 'file:///', 'http:///', 'ftp:///', ...)