00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package dochelper;
00011
00012 import dochelper.exceptions.IllegalParamterTypeException;
00013 import dochelper.exceptions.InitializationException;
00014 import dochelper.exceptions.InvalidValueException;
00015 import dochelper.exceptions.MissingArgumentException;
00016 import dochelper.exceptions.ResourceUnavailableException;
00017 import java.sql.SQLException;
00018 import java.util.ArrayList;
00019 import java.util.HashMap;
00020 import java.util.List;
00021
00030 public abstract class AbstractTableRecordSet implements RecordSet {
00031
00033 protected HashMap< String, Object > params = new HashMap< String, Object >();
00034
00036 private ArrayList<DocPattern> patterns;
00037
00039 private String name;
00040
00041
00042
00048 protected abstract void initImpl() throws SQLException, ResourceUnavailableException;
00049
00056 protected abstract void checkParamsImpl() throws MissingArgumentException, InvalidValueException, ResourceUnavailableException;
00057
00068 protected abstract List<Record> getRecords() throws ResourceUnavailableException, SQLException;
00069
00070
00083 public void setParam(String paramName, Object value) throws IllegalParamterTypeException {
00084
00085 if (value instanceof String || value instanceof DocumentSection)
00086 params.put(paramName, value);
00087 else
00088 throw new IllegalParamterTypeException(paramName);
00089 }
00090
00102 public void checkParams() throws InvalidValueException, MissingArgumentException, ResourceUnavailableException {
00103 checkParamsImpl();
00104 }
00105
00114 public void init() throws InitializationException, ResourceUnavailableException {
00115
00116 try {
00117 initImpl();
00118 }
00119 catch (SQLException sqe) {
00120 throw new InitializationException(sqe.getMessage());
00121 }
00122 }
00123
00141 public ResultNode execute(ResultNode doc) throws ResourceUnavailableException {
00142
00143 try {
00144 List<Record> records = this.getRecords();
00145
00146
00147 ResultNode result = new ResultNode(null, params, "RecordSet");
00148
00149 if (records != null) {
00150
00151 for (Record record : records) {
00152
00153 result.addChild(record.execute(patterns));
00154 }
00155 }
00156
00157 return result;
00158 }
00159 catch (SQLException sqle) {
00160 throw new RuntimeException(sqle);
00161 }
00162 }
00163
00169 public String getName() {
00170 return name;
00171 }
00172
00173 public void setName(String name) {
00174 this.name = name;
00175 }
00176
00183 public void addPattern(DocPattern pattern) {
00184
00185 if (this.patterns == null)
00186 this.patterns = new ArrayList<DocPattern>();
00187
00188 this.patterns.add(pattern);
00189 }
00190
00195 public void clearPatterns() {
00196 this.patterns = new ArrayList<DocPattern>();
00197 }
00198 }