1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.management.internal;
\r
14 import java.io.IOException;
\r
15 import java.io.InputStream;
\r
16 import java.net.URL;
\r
17 import java.util.Properties;
\r
19 import org.eclipse.core.runtime.Platform;
\r
20 import org.osgi.framework.Bundle;
\r
21 import org.simantics.db.SessionManager;
\r
22 import org.simantics.utils.FileUtils;
\r
24 import fi.vtt.simantics.procore.SessionManagerSource;
\r
27 * Complete hack for the time being. Simply provides the SessionManager behind
\r
28 * procore's SessionManagerSource with proper initialization.
\r
30 public final class SessionManagerProvider {
\r
32 // TODO: move this into BundleContext as a service ?
\r
33 private static SessionManagerProvider provider;
\r
35 private SessionManager sessionManager;
\r
37 public static SessionManagerProvider getInstance() {
\r
38 if (provider == null)
\r
39 provider = new SessionManagerProvider();
\r
43 public SessionManager getSessionManager() throws IOException {
\r
44 if (sessionManager == null) {
\r
45 sessionManager = SessionManagerSource.getSessionManager(loadProperties());
\r
47 return sessionManager;
\r
50 private Properties loadProperties() {
\r
51 Bundle procore = Platform.getBundle("org.simantics.db.procore");
\r
52 URL url = procore.getResource("log4j.properties");
\r
54 InputStream in = null;
\r
56 in = url.openStream();
\r
57 Properties props = new Properties();
\r
60 } catch (Exception e) {
\r
62 FileUtils.uncheckedClose(in);
\r