/** @param context */
  private void initialize(ServletContext context) {
    AppServer appServer = AppServerDetector.setAppServerForApplication(context);
    IWMainApplication _iwma = new IWMainApplication(context, appServer);
    _iwma.setApplicationServer(appServer);
    this.iwma = _iwma;
    this.context = context;

    this.startLogManager();

    // IWMainApplication iwma = IWMainApplication.getIWMainApplication(getServletContext());
    // sendStartMessage("Initializing IWMainApplicationStarter");
    String serverInfo = context.getServerInfo();
    String appServerName = appServer.getName();
    String appServerVersion = appServer.getVersion();
    if (appServer.isOfficiallySupported()) {
      if (appServerVersion != null) {
        log.fine(
            "Detected supported application server '"
                + appServerName
                + "' (version "
                + appServerVersion
                + ")");
      } else {
        log.fine("Detected supported application server '" + appServerName + "' (unknown version)");
      }
    } else {
      log.warning(
          "This application server (" + serverInfo + ") is not officially supported by idegaWeb");
    }
    startup();
  }
  private void updateDomainData() {

    String propertyKey = "dataupdate_domain_done";
    String done = iwma.getSettings().getProperty(propertyKey);
    if (done == null) {

      ICDomainHome domainHome = null;
      ICDomain defaultDomain = null;
      try {
        domainHome = (ICDomainHome) IDOLookup.getHome(ICDomain.class);
        defaultDomain = domainHome.findDefaultDomain();

      } catch (FinderException e) {
        if (defaultDomain == null) {
          try {
            defaultDomain = domainHome.findFirstDomain();
            defaultDomain.setType(ICDomain.TYPE_DEFAULT);
            defaultDomain.store();
            iwma.getSettings().setProperty(propertyKey, "true");
          } catch (FinderException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
          }
        }
      } catch (IDOLookupException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
 /** Not Implemented fully */
 public void executeServices(IWMainApplication application) {
   List list = application.getSettings().getServiceClasses();
   if (list != null) {
     Iterator iter = list.iterator();
     while (iter.hasNext()) {
       Class theClass = (Class) iter.next();
       try {
         IWService theService = (IWService) theClass.newInstance();
         theService.startService(application);
       } catch (Exception ex) {
         log.log(Level.WARNING, "Error starting service " + theClass.getName(), ex);
       }
     }
   }
 }
  public void startIdegaWebApplication() {
    long start = System.currentTimeMillis();

    try {
      addToClassPath();
    } catch (Exception e) {
      log.log(Level.WARNING, "Error adding libs to classpath", e);
    }

    // reset singletons
    IWMainApplication.shutdownApplicationServices();
    // enable singletons
    SingletonRepository.start();

    this.setDatabaseProperties();
    registerSystemBeans();
    this.startDatabasePool();

    // set application variables first before setting any properties (ICApplicationBinding table
    // might be created first)
    setApplicationVariables();
    if (!this.iwma.getSettings().getBoolean("use_debug_mode", false)) {
      this.iwma.regData();
    }
    // now set some properties
    this.iwma
        .getSettings()
        .setProperty("last_startup", com.idega.util.IWTimestamp.RightNow().toString());

    // cleaning, maintaining, updating
    if (!this.iwma.isInDatabaseLessMode()) {
      log.fine("Cleaning and updating database...");
      updateStartDataInDatabase();
      log.fine("...cleaning and updating database done");
    }
    startTemporaryBundleStarters();

    startComponentRegistry();

    boolean fileSystemStarted = false;
    if (!this.iwma.isInDatabaseLessMode()) {
      this.iwma.startAccessController();

      fileSystemStarted = this.iwma.startFileSystem(false);
    }

    try {
      log.fine("Loading the ViewManager...");
      this.iwma.loadViewManager();
      log.fine("...loading ViewManager done");
    } catch (Exception e) {
      log.log(Level.SEVERE, "Error loading the ViewManager", e);
    }

    if (!this.iwma.isInDatabaseLessMode()) {
      this.iwma.loadBundles();

      if (!fileSystemStarted) {
        this.iwma.startFileSystem(
            true); // added by Eiki to ensure that ic_file is created before ib_page
      }
    }

    executeServices(this.iwma);
    // create ibdomain
    long end = System.currentTimeMillis();
    long time = (end - start) / 1000;

    // test if all classes are available
    testReferencedClasses();
    log.info("Completed in " + time + " seconds");
  }