]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.rest/src/org/simantics/scl/rest/Activator.java
Merge "Dirty hack to get CHR ruleset resolved before functions using them"
[simantics/platform.git] / bundles / org.simantics.scl.rest / src / org / simantics / scl / rest / Activator.java
1 package org.simantics.scl.rest;
2
3 import org.osgi.framework.BundleActivator;
4 import org.osgi.framework.BundleContext;
5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
7
8 public class Activator implements BundleActivator {
9
10     public static final String START_SERVER = "org.simantics.scl.rest.startServer";
11     
12     private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
13     
14     private static BundleContext context;
15
16     static BundleContext getContext() {
17         return context;
18     }
19
20     /*
21      * (non-Javadoc)
22      * 
23      * @see
24      * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
25      */
26     public void start(BundleContext bundleContext) throws Exception {
27         String onStartup = System.getProperty(START_SERVER);
28         if (onStartup != null && !onStartup.isEmpty()) {
29             try {
30                 String[] tokenAndPort = onStartup.split("::");
31                 SCLRESTServer.start(tokenAndPort[0], Integer.parseInt(tokenAndPort[1]));
32             } catch (Exception e) {
33                 LOGGER.error("Could not start server with value {}. It should be in the form of <secret-token>::<port-number>", onStartup, e);
34             }
35         }
36         Activator.context = bundleContext;
37     }
38
39     /*
40      * (non-Javadoc)
41      * 
42      * @see
43      * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
44      */
45     public void stop(BundleContext bundleContext) throws Exception {
46         SCLRESTServer.stop();
47         Activator.context = null;
48     }
49
50 }