package org.simantics.scl.rest; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Activator implements BundleActivator { public static final String START_SERVER = "org.simantics.scl.rest.startServer"; private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class); private static BundleContext context; static BundleContext getContext() { return context; } /* * (non-Javadoc) * * @see * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) */ public void start(BundleContext bundleContext) throws Exception { String onStartup = System.getProperty(START_SERVER); if (onStartup != null && !onStartup.isEmpty()) { try { String[] tokenAndPort = onStartup.split("::"); SCLRESTServer.start(tokenAndPort[0], Integer.parseInt(tokenAndPort[1])); } catch (Exception e) { LOGGER.error("Could not start server with value {}. It should be in the form of ::", onStartup, e); } } Activator.context = bundleContext; } /* * (non-Javadoc) * * @see * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext bundleContext) throws Exception { SCLRESTServer.stop(); Activator.context = null; } }