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
10 * THTH ry - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.debug.browser.internal;
\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
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
30 public class Activator implements BundleActivator {
\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
41 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.
\r
44 @SuppressWarnings({ "unchecked", "rawtypes" })
\r
45 public void start(BundleContext bundleContext) throws Exception {
\r
46 Activator.context = bundleContext;
\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
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
63 public DebugBrowserServer getDebugServer() {
\r
67 public synchronized DebugBrowserServer startDebugServer() throws Exception {
\r
68 if (server == null) {
\r
69 server = new DebugBrowserServer(resourcesPath);
\r
75 public synchronized void stopDebugServer() throws Exception {
\r
76 if (server != null) {
\r
82 public static BundleContext getContext() {
\r
90 * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
\r
92 public void stop(BundleContext bundleContext) throws Exception {
\r
94 Activator.context = null;
\r
98 * Returns the shared instance
\r
100 * @return the shared instance
\r
102 public static Activator getDefault() {
\r