01: package com.teamkonzept.webman.mainint;
02:
03: import com.teamkonzept.lib.*;
04:
05: import java.sql.*;
06:
07: public class TKComponentIterator implements TKListIterator {
08:
09: TKListIterator oldIterator;
10: String listName;
11: ResultSet rsPC;
12: TKDBResult rsDC, rsDR;
13: int currDC = 0;
14: int currDR = 0;
15: int idxDC, idxDR;
16:
17: public TKComponentIterator(ResultSet rsPC, TKDBResult rsDC,
18: TKDBResult rsDR, TKListIterator oldIterator, String listName) {
19: this .oldIterator = oldIterator;
20: this .listName = listName;
21: this .rsPC = rsPC;
22: this .rsDC = rsDC;
23: this .rsDR = rsDR;
24: this .idxDC = getCompIdx((TKDBResultRow) (rsDC.get(currDC)),
25: "PRESENTATION_COMPONENT_IDX");
26: this .idxDR = getCompIdx((TKDBResultRow) (rsDR.get(currDR)),
27: "SRC_PRESENTATION_COMPONENT_IDX");
28: }
29:
30: public int getCompIdx(TKDBResultRow row, String name) {
31: if (row != null) {
32: String sVal = (String) row.getColumn(name);
33: int val = Integer.parseInt(sVal);
34: return val;
35: } else
36: return -1;
37: }
38:
39: public boolean apply(TKTemplate template, int i, String currListName) {
40: if (currListName.equalsIgnoreCase(listName)) {
41: try {
42: if (!TKDBTemplate.prepareTemplate(rsPC, template))
43: return false;
44:
45: int idxPC = rsPC.getInt("PRESENTATION_COMPONENT_IDX");
46: if ((idxPC == idxDC)) { // DC ist auch dran
47: if (!TKDBTemplate.prepareTemplate(
48: (TKDBResultRow) rsDC.get(currDC), template))
49: throw new Error();
50: this .idxDC = getCompIdx((TKDBResultRow) (rsDC
51: .get(++currDC)),
52: "PRESENTATION_COMPONENT_IDX");
53: template.set("FILLED", "Yes");
54: } else if (idxPC == idxDR) { // DR ist auch dran
55: if (!TKDBTemplate.prepareTemplate(
56: (TKDBResultRow) rsDR.get(currDR), template))
57: throw new Error();
58: this .idxDR = getCompIdx((TKDBResultRow) (rsDR
59: .get(++currDR)),
60: "SRC_PRESENTATION_COMPONENT_IDX");
61: template.set("FILLED", "Yes");
62: }
63: } catch (SQLException e) {
64: throw new Error(e.getMessage());
65: }
66: return true;
67: } else if (oldIterator != null) {
68: return oldIterator.apply(template, i, currListName);
69: } else {
70: return false;
71: }
72: }
73: }
|