]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/Activator.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.spreadsheet.common / src / org / simantics / spreadsheet / common / Activator.java
1 package org.simantics.spreadsheet.common;
2 import java.io.File;
3 import java.io.UnsupportedEncodingException;
4 import java.net.MalformedURLException;
5 import java.net.URL;
6 import java.net.URLDecoder;
7
8 import org.osgi.framework.BundleActivator;
9 import org.osgi.framework.BundleContext;
10
11
12 public class Activator implements BundleActivator {
13
14         /**
15          * Name of the log file. 
16          */
17         public static String LOG_FILE_NAME = "spreadsheet.log";
18
19         // The plug-in ID
20         public static final String BUNDLE_ID = "org.simantics.spreadsheet.common"; //$NON-NLS-1$
21
22         // The shared instance
23         private static Activator plugin;
24
25         /**
26          * The constructor
27          */
28         public Activator() {
29         }
30
31         /*
32          * (non-Javadoc)
33          * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
34          */
35         @Override
36         public void start(BundleContext context) throws Exception {
37                 plugin = this;
38
39                 String prop = System.getProperty("osgi.instance.area", null);
40                 if (prop != null) {
41                         try {
42                                 URL url = new URL(prop);
43                                 if ("file".equals(url .getProtocol())) {
44                                         try {
45                                                 File path = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
46                                                 if (!path.exists())
47                                                         path.mkdirs();
48                                                 if (path.exists() && path.canWrite()) {
49                                                         File logFile = new File(path, LOG_FILE_NAME);
50                                                         if (!logFile.exists() || (logFile.isFile() && logFile.canWrite()))
51                                                                 LOG_FILE_NAME = logFile.getAbsolutePath();
52
53                                                 }
54                                         } catch (UnsupportedEncodingException e) {
55                                                 // Should never happen since UTF-8 is always supported.
56                                         }
57                                 }
58                         } catch (MalformedURLException e) {
59                                 // Ignore.
60                         }
61                 }
62         }
63
64         /*
65          * (non-Javadoc)
66          * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
67          */
68         @Override
69         public void stop(BundleContext context) throws Exception {
70                 plugin = null;
71         }
72
73         /**
74          * Returns the shared instance
75          *
76          * @return the shared instance
77          */
78         public static Activator getDefault() {
79                 return plugin;
80         }
81
82 }