WebManThread.java :  » Content-Management-System » webman » com » teamkonzept » webman » mainint » Java Open Source

Java Open Source » Content Management System » webman 
webman » com » teamkonzept » webman » mainint » WebManThread.java
package com.teamkonzept.webman.mainint;

import com.teamkonzept.webman.*;
import com.teamkonzept.webman.db.*;

import com.teamkonzept.webman.mainint.db.*;
import com.teamkonzept.webman.mainint.db.queries.*;

import com.teamkonzept.field.*;
import com.teamkonzept.field.db.*;
import com.teamkonzept.field.db.queries.*;

import com.teamkonzept.publishing.markups.*;

import com.teamkonzept.db.*;
import com.teamkonzept.web.*;
import com.teamkonzept.lib.*;
import com.teamkonzept.webman.mainint.events.CachedEventDistributor;
import com.teamkonzept.webman.mainint.events.ParameterTypes;
import com.teamkonzept.webman.mainint.events.*;

import com.oroinc.text.regex.*;

import de.webman.util.log4j.WebmanCategory;
import de.webman.acl.ACEventDistributor;
import de.webman.generator.GREventDistributor;
import de.webman.content.CEEventDistributor;
import de.webman.template.TEEventDistributor;
import de.webman.form.CTEventDistributor;
import de.webman.sitetree.STEventDistributor;
import de.webman.duplication.DUEventDistributor;
import de.webman.documenttype.DTEventDistributor;
import de.webman.config.COEventDistributor;


import java.io.*;
import java.util.*;
import java.sql.*;

/**
 * zentrale Eventverteilungsklasse
 * enthaelt auch einiges an Initialisierungsroutinen
 * @author  $Author: alex $
 * @version $Revision: 1.61 $
 */
public class WebManThread extends CachedEventDistributor implements FrameConstants, DatabaseDefaults, ParameterTypes
{  
    /**
     * Liste aller Feldklassen
     **/
  private static TKVector classVector= null;

    static boolean initialized = false;

    /** Singleton Instanz */
    private static WebManThread instance = new WebManThread();

  /** Log4J Kategorie */
  private static WebmanCategory cat = (WebmanCategory)WebmanCategory.getInstance(WebManThread.class.getName());

    /**
     *  Zugriff auf Singleton
     * @return Singleton Instanz
     */
    public static WebManThread getInstance()
    {
      return instance;
    }

    public static TKVector getClassVector()
    {
      try
      {
      if(classVector == null)
        classVector = registerAllFields();
    }
    catch (Throwable t)
    {
      cat.fatal("registerFields", t);
    }
      return classVector;
    }


    private WebManThread()
    {
      /*try
      {
      TKWebmanDBManager.initConnection("/webmandb.ini", !initialized);
      }
      catch (TKException e)
      {
        cat.error("Exception during pre init : " , e);
      }             */
      // EventHandler registrieren
      addEventHandler(StartEventHandler.getInstance());
      addEventHandler(EmptyEventHandler.getInstance());
      addEventHandler(new CEEventDistributor());
      addEventHandler(new COEventDistributor());
      addEventHandler(new CTEventDistributor());
      addEventHandler(new MEEventHandler());
      addEventHandler(new DTEventDistributor());
      addEventHandler(new TEEventDistributor());
      addEventHandler(new STEventDistributor());
      addEventHandler(new ACEventDistributor());
      addEventHandler(new GREventDistributor());
      addEventHandler(new DUEventDistributor());
      addEventHandler(new FrameOrientationHandler());
      addEventHandler(WebmanExceptionHandler.getInstance());
    }
    
    /**
      returns true, because it is the top level handler
    */
    public boolean isHandler(TKEvent evt)
    {
      return true;
    }

    /**
     * Creates an event object.
     *
     * @param http the responsible HTTP interface.
     * @return an event object.
     */
    public TKEvent createEvent (TKHttpInterface http)
    {
        return new TKUserEvent(http);
    }

  /**
    villeicht noch irgendwo hin verschieben, gehrt das nicht eher ins field Package ???
  */
  public static TKVector registerAllFields() throws TKException
  {
    try
    {
      //---- Die Tabelle FIELD_CLASS ausleisen und in einem Vector speichern ----//
      TKQuery q = TKWebmanDBManager.newQuery(TKDBFormFieldClassGet.class);
      q.execute();
      ResultSet rs = q.fetchResultSet();

      //---- FIELD_TYPE = CLASS_ID  FIELD_CLASS = PATH ----//
      classVector = new TKVector();
      while(rs.next()){
        String rowArray[] = { rs.getString("FIELD_TYPE"), rs.getString("FIELD_CLASS") };
        classVector.addElement(rowArray);
      }

      //---- Alle Fields registrieren ----//
      for (int i=0; i < classVector.size(); i++) {
        Object element = classVector.elementAt(i);
        String classInfoArray[] = (String[]) element;
        TKFieldRegistry.registry.registerClass(classInfoArray[0], classInfoArray[1]);
      }
    }
    catch (SQLException e)
    {
      throw WebmanExceptionHandler.getException(e);
    }
    return classVector;
  }


  public void traceHttpEnv (TKEvent evt)
  {
    cat.info( "getOwnName() = "+evt.getHttpInterface().getOwnName());
    cat.info( "getOwnURL() = "+evt.getHttpInterface().getOwnURL());
    cat.info( "getOwnPath() = "+evt.getHttpInterface().getOwnPath());
    cat.info( "getDocumentRoot() = "+evt.getHttpInterface().getDocumentRoot());
    cat.info( "getServerName() = "+evt.getHttpInterface().getServerName());
    cat.info( "getRemoteUser() = "+evt.getHttpInterface().getRemoteUser());
  }


    public static synchronized void init(TKEvent evt ) throws TKException{
        if (initialized)
            return;
        //TKWebmanInit.init(evt.getHttpInterface().getDocumentRoot());
        TKUploadField.initStaticsForUpload(evt.getHttpInterface().getDocumentRoot());
  

        /*
  de.webman.generator.GeneratorContext.setupSharing (evt.getHttpInterface().getDocumentRoot()+File.separator+"servlets"+File.separator+
              "preview.ini");      auf Properties umgestellt */
    if(classVector == null)
      classVector = registerAllFields();
    TKMarkupAdmin.setup();
    initialized = true;
  }

  public void handleEvent( TKEvent evt) throws TKException
  {
    try
    {
      cat.access("Event : " + evt.getName());
      TKWebmanDBManager.initConnection("/webmandb.ini", !initialized);
      TKPrepQuery.enableCleanup();
      if (!initialized)
        init(evt);
      // ist der request vollstaendig da ?
      evt.checkChecker();
      super.handleEvent(evt);
    }
    catch (Throwable t)
    {
      boolean close = false;
      // CHANGE !!

      if (t instanceof TKException)
        close = WebmanExceptionHandler.handleException((TKException)t, evt);
      else
        close = WebmanExceptionHandler.handleException(WebmanExceptionHandler.getException(t), evt);
      // t.printStackTrace(System.err);
      deRegister( close );
      initialized = false;
      // deregistrieren nur bei SQL Exception !!!

    }
    deRegister( false );
  }

  void deRegister(boolean close) throws TKDatabaseException
  {
    try
    {
      TKWebmanDBManager.deregister( close );
    }
    catch (SQLException e)
    {
      throw new TKDatabaseException(e.toString(),UNDEFINED, NORMAL_SEVERITY, false,e);
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.