package info.elexis.server.core.connector.elexis.internal;

import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.elexis.core.constants.Preferences;
import info.elexis.server.core.connector.elexis.services.ConfigService;
import info.elexis.server.core.contrib.ApplicationShutdownRegistrar;
import info.elexis.server.core.contrib.IApplicationShutdownListener;

public class Activator implements BundleActivator {

	private Logger log = LoggerFactory.getLogger(Activator.class);

	private static BundleContext context;
	private static IApplicationShutdownListener iasl = new ApplicationShutdownListener();

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.
	 * BundleContext)
	 */
	public void start(BundleContext bundleContext) throws Exception {
		Activator.context = bundleContext;

		new Timer().schedule(new TimerTask() {

			@Override
			public void run() {
				Locale locale = Locale.getDefault();
				String dbStoredLocale = ConfigService.INSTANCE.get(Preferences.CFG_LOCALE, null);
				if (dbStoredLocale == null || !locale.toString().equals(dbStoredLocale)) {
					log.error("System locale [{}] does not match required database locale [{}].", locale.toString(),
							dbStoredLocale);
					System.out.println("System locale does not match required database locale!");
				}
				// TOOD verify db version?
			}
		}, 1000);

		ApplicationShutdownRegistrar.addShutdownListener(iasl);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext bundleContext) throws Exception {
		ApplicationShutdownRegistrar.removeShutdownListener(iasl);

		Activator.context = null;
	}

}

@@ -57,86 +57,8 @@
 l;%0A%0A
-import java.util.Locale;%0Aimport java.util.Timer;%0Aimport java.util.TimerTask;%0A%0A
 impo
@@ -199,125 +199,8 @@
 y;%0A%0A
-import ch.elexis.core.constants.Preferences;%0Aimport info.elexis.server.core.connector.elexis.services.ConfigService;%0A
 impo
@@ -805,16 +805,18 @@
 ntext;%0A%0A
+//
 %09%09new Ti
@@ -848,17 +848,21 @@
 ask() %7B%0A
-%0A
+//%0A//
 %09%09%09@Over
@@ -866,16 +866,18 @@
 verride%0A
+//
 %09%09%09publi
@@ -887,24 +887,26 @@
 oid run() %7B%0A
+//
 %09%09%09%09Locale l
@@ -934,16 +934,18 @@
 ault();%0A
+//
 %09%09%09%09Stri
@@ -1022,16 +1022,18 @@
  null);%0A
+//
 %09%09%09%09if (
@@ -1103,16 +1103,18 @@
 ale)) %7B%0A
+//
 %09%09%09%09%09log
@@ -1207,16 +1207,18 @@
 ring(),%0A
+//
 %09%09%09%09%09%09%09d
@@ -1233,16 +1233,18 @@
 ocale);%0A
+//
 %09%09%09%09%09Sys
@@ -1322,14 +1322,18 @@
 %22);%0A
+//
 %09%09%09%09%7D%0A
+//
 %09%09%09%09
@@ -1359,21 +1359,25 @@
 ersion?%0A
+//
 %09%09%09%7D%0A
+//
 %09%09%7D, 100

Remove Activator#checkLocale