1 11 package org.eclipse.core.internal.content; 12 13 import java.util.Hashtable ; 14 import javax.xml.parsers.SAXParserFactory ; 15 import org.eclipse.core.runtime.IExtensionRegistry; 16 import org.eclipse.core.runtime.content.IContentTypeManager; 17 import org.eclipse.osgi.service.debug.DebugOptions; 18 import org.osgi.framework.*; 19 import org.osgi.util.tracker.ServiceTracker; 20 import org.osgi.util.tracker.ServiceTrackerCustomizer; 21 22 25 public class Activator implements BundleActivator, ServiceTrackerCustomizer { 26 27 private static Activator singleton; 28 private static BundleContext bundleContext; 29 private ServiceRegistration contentManagerService = null; 30 private ServiceTracker parserTracker = null; 31 private ServiceTracker debugTracker = null; 32 private ServiceTracker registryTracker = null; 33 34 37 public static Activator getDefault() { 38 return singleton; 39 } 40 41 44 public void start(BundleContext context) throws Exception { 45 bundleContext = context; 46 singleton = this; 47 ContentTypeManager.startup(); 49 contentManagerService = bundleContext.registerService(IContentTypeManager.class.getName(), ContentTypeManager.getInstance(), new Hashtable ()); 50 registryTracker = new ServiceTracker(context, IExtensionRegistry.class.getName(), this); 51 registryTracker.open(); 52 } 53 54 57 public void stop(BundleContext context) throws Exception { 58 if (contentManagerService != null) { 59 contentManagerService.unregister(); 60 contentManagerService = null; 61 } 62 if (parserTracker != null) { 63 parserTracker.close(); 64 parserTracker = null; 65 } 66 if (debugTracker != null) { 67 debugTracker.close(); 68 debugTracker = null; 69 } 70 if (registryTracker != null) { 71 registryTracker.close(); 72 registryTracker = null; 73 } 74 ContentTypeManager.shutdown(); 75 bundleContext = null; 76 } 77 78 81 static BundleContext getContext() { 82 return bundleContext; 83 } 84 85 89 public SAXParserFactory getFactory() { 90 if (parserTracker == null) { 91 parserTracker = new ServiceTracker(bundleContext, SAXParserFactory .class.getName(), null); 92 parserTracker.open(); 93 } 94 SAXParserFactory theFactory = (SAXParserFactory ) parserTracker.getService(); 95 if (theFactory != null) 96 theFactory.setNamespaceAware(true); 97 return theFactory; 98 } 99 100 104 public boolean getBooleanDebugOption(String option, boolean defaultValue) { 105 if (debugTracker == null) { 106 debugTracker = new ServiceTracker(bundleContext, DebugOptions.class.getName(), null); 107 debugTracker.open(); 108 } 109 DebugOptions options = (DebugOptions) debugTracker.getService(); 110 if (options != null) { 111 String value = options.getOption(option); 112 if (value != null) 113 return "true".equalsIgnoreCase(value); } 115 return defaultValue; 116 } 117 118 public Object addingService(ServiceReference reference) { 119 IExtensionRegistry registry = (IExtensionRegistry) bundleContext.getService(reference); 120 ContentTypeManager.addRegistryChangeListener(registry); 122 return registry; 123 } 124 125 public void modifiedService(ServiceReference reference, Object service) { 126 } 128 129 public void removedService(ServiceReference reference, Object service) { 130 ContentTypeManager.removeRegistryChangeListener((IExtensionRegistry) service); 132 bundleContext.ungetService(reference); 133 } 134 } 135 | Popular Tags |