uk.org.ogsadai.converters.resultset
Class ResultSetConverter

java.lang.Object
  |
  +--uk.org.ogsadai.converters.resultset.ResultSetConverter

public class ResultSetConverter
extends java.lang.Object

A class to convert the contents of java.sql.ResultSet objects into blocks of data. An instance of this class is constructed using the java.sql.ResultSet to be converted and a ResultSetHandler to handle the events that are dispatched during the process. Depending on the type of ResultSetHandler that is used, different serialisations can be produced.

Author:
The OGSA-DAI Project Team
See Also:
ResultSetHandler

Field Summary
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement.
private  java.lang.StringBuffer mBlock
          The string buffer that holds the next block of data to be returned.
private  boolean mFooter
          Flag used to track whether the footer has been handled.
private  ResultSetHandler mHandler
          The handler for converting different parts of the result set.
private  boolean mHeader
          Flag used to track whether the header has been handled.
private  java.sql.ResultSet mResultSet
          The result set that is being converted into blocks.
 
Constructor Summary
ResultSetConverter(java.sql.ResultSet results, ResultSetHandler handler)
          Creates a new ResultSetConverter.
 
Method Summary
protected  java.lang.StringBuffer createStringBuffer()
          Creates and returns a string buffer used for storing the string representation of the next block of data.
 boolean hasNext()
          Indicates whether or not there are any more blocks of data to be read.
 java.lang.String next()
          Gets the next block of converted data.
private  void processNextBlock()
          Generates the next block of data from the result set and saves a reference to it using mBlock.
private  void processRow(java.lang.StringBuffer strbuf)
          Processes the current row of the result set, adding the converted data to the string buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT_NOTICE

private static final java.lang.String COPYRIGHT_NOTICE
Copyright statement.

See Also:
Constant Field Values

mResultSet

private final java.sql.ResultSet mResultSet
The result set that is being converted into blocks.


mHandler

private final ResultSetHandler mHandler
The handler for converting different parts of the result set.


mBlock

private java.lang.StringBuffer mBlock
The string buffer that holds the next block of data to be returned.


mHeader

private boolean mHeader
Flag used to track whether the header has been handled.


mFooter

private boolean mFooter
Flag used to track whether the footer has been handled.

Constructor Detail

ResultSetConverter

public ResultSetConverter(java.sql.ResultSet results,
                          ResultSetHandler handler)
Creates a new ResultSetConverter.

Parameters:
results - result set to convert
handler - handler to use for converting the result set
Throws:
java.lang.IllegalArgumentException - if results or handler are null.
Method Detail

hasNext

public boolean hasNext()
                throws ResultSetHandlerException
Indicates whether or not there are any more blocks of data to be read.

Returns:
true if there are, false otherwise.
Throws:
ResultSetHandlerException - If a problem occurs when accessing the ResultSet.

next

public java.lang.String next()
                      throws ResultSetHandlerException
Gets the next block of converted data.

Returns:
a String representing data
Throws:
java.util.NoSuchElementException - If there are no more blocks of data.
ResultSetHandlerException - If a problem occurs when accessing the ResultSet.

processNextBlock

private void processNextBlock()
                       throws ResultSetHandlerException
Generates the next block of data from the result set and saves a reference to it using mBlock. If there are no more blocks then the reference is set to null.

Throws:
ResultSetHandlerException - If a problem occurs when accessing the ResultSet.

processRow

private void processRow(java.lang.StringBuffer strbuf)
                 throws ResultSetHandlerException
Processes the current row of the result set, adding the converted data to the string buffer.

Throws:
ResultSetHandlerException - If a problem occurs when accessing the ResultSet or writing data to the byte stream.

createStringBuffer

protected java.lang.StringBuffer createStringBuffer()
Creates and returns a string buffer used for storing the string representation of the next block of data. This method has protected accessibility so that it can be overridden for testing purposes.

Returns:
a byte stream