001: package com.teamkonzept.webman.mainint;
002:
003: import com.teamkonzept.webman.*;
004: import com.teamkonzept.webman.db.*;
005:
006: import com.teamkonzept.webman.mainint.db.*;
007: import com.teamkonzept.webman.mainint.db.queries.*;
008:
009: import com.teamkonzept.field.*;
010: import com.teamkonzept.field.db.*;
011: import com.teamkonzept.field.db.queries.*;
012:
013: import com.teamkonzept.publishing.markups.*;
014:
015: import com.teamkonzept.db.*;
016: import com.teamkonzept.web.*;
017: import com.teamkonzept.lib.*;
018: import com.teamkonzept.webman.mainint.events.CachedEventDistributor;
019: import com.teamkonzept.webman.mainint.events.ParameterTypes;
020: import com.teamkonzept.webman.mainint.events.*;
021:
022: import com.oroinc.text.regex.*;
023:
024: import de.webman.util.log4j.WebmanCategory;
025: import de.webman.acl.ACEventDistributor;
026: import de.webman.generator.GREventDistributor;
027: import de.webman.content.CEEventDistributor;
028: import de.webman.template.TEEventDistributor;
029: import de.webman.form.CTEventDistributor;
030: import de.webman.sitetree.STEventDistributor;
031: import de.webman.duplication.DUEventDistributor;
032: import de.webman.documenttype.DTEventDistributor;
033: import de.webman.config.COEventDistributor;
034:
035: import java.io.*;
036: import java.util.*;
037: import java.sql.*;
038:
039: /**
040: * zentrale Eventverteilungsklasse
041: * enthaelt auch einiges an Initialisierungsroutinen
042: * @author $Author: alex $
043: * @version $Revision: 1.61 $
044: */
045: public class WebManThread extends CachedEventDistributor implements
046: FrameConstants, DatabaseDefaults, ParameterTypes {
047: /**
048: * Liste aller Feldklassen
049: **/
050: private static TKVector classVector = null;
051:
052: static boolean initialized = false;
053:
054: /** Singleton Instanz */
055: private static WebManThread instance = new WebManThread();
056:
057: /** Log4J Kategorie */
058: private static WebmanCategory cat = (WebmanCategory) WebmanCategory
059: .getInstance(WebManThread.class.getName());
060:
061: /**
062: * Zugriff auf Singleton
063: * @return Singleton Instanz
064: */
065: public static WebManThread getInstance() {
066: return instance;
067: }
068:
069: public static TKVector getClassVector() {
070: try {
071: if (classVector == null)
072: classVector = registerAllFields();
073: } catch (Throwable t) {
074: cat.fatal("registerFields", t);
075: }
076: return classVector;
077: }
078:
079: private WebManThread() {
080: /*try
081: {
082: TKWebmanDBManager.initConnection("/webmandb.ini", !initialized);
083: }
084: catch (TKException e)
085: {
086: cat.error("Exception during pre init : " , e);
087: } */
088: // EventHandler registrieren
089: addEventHandler(StartEventHandler.getInstance());
090: addEventHandler(EmptyEventHandler.getInstance());
091: addEventHandler(new CEEventDistributor());
092: addEventHandler(new COEventDistributor());
093: addEventHandler(new CTEventDistributor());
094: addEventHandler(new MEEventHandler());
095: addEventHandler(new DTEventDistributor());
096: addEventHandler(new TEEventDistributor());
097: addEventHandler(new STEventDistributor());
098: addEventHandler(new ACEventDistributor());
099: addEventHandler(new GREventDistributor());
100: addEventHandler(new DUEventDistributor());
101: addEventHandler(new FrameOrientationHandler());
102: addEventHandler(WebmanExceptionHandler.getInstance());
103: }
104:
105: /**
106: returns true, because it is the top level handler
107: */
108: public boolean isHandler(TKEvent evt) {
109: return true;
110: }
111:
112: /**
113: * Creates an event object.
114: *
115: * @param http the responsible HTTP interface.
116: * @return an event object.
117: */
118: public TKEvent createEvent(TKHttpInterface http) {
119: return new TKUserEvent(http);
120: }
121:
122: /**
123: villeicht noch irgendwo hin verschieben, gehört das nicht eher ins field Package ???
124: */
125: public static TKVector registerAllFields() throws TKException {
126: try {
127: //---- Die Tabelle FIELD_CLASS ausleisen und in einem Vector speichern ----//
128: TKQuery q = TKWebmanDBManager
129: .newQuery(TKDBFormFieldClassGet.class);
130: q.execute();
131: ResultSet rs = q.fetchResultSet();
132:
133: //---- FIELD_TYPE = CLASS_ID FIELD_CLASS = PATH ----//
134: classVector = new TKVector();
135: while (rs.next()) {
136: String rowArray[] = { rs.getString("FIELD_TYPE"),
137: rs.getString("FIELD_CLASS") };
138: classVector.addElement(rowArray);
139: }
140:
141: //---- Alle Fields registrieren ----//
142: for (int i = 0; i < classVector.size(); i++) {
143: Object element = classVector.elementAt(i);
144: String classInfoArray[] = (String[]) element;
145: TKFieldRegistry.registry.registerClass(
146: classInfoArray[0], classInfoArray[1]);
147: }
148: } catch (SQLException e) {
149: throw WebmanExceptionHandler.getException(e);
150: }
151: return classVector;
152: }
153:
154: public void traceHttpEnv(TKEvent evt) {
155: cat.info("getOwnName() = "
156: + evt.getHttpInterface().getOwnName());
157: cat.info("getOwnURL() = " + evt.getHttpInterface().getOwnURL());
158: cat.info("getOwnPath() = "
159: + evt.getHttpInterface().getOwnPath());
160: cat.info("getDocumentRoot() = "
161: + evt.getHttpInterface().getDocumentRoot());
162: cat.info("getServerName() = "
163: + evt.getHttpInterface().getServerName());
164: cat.info("getRemoteUser() = "
165: + evt.getHttpInterface().getRemoteUser());
166: }
167:
168: public static synchronized void init(TKEvent evt)
169: throws TKException {
170: if (initialized)
171: return;
172: //TKWebmanInit.init(evt.getHttpInterface().getDocumentRoot());
173: TKUploadField.initStaticsForUpload(evt.getHttpInterface()
174: .getDocumentRoot());
175:
176: /*
177: de.webman.generator.GeneratorContext.setupSharing (evt.getHttpInterface().getDocumentRoot()+File.separator+"servlets"+File.separator+
178: "preview.ini"); auf Properties umgestellt */
179: if (classVector == null)
180: classVector = registerAllFields();
181: TKMarkupAdmin.setup();
182: initialized = true;
183: }
184:
185: public void handleEvent(TKEvent evt) throws TKException {
186: try {
187: cat.access("Event : " + evt.getName());
188: TKWebmanDBManager.initConnection("/webmandb.ini",
189: !initialized);
190: TKPrepQuery.enableCleanup();
191: if (!initialized)
192: init(evt);
193: // ist der request vollstaendig da ?
194: evt.checkChecker();
195: super .handleEvent(evt);
196: } catch (Throwable t) {
197: boolean close = false;
198: // CHANGE !!
199:
200: if (t instanceof TKException)
201: close = WebmanExceptionHandler.handleException(
202: (TKException) t, evt);
203: else
204: close = WebmanExceptionHandler.handleException(
205: WebmanExceptionHandler.getException(t), evt);
206: // t.printStackTrace(System.err);
207: deRegister(close);
208: initialized = false;
209: // deregistrieren nur bei SQL Exception !!!
210:
211: }
212: deRegister(false);
213: }
214:
215: void deRegister(boolean close) throws TKDatabaseException {
216: try {
217: TKWebmanDBManager.deregister(close);
218: } catch (SQLException e) {
219: throw new TKDatabaseException(e.toString(), UNDEFINED,
220: NORMAL_SEVERITY, false, e);
221: }
222: }
223: }
|