package mypackage;
import java.sql.ResultSet;
/**
* Implementation of a DocumentBuilder that extracts the data
* needed to support the getValue method from the ResultSet
* provided in the constructor. The field code it accepts
* in the getValue method, must match a field in the ResultSet
* provided. Otherwise, <code>null</code> is used.
**/
public class ResultSetDocumentBuilder extends DocumentBuilder {
private ResultSet model;
/**
* Creates a new instance using the ResultSet parameter as the "data"
* source, and the template as the document template.
**/
// Line 20
public ResultSetDocumentBuilder(ResultSet model, String template) {
super(template); // Line 21
this.model = model; // Line 23
}
/**
* returns String value representing data associated with field code.
* in this implementation, the field code is the name of a field in
* the ResultSet provided. If no value is returned from the ResultSet,
* or the field does not exist, <code>null</code> is returned.
**/
public String getValue(String fieldCode) {
String ret = null;
try{
ret = model.getString(fieldCode); // Line 35
}
catch(Exception e){
ret = null;
}
finally{
return ret;
}
}
}
End of Listing