]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/internal/Activator.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.debug.browser / src / org / simantics / debug / browser / internal / Activator.java
1 /*******************************************************************************\r
2  * Copyright (c) 2016 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     THTH ry - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.debug.browser.internal;\r
13 \r
14 import java.io.File;\r
15 import java.net.URL;\r
16 import java.net.URLDecoder;\r
17 import java.util.Hashtable;\r
18 \r
19 import org.eclipse.core.runtime.FileLocator;\r
20 import org.osgi.framework.BundleActivator;\r
21 import org.osgi.framework.BundleContext;\r
22 import org.simantics.debug.browser.content.ResourceBrowserRewriter;\r
23 import org.simantics.debug.browser.internal.rewriters.BreadcrumbCreator;\r
24 import org.simantics.debug.browser.internal.rewriters.PageHeaderCreator;\r
25 import org.simantics.debug.browser.internal.rewriters.RawStatementsCreator;\r
26 import org.simantics.debug.browser.internal.rewriters.ResourceInfoCreator;\r
27 import org.simantics.debug.browser.internal.rewriters.ResourceLookupCreator;\r
28 import org.simantics.debug.browser.internal.rewriters.TypeHierarchyCreator;\r
29 \r
30 public class Activator implements BundleActivator {\r
31 \r
32     public static final String PLUGIN_ID = "org.simantics.debug.browser";\r
33     private static BundleContext context;\r
34     private static Activator plugin;\r
35     private static String resourcesPath;\r
36     private DebugBrowserServer server;\r
37 \r
38     /*\r
39      * (non-Javadoc)\r
40      * \r
41      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.\r
42      * BundleContext)\r
43      */\r
44     @SuppressWarnings({ "unchecked", "rawtypes" })\r
45     public void start(BundleContext bundleContext) throws Exception {\r
46         Activator.context = bundleContext;\r
47         plugin = this;\r
48 \r
49         Hashtable properties = new Hashtable();\r
50         bundleContext.registerService(ResourceBrowserRewriter.class, PageHeaderCreator.INSTANCE, properties);\r
51         bundleContext.registerService(ResourceBrowserRewriter.class, ResourceLookupCreator.INSTANCE, properties);\r
52         bundleContext.registerService(ResourceBrowserRewriter.class, RawStatementsCreator.INSTANCE, properties);\r
53         bundleContext.registerService(ResourceBrowserRewriter.class, BreadcrumbCreator.INSTANCE, properties);\r
54         bundleContext.registerService(ResourceBrowserRewriter.class, TypeHierarchyCreator.INSTANCE, properties);\r
55         bundleContext.registerService(ResourceBrowserRewriter.class, ResourceInfoCreator.INSTANCE, properties);\r
56 \r
57         URL url = context.getBundle().getEntry("resources");\r
58         URL fileURL = FileLocator.toFileURL(url);\r
59         File filePath = new File(URLDecoder.decode(fileURL.getPath(), "UTF-8"));\r
60         resourcesPath = filePath.getCanonicalPath();\r
61     }\r
62 \r
63     public DebugBrowserServer getDebugServer() {\r
64         return server;\r
65     }\r
66 \r
67     public synchronized DebugBrowserServer startDebugServer() throws Exception {\r
68         if (server == null) {\r
69             server = new DebugBrowserServer(resourcesPath);\r
70             server.start();\r
71         }\r
72         return server;\r
73     }\r
74 \r
75     public synchronized void stopDebugServer() throws Exception {\r
76         if (server != null) {\r
77             server.stop();\r
78         }\r
79         server = null;\r
80     }\r
81 \r
82     public static BundleContext getContext() {\r
83         return context;\r
84     }\r
85 \r
86     /*\r
87      * (non-Javadoc)\r
88      * \r
89      * @see\r
90      * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)\r
91      */\r
92     public void stop(BundleContext bundleContext) throws Exception {\r
93         stopDebugServer();\r
94         Activator.context = null;\r
95     }\r
96 \r
97     /**\r
98      * Returns the shared instance\r
99      *\r
100      * @return the shared instance\r
101      */\r
102     public static Activator getDefault() {\r
103         return plugin;\r
104     }\r
105 \r
106 }\r