KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > webman > mainint > TKComponentIterator


1 package com.teamkonzept.webman.mainint;
2
3 import com.teamkonzept.lib.*;
4
5 import java.sql.*;
6
7 public class TKComponentIterator implements TKListIterator {
8
9     TKListIterator oldIterator;
10     String JavaDoc 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, TKDBResult rsDR, TKListIterator oldIterator, String JavaDoc listName )
18     {
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 )), "PRESENTATION_COMPONENT_IDX" );
25         this.idxDR = getCompIdx( (TKDBResultRow)(rsDR.get( currDR )), "SRC_PRESENTATION_COMPONENT_IDX" );
26     }
27     
28     public int getCompIdx( TKDBResultRow row, String JavaDoc name )
29     {
30         if( row != null ) {
31             String JavaDoc sVal = (String JavaDoc) row.getColumn( name );
32             int val = Integer.parseInt( sVal );
33             return val;
34         }
35         else return -1;
36     }
37     
38     public boolean apply( TKTemplate template, int i, String JavaDoc currListName )
39     {
40         if( currListName.equalsIgnoreCase( listName ) ) {
41             try {
42                 if( !TKDBTemplate.prepareTemplate( rsPC,template ) ) return false;
43                 
44                 int idxPC = rsPC.getInt( "PRESENTATION_COMPONENT_IDX" );
45                 if( (idxPC == idxDC) ) { // DC ist auch dran
46
if( !TKDBTemplate.prepareTemplate( (TKDBResultRow) rsDC.get( currDC ), template ) ) throw new Error JavaDoc();
47                     this.idxDC = getCompIdx( (TKDBResultRow)(rsDC.get( ++currDC )), "PRESENTATION_COMPONENT_IDX" );
48                     template.set( "FILLED", "Yes" );
49                 }
50                 else if( idxPC == idxDR ) { // DR ist auch dran
51
if( !TKDBTemplate.prepareTemplate( (TKDBResultRow) rsDR.get( currDR ), template ) ) throw new Error JavaDoc();
52                     this.idxDR = getCompIdx( (TKDBResultRow)(rsDR.get( ++currDR )), "SRC_PRESENTATION_COMPONENT_IDX" );
53                     template.set( "FILLED", "Yes" );
54                 }
55             }
56             catch( SQLException e ) {
57                 throw new Error JavaDoc( e.getMessage() );
58             }
59             return true;
60         }
61         else if( oldIterator != null ) {
62             return oldIterator.apply( template, i, currListName );
63         }
64         else {
65             return false;
66         }
67     }
68 }
69
70
Popular Tags