--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.management.internal;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.net.URL;\r
+import java.util.Properties;\r
+\r
+import org.eclipse.core.runtime.Platform;\r
+import org.osgi.framework.Bundle;\r
+import org.simantics.db.SessionManager;\r
+import org.simantics.utils.FileUtils;\r
+\r
+import fi.vtt.simantics.procore.SessionManagerSource;\r
+\r
+/**\r
+ * Complete hack for the time being. Simply provides the SessionManager behind\r
+ * procore's SessionManagerSource with proper initialization.\r
+ */\r
+public final class SessionManagerProvider {\r
+\r
+ // TODO: move this into BundleContext as a service ?\r
+ private static SessionManagerProvider provider;\r
+\r
+ private SessionManager sessionManager;\r
+\r
+ public static SessionManagerProvider getInstance() {\r
+ if (provider == null)\r
+ provider = new SessionManagerProvider();\r
+ return provider;\r
+ }\r
+\r
+ public SessionManager getSessionManager() throws IOException {\r
+ if (sessionManager == null) {\r
+ sessionManager = SessionManagerSource.getSessionManager(loadProperties());\r
+ }\r
+ return sessionManager;\r
+ }\r
+\r
+ private Properties loadProperties() {\r
+ Bundle procore = Platform.getBundle("org.simantics.db.procore");\r
+ URL url = procore.getResource("log4j.properties");\r
+ if (url != null) {\r
+ InputStream in = null;\r
+ try {\r
+ in = url.openStream();\r
+ Properties props = new Properties();\r
+ props.load(in);\r
+ return props;\r
+ } catch (Exception e) {\r
+ } finally {\r
+ FileUtils.uncheckedClose(in);\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+}\r