private Element produceMsg(ResultSet object, int endRow) throws JDOMException, SQLException {
// -----------------------------------
// Create the QueryResults element ...
// -----------------------------------
Element resultsElement = new Element(TagNames.Elements.QUERY_RESULTS);
// -----------------------------------
// Add the Select (header) element ...
// -----------------------------------
try {
ResultSetMetaData rmdata = object.getMetaData();
List identList = new ArrayList(rmdata.getColumnCount());
for ( int i = 1; i <= rmdata.getColumnCount(); i++ ) {
identList.add(new ElementSymbol(rmdata.getColumnName(i)));
}
Select select = new Select(identList);
resultsElement = produceMsg(select, rmdata, resultsElement);
// -------------------------
// Add the Table element ...
// -------------------------
resultsElement.addContent(new Element(TagNames.Elements.TABLE));
Element tableElement = resultsElement.getChild(TagNames.Elements.TABLE);
int rowCount = 0;
int colCount = rmdata.getColumnCount();
while ( object.next() && (object.getRow() <= endRow) ) {
// -------------------------
// Add the ROW element ...
// -------------------------
Element rowElement = new Element(TagNames.Elements.TABLE_ROW);
for ( int i = 1; i <= colCount; i++ ) {
// -------------------------
// Add the Cell element ...
// -------------------------
Element cellElement = new Element(TagNames.Elements.TABLE_CELL);
Object cellValue = object.getObject(i);
if ( cellValue != null ) {
cellElement = produceMsg(cellValue, cellElement);
} else {
cellElement = cellElement.addContent(TagNames.Elements.NULL);
}
rowElement.addContent(cellElement);
}
tableElement.addContent(rowElement);
rowCount++;