KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.teamkonzept.webman.mainint;
2
3 import com.teamkonzept.webman.*;
4 import com.teamkonzept.webman.db.*;
5
6 import com.teamkonzept.webman.mainint.db.*;
7 import com.teamkonzept.webman.mainint.db.queries.*;
8
9 import com.teamkonzept.field.*;
10 import com.teamkonzept.field.db.*;
11 import com.teamkonzept.field.db.queries.*;
12
13 import com.teamkonzept.publishing.markups.*;
14
15 import com.teamkonzept.db.*;
16 import com.teamkonzept.web.*;
17 import com.teamkonzept.lib.*;
18 import com.teamkonzept.webman.mainint.events.CachedEventDistributor;
19 import com.teamkonzept.webman.mainint.events.ParameterTypes;
20 import com.teamkonzept.webman.mainint.events.*;
21
22 import com.oroinc.text.regex.*;
23
24 import de.webman.util.log4j.WebmanCategory;
25 import de.webman.acl.ACEventDistributor;
26 import de.webman.generator.GREventDistributor;
27 import de.webman.content.CEEventDistributor;
28 import de.webman.template.TEEventDistributor;
29 import de.webman.form.CTEventDistributor;
30 import de.webman.sitetree.STEventDistributor;
31 import de.webman.duplication.DUEventDistributor;
32 import de.webman.documenttype.DTEventDistributor;
33 import de.webman.config.COEventDistributor;
34
35
36 import java.io.*;
37 import java.util.*;
38 import java.sql.*;
39
40 /**
41  * zentrale Eventverteilungsklasse
42  * enthaelt auch einiges an Initialisierungsroutinen
43  * @author $Author: alex $
44  * @version $Revision: 1.61 $
45  */

46 public class WebManThread extends CachedEventDistributor implements FrameConstants, DatabaseDefaults, ParameterTypes
47 {
48     /**
49      * Liste aller Feldklassen
50      **/

51     private static TKVector classVector= null;
52
53     static boolean initialized = false;
54
55     /** Singleton Instanz */
56     private static WebManThread instance = new WebManThread();
57
58     /** Log4J Kategorie */
59     private static WebmanCategory cat = (WebmanCategory)WebmanCategory.getInstance(WebManThread.class.getName());
60
61     /**
62      * Zugriff auf Singleton
63      * @return Singleton Instanz
64      */

65     public static WebManThread getInstance()
66     {
67         return instance;
68     }
69
70     public static TKVector getClassVector()
71     {
72         try
73         {
74             if(classVector == null)
75                 classVector = registerAllFields();
76         }
77         catch (Throwable JavaDoc t)
78         {
79             cat.fatal("registerFields", t);
80         }
81         return classVector;
82     }
83
84
85     private WebManThread()
86     {
87         /*try
88         {
89             TKWebmanDBManager.initConnection("/webmandb.ini", !initialized);
90         }
91         catch (TKException e)
92         {
93             cat.error("Exception during pre init : " , e);
94         } */

95         // EventHandler registrieren
96
addEventHandler(StartEventHandler.getInstance());
97         addEventHandler(EmptyEventHandler.getInstance());
98         addEventHandler(new CEEventDistributor());
99         addEventHandler(new COEventDistributor());
100         addEventHandler(new CTEventDistributor());
101         addEventHandler(new MEEventHandler());
102         addEventHandler(new DTEventDistributor());
103         addEventHandler(new TEEventDistributor());
104         addEventHandler(new STEventDistributor());
105         addEventHandler(new ACEventDistributor());
106         addEventHandler(new GREventDistributor());
107         addEventHandler(new DUEventDistributor());
108         addEventHandler(new FrameOrientationHandler());
109         addEventHandler(WebmanExceptionHandler.getInstance());
110     }
111     
112     /**
113         returns true, because it is the top level handler
114     */

115     public boolean isHandler(TKEvent evt)
116     {
117         return true;
118     }
119
120     /**
121      * Creates an event object.
122      *
123      * @param http the responsible HTTP interface.
124      * @return an event object.
125      */

126     public TKEvent createEvent (TKHttpInterface http)
127     {
128         return new TKUserEvent(http);
129     }
130
131     /**
132         villeicht noch irgendwo hin verschieben, geh�rt das nicht eher ins field Package ???
133     */

134     public static TKVector registerAllFields() throws TKException
135     {
136         try
137         {
138             //---- Die Tabelle FIELD_CLASS ausleisen und in einem Vector speichern ----//
139
TKQuery q = TKWebmanDBManager.newQuery(TKDBFormFieldClassGet.class);
140             q.execute();
141             ResultSet rs = q.fetchResultSet();
142
143             //---- FIELD_TYPE = CLASS_ID FIELD_CLASS = PATH ----//
144
classVector = new TKVector();
145             while(rs.next()){
146                 String JavaDoc rowArray[] = { rs.getString("FIELD_TYPE"), rs.getString("FIELD_CLASS") };
147                 classVector.addElement(rowArray);
148             }
149
150             //---- Alle Fields registrieren ----//
151
for (int i=0; i < classVector.size(); i++) {
152                 Object JavaDoc element = classVector.elementAt(i);
153                 String JavaDoc classInfoArray[] = (String JavaDoc[]) element;
154                 TKFieldRegistry.registry.registerClass(classInfoArray[0], classInfoArray[1]);
155             }
156         }
157         catch (SQLException e)
158         {
159             throw WebmanExceptionHandler.getException(e);
160         }
161         return classVector;
162     }
163
164
165     public void traceHttpEnv (TKEvent evt)
166     {
167         cat.info( "getOwnName() = "+evt.getHttpInterface().getOwnName());
168         cat.info( "getOwnURL() = "+evt.getHttpInterface().getOwnURL());
169         cat.info( "getOwnPath() = "+evt.getHttpInterface().getOwnPath());
170         cat.info( "getDocumentRoot() = "+evt.getHttpInterface().getDocumentRoot());
171         cat.info( "getServerName() = "+evt.getHttpInterface().getServerName());
172         cat.info( "getRemoteUser() = "+evt.getHttpInterface().getRemoteUser());
173     }
174
175
176     public static synchronized void init(TKEvent evt ) throws TKException{
177         if (initialized)
178             return;
179         //TKWebmanInit.init(evt.getHttpInterface().getDocumentRoot());
180
TKUploadField.initStaticsForUpload(evt.getHttpInterface().getDocumentRoot());
181     
182
183         /*
184     de.webman.generator.GeneratorContext.setupSharing (evt.getHttpInterface().getDocumentRoot()+File.separator+"servlets"+File.separator+
185                             "preview.ini"); auf Properties umgestellt */

186         if(classVector == null)
187             classVector = registerAllFields();
188         TKMarkupAdmin.setup();
189         initialized = true;
190     }
191
192     public void handleEvent( TKEvent evt) throws TKException
193     {
194         try
195         {
196             cat.access("Event : " + evt.getName());
197             TKWebmanDBManager.initConnection("/webmandb.ini", !initialized);
198             TKPrepQuery.enableCleanup();
199             if (!initialized)
200                 init(evt);
201             // ist der request vollstaendig da ?
202
evt.checkChecker();
203             super.handleEvent(evt);
204         }
205         catch (Throwable JavaDoc t)
206         {
207             boolean close = false;
208             // CHANGE !!
209

210             if (t instanceof TKException)
211                 close = WebmanExceptionHandler.handleException((TKException)t, evt);
212             else
213                 close = WebmanExceptionHandler.handleException(WebmanExceptionHandler.getException(t), evt);
214             // t.printStackTrace(System.err);
215
deRegister( close );
216             initialized = false;
217             // deregistrieren nur bei SQL Exception !!!
218

219         }
220         deRegister( false );
221     }
222
223     void deRegister(boolean close) throws TKDatabaseException
224     {
225         try
226         {
227             TKWebmanDBManager.deregister( close );
228         }
229         catch (SQLException e)
230         {
231             throw new TKDatabaseException(e.toString(),UNDEFINED, NORMAL_SEVERITY, false,e);
232         }
233     }
234 }
235
Free Books   Free Magazines  
Popular Tags