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