]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics/src/org/simantics/internal/Activator.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / internal / Activator.java
1 package org.simantics.internal;\r
2 \r
3 import java.io.File;\r
4 import java.io.UnsupportedEncodingException;\r
5 import java.net.MalformedURLException;\r
6 import java.net.URL;\r
7 import java.net.URLDecoder;\r
8 \r
9 import org.eclipse.core.runtime.Plugin;\r
10 import org.osgi.framework.BundleContext;\r
11 import org.simantics.internal.startup.StartupRegistry;\r
12 \r
13 public class Activator extends Plugin {\r
14 \r
15         /**\r
16          * Name of the log file. \r
17          */\r
18         public static String LOG_FILE_NAME = "simantics.log";\r
19 \r
20         public static final String PLUGIN_ID = "org.simantics";\r
21 \r
22         // The shared instance\r
23         private static Activator plugin;\r
24 \r
25         private static BundleContext context;\r
26 \r
27         private StartupRegistry startupRegistry;\r
28 \r
29         static BundleContext getContext() {\r
30                 return context;\r
31         }\r
32 \r
33         /*\r
34          * (non-Javadoc)\r
35          * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)\r
36          */\r
37         public void start(BundleContext bundleContext) throws Exception {\r
38                 super.start(bundleContext);\r
39                 Activator.context = bundleContext;\r
40                 plugin = this;\r
41 \r
42                 String prop = System.getProperty("osgi.instance.area", null);\r
43                 if (prop != null) {\r
44                         try {\r
45                                 URL url = new URL(prop);\r
46                                 if ("file".equals(url .getProtocol())) {\r
47                                         try {\r
48                                                 File path = new File(URLDecoder.decode(url.getPath(), "UTF-8"));\r
49                                                 if (!path.exists())\r
50                                                         path.mkdirs();\r
51                                                 if (path.exists() && path.canWrite()) {\r
52                                                         File logFile = new File(path, LOG_FILE_NAME);\r
53                                                         if (!logFile.exists() || (logFile.isFile() && logFile.canWrite()))\r
54                                                                 LOG_FILE_NAME = logFile.getAbsolutePath();\r
55 \r
56                                                 }\r
57                                         } catch (UnsupportedEncodingException e) {\r
58                                                 // Should never happen since UTF-8 is always supported.\r
59                                         }\r
60                                 }\r
61                         } catch (MalformedURLException e) {\r
62                                 // Ignore.\r
63                         }\r
64                 }               \r
65 \r
66                 startupRegistry = new StartupRegistry();\r
67         }\r
68 \r
69         /*\r
70          * (non-Javadoc)\r
71          * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)\r
72          */\r
73         public void stop(BundleContext bundleContext) throws Exception {\r
74                 Activator.context = null;\r
75                 plugin = null;\r
76                 super.stop(bundleContext);\r
77         }\r
78 \r
79         /**\r
80          * @return the context of this bundle.\r
81          */\r
82         public static BundleContext getBundleContext() {\r
83                 return context;\r
84         }\r
85 \r
86         /**\r
87          * Returns the shared instance\r
88          *\r
89          * @return the shared instance\r
90          */\r
91         public static Activator getDefault() {\r
92                 return plugin;\r
93         }\r
94 \r
95         /**\r
96          * @return\r
97          */\r
98         public StartupRegistry getStartupRegistry() {\r
99                 return startupRegistry;\r
100         }\r
101 \r
102 }\r