]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/internal/Activator.java b/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/internal/Activator.java
new file mode 100644 (file)
index 0000000..2709163
--- /dev/null
@@ -0,0 +1,106 @@
+/*******************************************************************************\r
+ * Copyright (c) 2016 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     THTH ry - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.debug.browser.internal;\r
+\r
+import java.io.File;\r
+import java.net.URL;\r
+import java.net.URLDecoder;\r
+import java.util.Hashtable;\r
+\r
+import org.eclipse.core.runtime.FileLocator;\r
+import org.osgi.framework.BundleActivator;\r
+import org.osgi.framework.BundleContext;\r
+import org.simantics.debug.browser.content.ResourceBrowserRewriter;\r
+import org.simantics.debug.browser.internal.rewriters.BreadcrumbCreator;\r
+import org.simantics.debug.browser.internal.rewriters.PageHeaderCreator;\r
+import org.simantics.debug.browser.internal.rewriters.RawStatementsCreator;\r
+import org.simantics.debug.browser.internal.rewriters.ResourceInfoCreator;\r
+import org.simantics.debug.browser.internal.rewriters.ResourceLookupCreator;\r
+import org.simantics.debug.browser.internal.rewriters.TypeHierarchyCreator;\r
+\r
+public class Activator implements BundleActivator {\r
+\r
+    public static final String PLUGIN_ID = "org.simantics.debug.browser";\r
+    private static BundleContext context;\r
+    private static Activator plugin;\r
+    private static String resourcesPath;\r
+    private DebugBrowserServer server;\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.\r
+     * BundleContext)\r
+     */\r
+    @SuppressWarnings({ "unchecked", "rawtypes" })\r
+    public void start(BundleContext bundleContext) throws Exception {\r
+        Activator.context = bundleContext;\r
+        plugin = this;\r
+\r
+        Hashtable properties = new Hashtable();\r
+        bundleContext.registerService(ResourceBrowserRewriter.class, PageHeaderCreator.INSTANCE, properties);\r
+        bundleContext.registerService(ResourceBrowserRewriter.class, ResourceLookupCreator.INSTANCE, properties);\r
+        bundleContext.registerService(ResourceBrowserRewriter.class, RawStatementsCreator.INSTANCE, properties);\r
+        bundleContext.registerService(ResourceBrowserRewriter.class, BreadcrumbCreator.INSTANCE, properties);\r
+        bundleContext.registerService(ResourceBrowserRewriter.class, TypeHierarchyCreator.INSTANCE, properties);\r
+        bundleContext.registerService(ResourceBrowserRewriter.class, ResourceInfoCreator.INSTANCE, properties);\r
+\r
+        URL url = context.getBundle().getEntry("resources");\r
+        URL fileURL = FileLocator.toFileURL(url);\r
+        File filePath = new File(URLDecoder.decode(fileURL.getPath(), "UTF-8"));\r
+        resourcesPath = filePath.getCanonicalPath();\r
+    }\r
+\r
+    public DebugBrowserServer getDebugServer() {\r
+        return server;\r
+    }\r
+\r
+    public synchronized DebugBrowserServer startDebugServer() throws Exception {\r
+        if (server == null) {\r
+            server = new DebugBrowserServer(resourcesPath);\r
+            server.start();\r
+        }\r
+        return server;\r
+    }\r
+\r
+    public synchronized void stopDebugServer() throws Exception {\r
+        if (server != null) {\r
+            server.stop();\r
+        }\r
+        server = null;\r
+    }\r
+\r
+    public static BundleContext getContext() {\r
+        return context;\r
+    }\r
+\r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see\r
+     * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)\r
+     */\r
+    public void stop(BundleContext bundleContext) throws Exception {\r
+        stopDebugServer();\r
+        Activator.context = null;\r
+    }\r
+\r
+    /**\r
+     * Returns the shared instance\r
+     *\r
+     * @return the shared instance\r
+     */\r
+    public static Activator getDefault() {\r
+        return plugin;\r
+    }\r
+\r
+}\r