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