1 package org.simantics.internal;
4 import java.io.UnsupportedEncodingException;
5 import java.net.MalformedURLException;
7 import java.net.URLDecoder;
9 import org.eclipse.core.runtime.Plugin;
10 import org.osgi.framework.BundleContext;
11 import org.simantics.internal.startup.StartupRegistry;
13 public class Activator extends Plugin {
16 * Name of the log file.
18 public static String LOG_FILE_NAME = "simantics.log";
20 public static final String PLUGIN_ID = "org.simantics";
22 // The shared instance
23 private static Activator plugin;
25 private static BundleContext context;
27 private StartupRegistry startupRegistry;
29 static BundleContext getContext() {
35 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
37 public void start(BundleContext bundleContext) throws Exception {
38 super.start(bundleContext);
39 Activator.context = bundleContext;
42 String prop = System.getProperty("osgi.instance.area", null);
45 URL url = new URL(prop);
46 if ("file".equals(url .getProtocol())) {
48 File path = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
51 if (path.exists() && path.canWrite()) {
52 File logFile = new File(path, LOG_FILE_NAME);
53 if (!logFile.exists() || (logFile.isFile() && logFile.canWrite()))
54 LOG_FILE_NAME = logFile.getAbsolutePath();
57 } catch (UnsupportedEncodingException e) {
58 // Should never happen since UTF-8 is always supported.
61 } catch (MalformedURLException e) {
66 startupRegistry = new StartupRegistry();
71 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
73 public void stop(BundleContext bundleContext) throws Exception {
74 Activator.context = null;
76 super.stop(bundleContext);
80 * @return the context of this bundle.
82 public static BundleContext getBundleContext() {
87 * Returns the shared instance
89 * @return the shared instance
91 public static Activator getDefault() {
98 public StartupRegistry getStartupRegistry() {
99 return startupRegistry;