| package sample.js.debugdisplay; |
| |
| import java.net.URL; |
| |
| import org.eclipse.e4.internal.languages.javascript.JSFrameworkImpl; |
| import org.eclipse.e4.languages.javascript.JSBundle; |
| import org.eclipse.e4.languages.javascript.JSBundleException; |
| import org.eclipse.e4.languages.javascript.JSFramework; |
| import org.osgi.framework.Bundle; |
| import org.osgi.framework.BundleActivator; |
| import org.osgi.framework.BundleContext; |
| import org.osgi.framework.ServiceReference; |
| import org.osgi.util.tracker.ServiceTracker; |
| import org.osgi.util.tracker.ServiceTrackerCustomizer; |
| |
| public class Activator implements BundleActivator, ServiceTrackerCustomizer { |
| |
| public static final String TEST = "test"; |
| |
| private BundleContext context; |
| private ServiceTracker frameworkTracker; |
| private JSFramework framework; |
| |
| private JSBundle jsBundle; |
| |
| public void start(BundleContext bundleContext) throws Exception { |
| this.context = bundleContext; |
| |
| frameworkTracker = new ServiceTracker(context, JSFramework.class.getName(), this); |
| frameworkTracker.open(); |
| } |
| |
| public void stop(BundleContext bundleContext) throws Exception { |
| frameworkTracker.close(); |
| frameworkTracker = null; |
| context = null; |
| } |
| |
| public Object addingService(ServiceReference reference) { |
| framework = (JSFramework) context.getService(reference); |
| |
| Bundle bundle = context.getBundle(); |
| URL jsBundleEntry = bundle.getEntry("scripts/bundle.json"); |
| if (jsBundleEntry == null) |
| return null; |
| |
| |
| try { |
| jsBundle =((JSFrameworkImpl)framework).installBundle(jsBundleEntry.toString(), bundle); |
| } catch (JSBundleException e) { |
| // TODO Auto-generated catch block |
| e.printStackTrace(); |
| } |
| framework.resolve(); |
| return framework; |
| } |
| |
| public void modifiedService(ServiceReference reference, Object service) { |
| } |
| |
| public void removedService(ServiceReference reference, Object service) { |
| jsBundle.uninstall(); |
| framework.resolve(); |
| } |
| |
| |
| } |