KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > generator > ReferenceTypeStatics


1 package de.webman.generator;
2
3 import com.teamkonzept.db.*;
4 import com.teamkonzept.lib.*;
5 import com.teamkonzept.webman.db.*;
6 import de.webman.generator.db.queries.*;
7
8 import java.sql.*;
9
10 /**
11     Statische Daten und Methoden der Klasse ReferenceType
12     verwaltet die Dokumenttypen
13     * @author $Author: alex $
14     * @version $Revision: 1.2 $
15 */

16 public class ReferenceTypeStatics
17 {
18
19     /**
20         Verweis zurück auf den aktuellen statischen Kontext des laufenden Threads
21     */

22     private GeneratorContext context;
23
24     /**
25         verwaltet eine ReferenceType pro Referenz-Komponente aller Presentation
26         Key := Integer( presentationId )
27         Value = Hashtable mit (
28             Key := Integer( presComponentIdx )
29             Value := ReferenceType;
30         )
31     */

32     private TKHashtable presentations;
33
34     public ReferenceTypeStatics (GeneratorContext context) {
35
36         this.context = context != null ? context : GeneratorContext.setup ();
37         this.presentations = null;
38     }
39
40     /**
41         Holt alle ReferenzTypes aller Presentations
42         aus der DB und verwaltet sie
43         in der Hashtable presetations
44     */

45     public void getTypes()
46     {
47         try {
48             TKQuery q = TKWebmanDBManager.newQuery(GenRefTypes.class);
49             q.execute();
50             ResultSet rs = q.fetchResultSet();
51
52             TKHashtable lastHash = null;
53             ReferenceType lastType = null;
54             int lastPresId = -1;
55             int lastIdx = -1;
56
57             presentations = new TKHashtable();
58
59             while( rs.next() ) {
60                 int newPresId = rs.getInt( "PRESENTATION_ID" );
61                 if( lastPresId != newPresId ) {
62                     Integer JavaDoc newKey = new Integer JavaDoc( newPresId );
63                     lastHash = (TKHashtable) presentations.get( newKey );
64                     if( lastHash == null ) {
65                         lastHash = new TKHashtable();
66                         presentations.put( newKey, lastHash );
67                     }
68                     lastIdx = -1;
69                 }
70                 int newIdx = rs.getInt( "PRESENTATION_COMPONENT_IDX" );
71                 if( lastIdx != newIdx ) {
72                     Integer JavaDoc newKey = new Integer JavaDoc( newIdx );
73                     lastType = (ReferenceType) lastHash.get( newKey );
74                     if( lastType == null ) {
75                         lastType = new ReferenceType(context);
76                         lastHash.put( newKey, lastType );
77                     }
78                 }
79                 lastType.addType( rs.getInt( "SUB_PRESENTATION_ID" ) );
80             }
81         }
82         catch( SQLException e ) {
83             throw new TKSQLError( e.getMessage(), e );
84         }
85
86     }
87
88     /**
89         liefert das ReferenceType-Objekt einer Komponente einer Presentation
90     */

91     public final ReferenceType getType( int presId, int presIdx )
92     {
93         if( presentations == null ) return null;
94         TKHashtable v = (TKHashtable)presentations.get( new Integer JavaDoc( presId ) );
95         if( v == null )
96             return null;
97         return (ReferenceType)v.get( new Integer JavaDoc( presIdx ) );
98     }
99
100     /**
101         ueberprueft, ob die Presentation mit PresentationId destPresId eine
102         gueltige Content-Quelle fuer die srcPresIdx-te Komponente der Presentation
103         mit Id srcPresId ist
104     */

105     public final boolean isValidType( int srcPresId, int srcPresIdx, int destPresId )
106     {
107         ReferenceType t = getType( srcPresId, srcPresIdx );
108         return ((t != null) && t.contains( destPresId ));
109     }
110 }
111
Popular Tags