com.ibm.wbi.util
Class FileElementParser

java.lang.Object
  |
  +--com.ibm.wbi.util.FileElementParser

public class FileElementParser
extends java.lang.Object

A FileElementParser reads in the contents of a file and parses the contents into elements and encapsulated data. (i.e. the encapsulated data) The elements can then be read and manipulated and then written back out to the file once we close().


Field Summary
protected  boolean dirty
           
 
Constructor Summary
FileElementParser()
          Constructs a new file element parser.
 
Method Summary
 void addElement(java.lang.String element, java.lang.String data)
          Add element to the file with the specified data.
 void close()
          Close the file writing all the elements and their encapsulated data to the file.
protected  void finalize()
          Just in case no ones closes the file and the garbage collector cleans this object up, then close the file first.
 void flush()
          Flush the contents to the file.
 java.lang.String getElementData(java.lang.String element)
          Get the encapsulated data associated with the specified element.
 java.util.Enumeration getElements()
          Get an enumeration of all the elements that encapsulated data.
static void main(java.lang.String[] args)
          Test driver.
 void open(java.io.File file)
          Open the file and extract all the elements and their encapsulated data.
 void open(java.lang.String file)
          Open the file and extract all the elements and their encapsulated data.
 void removeElement(java.lang.String element)
          Remove an element and it's encapsulated data.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dirty

protected boolean dirty
Constructor Detail

FileElementParser

public FileElementParser()
Constructs a new file element parser.
Method Detail

open

public void open(java.lang.String file)
          throws FileElementParserException,
                 java.io.IOException
Open the file and extract all the elements and their encapsulated data.
Parameters:
file - The file to read from and write to when close() is called.
Throws:
FileElementParserException - If any error occurs; see the detailed message for more information.
java.io.IOException - can be thrown for IO problems while closing the file (for example, FileNotFoundException)

open

public void open(java.io.File file)
          throws FileElementParserException,
                 java.io.IOException
Open the file and extract all the elements and their encapsulated data.
Parameters:
file - The file to read from and write to when close() is called.
Throws:
FileElementParserException - If any error occurs; see the detailed message for more information.
java.io.IOException - can be thrown for IO problems while closing the file (for example, FileNotFoundException)

flush

public void flush()
           throws FileElementParserException,
                  java.io.IOException
Flush the contents to the file.
Throws:
FileElementParserException - If any error occurs; see the detailed message for more information.
java.io.IOException - can be thrown for IO problems while closing the file (for example, FileNotFoundException)

close

public void close()
           throws FileElementParserException,
                  java.io.IOException
Close the file writing all the elements and their encapsulated data to the file.
Throws:
FileElementParserException - If any error occurs; see the detailed message for more information.
java.io.IOException - can be thrown for IO problems while closing the file (for example, FileNotFoundException)

getElements

public java.util.Enumeration getElements()
Get an enumeration of all the elements that encapsulated data.
Returns:
The elements.

addElement

public void addElement(java.lang.String element,
                       java.lang.String data)
Add element to the file with the specified data.
Parameters:
element - The element to add to the file.
data - The data encapsulated by the element.

getElementData

public java.lang.String getElementData(java.lang.String element)
Get the encapsulated data associated with the specified element.
Parameters:
element - The element.
Returns:
The data encapsulated by the element.

removeElement

public void removeElement(java.lang.String element)
Remove an element and it's encapsulated data.
Parameters:
element - The element to remove.

finalize

protected void finalize()
                 throws java.lang.Throwable
Just in case no ones closes the file and the garbage collector cleans this object up, then close the file first.
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - Nothing gets thrown.

main

public static final void main(java.lang.String[] args)
Test driver.
Parameters:
args - Command line arguments.