]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/internal/Activator.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / internal / Activator.java
1 package org.simantics.db.common.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.osgi.framework.BundleActivator;\r
10 import org.osgi.framework.BundleContext;\r
11 import org.simantics.db.common.internal.config.InternalClientConfig;\r
12 \r
13 /**\r
14  * @author Tuukka Lehtonen\r
15  *\r
16  */\r
17 public class Activator implements BundleActivator {\r
18 \r
19         // The plug-in ID\r
20         public static final String BUNDLE_ID = "org.simantics.db.common"; //$NON-NLS-1$\r
21 \r
22         // The shared instance\r
23         private static Activator plugin;\r
24 \r
25         /**\r
26          * The constructor\r
27          */\r
28         public Activator() {\r
29         }\r
30 \r
31         /*\r
32          * (non-Javadoc)\r
33          * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)\r
34          */\r
35         @Override\r
36         public void start(BundleContext context) throws Exception {\r
37                 plugin = this;\r
38 \r
39                 String prop = System.getProperty("osgi.instance.area", null);\r
40                 if (prop != null) {\r
41                         try {\r
42                                 URL url = new URL(prop);\r
43                                 if ("file".equals(url .getProtocol())) {\r
44                                         try {\r
45                                                 File path = new File(URLDecoder.decode(url.getPath(), "UTF-8"));\r
46                                                 if (!path.exists())\r
47                                                         path.mkdirs();\r
48                                                 if (path.exists() && path.canWrite()) {\r
49                                                         File logFile = new File(path, InternalClientConfig.DB_CLIENT_LOG_FILE_NAME);\r
50                                                         if (!logFile.exists() || (logFile.isFile() && logFile.canWrite()))\r
51                                                                 InternalClientConfig.DB_CLIENT_LOG_FILE = logFile.getAbsolutePath();\r
52 \r
53                                                         File tempDir = new File(path, InternalClientConfig.DB_CLIENT_TEMP_DIR_NAME);\r
54                                                         if (!tempDir.exists() || (tempDir.isDirectory() && tempDir.canWrite()))\r
55                                                                 InternalClientConfig.DB_CLIENT_TEMP_DIR = tempDir;\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 \r
67         /*\r
68          * (non-Javadoc)\r
69          * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)\r
70          */\r
71         @Override\r
72         public void stop(BundleContext context) throws Exception {\r
73                 plugin = null;\r
74         }\r
75 \r
76         /**\r
77          * Returns the shared instance\r
78          *\r
79          * @return the shared instance\r
80          */\r
81         public static Activator getDefault() {\r
82                 return plugin;\r
83         }\r
84 \r
85 }