1 11 12 package org.eclipse.core.runtime.internal.adaptor; 13 14 import java.io.*; 15 import java.net.URLConnection ; 16 import java.util.*; 17 import javax.xml.parsers.DocumentBuilderFactory ; 18 import javax.xml.parsers.SAXParserFactory ; 19 import org.eclipse.core.runtime.adaptor.LocationManager; 20 import org.eclipse.osgi.baseadaptor.*; 21 import org.eclipse.osgi.baseadaptor.hooks.AdaptorHook; 22 import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor; 23 import org.eclipse.osgi.framework.console.CommandProvider; 24 import org.eclipse.osgi.framework.debug.Debug; 25 import org.eclipse.osgi.framework.debug.FrameworkDebugOptions; 26 import org.eclipse.osgi.framework.internal.core.Constants; 27 import org.eclipse.osgi.framework.log.FrameworkLog; 28 import org.eclipse.osgi.framework.log.FrameworkLogEntry; 29 import org.eclipse.osgi.internal.baseadaptor.AdaptorUtil; 30 import org.eclipse.osgi.service.datalocation.Location; 31 import org.eclipse.osgi.service.pluginconversion.PluginConverter; 32 import org.eclipse.osgi.service.resolver.PlatformAdmin; 33 import org.eclipse.osgi.service.runnable.ApplicationLauncher; 34 import org.eclipse.osgi.service.urlconversion.URLConverter; 35 import org.osgi.framework.*; 36 37 public class EclipseAdaptorHook implements AdaptorHook, HookConfigurator { 38 39 public static final String SAXFACTORYNAME = "javax.xml.parsers.SAXParserFactory"; 41 public static final String DOMFACTORYNAME = "javax.xml.parsers.DocumentBuilderFactory"; private static final String RUNTIME_ADAPTOR = FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME + "/eclipseadaptor"; private static final String OPTION_CONVERTER = RUNTIME_ADAPTOR + "/converter/debug"; private static final String OPTION_LOCATION = RUNTIME_ADAPTOR + "/debug/location"; 46 private BaseAdaptor adaptor; 47 private boolean noXML = false; 48 49 public void frameworkStart(BundleContext context) throws BundleException { 50 registerEndorsedXMLParser(context); 51 Location location = LocationManager.getUserLocation(); 52 Hashtable locationProperties = new Hashtable(1); 53 if (location != null) { 54 locationProperties.put("type", LocationManager.PROP_USER_AREA); context.registerService(Location.class.getName(), location, locationProperties); 56 } 57 location = LocationManager.getInstanceLocation(); 58 if (location != null) { 59 locationProperties.put("type", LocationManager.PROP_INSTANCE_AREA); context.registerService(Location.class.getName(), location, locationProperties); 61 } 62 location = LocationManager.getConfigurationLocation(); 63 if (location != null) { 64 locationProperties.put("type", LocationManager.PROP_CONFIG_AREA); context.registerService(Location.class.getName(), location, locationProperties); 66 } 67 location = LocationManager.getInstallLocation(); 68 if (location != null) { 69 locationProperties.put("type", LocationManager.PROP_INSTALL_AREA); context.registerService(Location.class.getName(), location, locationProperties); 71 } 72 73 Dictionary urlProperties = new Hashtable(); 74 urlProperties.put("protocol", new String [] {"bundleentry", "bundleresource"}); context.registerService(URLConverter.class.getName(), new URLConverterImpl(), urlProperties); 76 77 AdaptorUtil.register(org.eclipse.osgi.service.environment.EnvironmentInfo.class.getName(), EclipseEnvironmentInfo.getDefault(), context); 78 AdaptorUtil.register(PlatformAdmin.class.getName(), adaptor.getPlatformAdmin(), context); 79 PluginConverter converter = PluginConverterImpl.getDefault(); 80 if (converter == null) 81 converter = new PluginConverterImpl(adaptor, context); 82 AdaptorUtil.register(PluginConverter.class.getName(), converter, context); 83 AdaptorUtil.register(CommandProvider.class.getName(), new EclipseCommandProvider(context), context); 84 AdaptorUtil.register(org.eclipse.osgi.service.localization.BundleLocalization.class.getName(), new BundleLocalizationImpl(), context); 85 } 86 87 private void registerEndorsedXMLParser(BundleContext bc) { 88 try { 89 Class.forName(SAXFACTORYNAME); 90 bc.registerService(SAXFACTORYNAME, new SaxParsingService(), new Hashtable()); 91 Class.forName(DOMFACTORYNAME); 92 bc.registerService(DOMFACTORYNAME, new DomParsingService(), new Hashtable()); 93 } catch (ClassNotFoundException e) { 94 noXML = true; 95 if (Debug.DEBUG && Debug.DEBUG_ENABLED) { 96 String message = EclipseAdaptorMsg.ECLIPSE_ADAPTOR_ERROR_XML_SERVICE; 97 adaptor.getFrameworkLog().log(new FrameworkLogEntry(FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME, FrameworkLogEntry.ERROR, 0, message, 0, e, null)); 98 } 99 } 100 } 101 102 private class SaxParsingService implements ServiceFactory { 103 public Object getService(Bundle bundle, ServiceRegistration registration) { 104 return SAXParserFactory.newInstance(); 105 } 106 107 public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) { 108 } 110 } 111 112 private class DomParsingService implements ServiceFactory { 113 public Object getService(Bundle bundle, ServiceRegistration registration) { 114 return DocumentBuilderFactory.newInstance(); 115 } 116 117 public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) { 118 } 120 } 121 122 public void frameworkStop(BundleContext context) throws BundleException { 123 printStats(); 125 if (!noXML) 126 PluginParser.releaseXMLParsing(); 127 } 128 129 private void printStats() { 130 FrameworkDebugOptions debugOptions = FrameworkDebugOptions.getDefault(); 131 if (debugOptions == null) 132 return; 133 String registryParsing = debugOptions.getOption("org.eclipse.core.runtime/registry/parsing/timing/value"); if (registryParsing != null) 135 MessageHelper.debug("Time spent in registry parsing: " + registryParsing); String packageAdminResolution = debugOptions.getOption("debug.packageadmin/timing/value"); if (packageAdminResolution != null) 138 System.out.println("Time spent in package admin resolve: " + packageAdminResolution); String constraintResolution = debugOptions.getOption("org.eclipse.core.runtime.adaptor/resolver/timing/value"); if (constraintResolution != null) 141 System.out.println("Time spent resolving the dependency system: " + constraintResolution); } 143 144 public void frameworkStopping(BundleContext context) { 145 ServiceReference launcherRef = context.getServiceReference(ApplicationLauncher.class.getName()); 147 if (launcherRef != null) { 148 ApplicationLauncher launcher = (ApplicationLauncher) context.getService(launcherRef); 149 launcher.shutdown(); 151 context.ungetService(launcherRef); 152 } 153 } 154 155 public void addProperties(Properties properties) { 156 if (properties.getProperty(Constants.ECLIPSE_EE_INSTALL_VERIFY) == null) 158 properties.put(Constants.ECLIPSE_EE_INSTALL_VERIFY, "false"); if (properties.getProperty(Constants.OSGI_COMPATIBILITY_BOOTDELEGATION) == null) 161 properties.put(Constants.OSGI_COMPATIBILITY_BOOTDELEGATION, "true"); } 163 164 public URLConnection mapLocationToURLConnection(String location) throws IOException { 165 return null; 167 } 168 169 public void handleRuntimeError(Throwable error) { 170 } 172 173 public boolean matchDNChain(String pattern, String [] dnChain) { 174 return false; 176 } 177 178 public FrameworkLog createFrameworkLog() { 179 return null; 181 } 182 183 public void initialize(BaseAdaptor adaptor) { 184 this.adaptor = adaptor; 185 EclipseEnvironmentInfo.getDefault(); 187 setDebugOptions(); 188 } 189 190 private void setDebugOptions() { 191 FrameworkDebugOptions options = FrameworkDebugOptions.getDefault(); 192 if (options == null) 194 return; 195 PluginConverterImpl.DEBUG = options.getBooleanOption(OPTION_CONVERTER, false); 196 BasicLocation.DEBUG = options.getBooleanOption(OPTION_LOCATION, false); 197 } 198 199 public void addHooks(HookRegistry hookRegistry) { 200 hookRegistry.addAdaptorHook(this); 201 } 202 203 } 204 | Popular Tags |