com.createtank.util.configuration
Class XMLConfiguration

java.lang.Object
  extended by com.createtank.util.configuration.XMLConfiguration

public class XMLConfiguration
extends java.lang.Object

Utility class developed by createTank to allow simple parsing of configuration files written in XML. copyright (c) 1999,2006 createTank

Author:
John Joseph Roets mailto:joe@createtank.com

Constructor Summary
XMLConfiguration(java.lang.String configFile)
          XMLConfiguration constructor.
 
Method Summary
 java.util.Properties getProperties(java.lang.String elementTagName)
          Returns Properties object containing attributes from within the element requested by tagName For use when the user knows that there is only one occurrance of the requested tagName within the XML document.
 java.util.Properties getProperties(java.lang.String elementTagName, java.lang.String compAttr, java.lang.String compValue)
          Returns Properties object containing attributes from within the occurance of the element requested by tagName when its Attribute compAttr is equal to the value requested in compValue.
 java.util.List getPropertiesList(java.util.List tagTree, java.util.List compAttr, java.util.List compValue)
          Returns List of Properties objects containing attributes from within the occurance of the element requested by the tagTree list, when its respective attribute compAttr is equal to the respective value in compValue.
 java.util.List getPropertiesList(java.lang.String elementTagName)
          Returns a List of Properties objects containing attributes from multiple occurances of the elementTagName requested.
 java.util.List getPropertiesListByPath(java.lang.String path)
          Allows passing of a UNIX style path as a String, in order to specify a specific set of nodes within the XML configuration file.
static void main(java.lang.String[] args)
          Starts the application.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLConfiguration

public XMLConfiguration(java.lang.String configFile)
                 throws org.xml.sax.SAXException,
                        java.io.IOException
XMLConfiguration constructor.

Parameters:
configFile - java.lang.String The file to parse
Throws:
org.xml.sax.SAXException - SAX specific exception
java.io.IOException - IOException
Method Detail

getProperties

public java.util.Properties getProperties(java.lang.String elementTagName)
                                   throws NonexistentElementException
Returns Properties object containing attributes from within the element requested by tagName For use when the user knows that there is only one occurrance of the requested tagName within the XML document.

Parameters:
elementTagName - java.lang.String The XML tagName to get attributes from
Returns:
java.util.Properties Attributes from requested tagName Element (the first such Element if multiple are present).
Throws:
NonexistentElementException - elementTagName does not exist within current XML document.

getProperties

public java.util.Properties getProperties(java.lang.String elementTagName,
                                          java.lang.String compAttr,
                                          java.lang.String compValue)
                                   throws NonexistentElementException
Returns Properties object containing attributes from within the occurance of the element requested by tagName when its Attribute compAttr is equal to the value requested in compValue. For use when the user knows that there are multiple occurrances of the requested tagName within the XML document, and the user knows which occurance is needed (by a particular Attribute's value).

Parameters:
elementTagName - java.lang.String The XML tagName to get attributes from
compAttr - the Element's Attribute with which to compare compValue in order to decide which Attributes to pass back.
compValue - the value with which to compare to compAttr's value in order to decide which Attributes to pass back.
Returns:
java.util.Properties Attributes from requested tagName Element which comply to the above matching criteria.
Throws:
NonexistentElementException - elementTagName does not exist within current XML document.

getPropertiesList

public java.util.List getPropertiesList(java.lang.String elementTagName)
                                 throws NonexistentElementException
Returns a List of Properties objects containing attributes from multiple occurances of the elementTagName requested. For use when the user knows that there are multiple occurrances of the requested tagName within the XML document, and all are wanted/needed.

Parameters:
elementTagName - java.lang.String The XML tagName to get attributes from
Returns:
java.util.List A List of Properties objects containing Attributes from the requested tagName Element.
Throws:
NonexistentElementException - elementTagName does not exist within current XML document.

getPropertiesListByPath

public java.util.List getPropertiesListByPath(java.lang.String path)
                                       throws NonexistentElementException
Allows passing of a UNIX style path as a String, in order to specify a specific set of nodes within the XML configuration file. This set of nodes is returned as a List, populated with Properties objects, further populated by the attributes within the nodes returned. The path can be specified in a number of ways:
root/node/node/node-set
This will retrieve set of nodes in the XML tree pointed to by the path.
root/node:att-name=attvalue/node/node-set
This will retrieve set of nodes in the XML tree pointed to by the path, and limited by the att-name=att-value components.
For Example, the first type, a simple path will retrieve the List of Properties as pointed to by the direct path: "LMNOP/production/database/connectionPool" will retrieve all connectionPool nodes, returning their respective attributes as elements within the individual Properties objects returned. "LMNOP/production/transactions/transactionSet:name=inputTransactions/transaction" will retrieve all transactions nodes within the transactionSet node which has the name attribute set to "inputTransactions".

Parameters:
path - UNIX style path to node of interest...See above for details.
Returns:
List of Properties objects, populated with attributes of selected node(s).
Throws:
NonexistentElementException - thrown if element in path doesn't exist

getPropertiesList

public java.util.List getPropertiesList(java.util.List tagTree,
                                        java.util.List compAttr,
                                        java.util.List compValue)
                                 throws NonexistentElementException
Returns List of Properties objects containing attributes from within the occurance of the element requested by the tagTree list, when its respective attribute compAttr is equal to the respective value in compValue. For use when the user knows that there are one or multiple occurrances of the requested tagName within the XML document, and the user knows the full XML tree path.

Parameters:
tagTree - java.util.List The XML tree path
compAttr - java.util.List the respective tree path of Element's Attribute with which to compare compValue in order to decide which Attributes to pass back.
compValue - java.util.List the respective tree path of the value with which to compare to compAttr's value in order to decide which Attributes to pass back.
Returns:
java.util.List list of Properties objects containing Attributes from requested XML tree path which comply to the above matching criteria.
Throws:
NonexistentElementException - elementTagName does not exist within current XML document.

main

public static void main(java.lang.String[] args)
Starts the application. A simple test of the class.

Parameters:
args - an array of command-line arguments