KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > webman > TKWMContentSelectorReg


1 package com.teamkonzept.webman;
2
3 import com.teamkonzept.web.*;
4 import com.teamkonzept.webman.db.*;
5 import com.teamkonzept.webman.db.queries.*;
6 import com.teamkonzept.db.*;
7 import com.teamkonzept.lib.*;
8
9 import java.sql.*;
10
11 public class TKWMContentSelectorReg extends TKClassRegistry {
12
13     protected TKHashtable resultTypes = new TKHashtable();
14
15     public void registerClass( String JavaDoc selectionType, String JavaDoc selectionClass, int resultType )
16     {
17         super.registerClass( selectionType, selectionClass );
18         resultTypes.put( selectionType, Integer.toString( resultType ) );
19     }
20
21     public final TKWMContentSelector getSelector( String JavaDoc selectionType )
22     {
23         try {
24             return (TKWMContentSelector) get( selectionType );
25         }
26         catch( Throwable JavaDoc t ) {
27             throw new Error JavaDoc( t.getMessage() );
28         }
29     }
30
31     public void _edit( TKHTMLTemplate t, String JavaDoc selectionType, int contentNodeId, String JavaDoc selectionData )
32     {
33         String JavaDoc resultType = (String JavaDoc) resultTypes.get( selectionType );
34         TKHashtable dummyParams = new TKHashtable(4);
35         dummyParams.put( "SEL_TYPE", selectionType );
36         dummyParams.put( "RES_TYPE", resultType );
37         dummyParams.put( "NODE_ID", Integer.toString( contentNodeId ) );
38         if( selectionData != null ) dummyParams.put( "SEL_DATA", selectionData );
39
40         _modify( t, selectionType, TKWMContentSelector.ACTION_INIT, dummyParams );
41     }
42
43     public void _modify( TKHTMLTemplate t, String JavaDoc selectionType, String JavaDoc action, TKHashtable params )
44     {
45         getSelector( selectionType ).modifySelection( t, action, params );
46     }
47
48     public String JavaDoc _getData( String JavaDoc selectionType, TKHashtable params )
49     {
50         return getSelector( selectionType ).getSelectionData( params );
51     }
52
53     public TKVector _select( String JavaDoc selectionType, String JavaDoc selectionData, int contentNodeId )
54     {
55         return getSelector( selectionType ).doSelection( selectionData, contentNodeId );
56     }
57
58     //*******************************************************************
59
protected static TKWMContentSelectorReg registry = null;
60     protected static boolean initialized = false;
61
62     public static final void edit( TKHTMLTemplate t, String JavaDoc selectionType, int contentNodeId, String JavaDoc selectionData )
63     {
64         if( !initialized ) initialize();
65         registry._edit( t, selectionType, contentNodeId, selectionData );
66     }
67
68     public static final void edit( TKHTMLTemplate t, String JavaDoc selectionType, int contentNodeId )
69     {
70         edit( t, selectionType, contentNodeId, null );
71     }
72
73     public static final void modify( TKHTMLTemplate t, String JavaDoc selectionType, String JavaDoc action, TKHashtable params )
74     {
75         if( !initialized ) initialize();
76         registry._modify( t, selectionType, action, params );
77     }
78
79     public static final String JavaDoc getData( String JavaDoc selectionType, TKHashtable params )
80     {
81         if( !initialized ) initialize();
82         return registry._getData( selectionType, params );
83     }
84
85     public static final TKVector select( String JavaDoc selectionType, String JavaDoc selectionData, int contentNodeId )
86     {
87         if( !initialized ) initialize();
88         return registry._select( selectionType, selectionData, contentNodeId );
89     }
90
91     public static final synchronized void initialize()
92     {
93         if( initialized ) return;
94
95         initialized = true;
96         registry = new TKWMContentSelectorReg();
97
98         try {
99             TKQuery q = TKWebmanDBManager.newQuery(TKDBContSelClassGetAll.class);
100             q.execute();
101             ResultSet rs = q.fetchResultSet();
102
103             while( rs.next() ) {
104                 registry.registerClass(
105                     rs.getString("SELECTION_TYPE"),
106                     rs.getString("SELECTION_CLASS"),
107                     rs.getInt("RESULT_TYPE")
108                 );
109             }
110         }
111         catch( SQLException e ) {
112             throw new TKSQLError( e.getMessage(), e );
113         }
114     }
115 }
Popular Tags