public void registerExtensions() { if (extensionPoints.length > 0) { return; } List registeringExtensions = new ArrayList(); BundleContext ctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); // parse the plugin files DocumentBuilder docBuilder = OSGiBundleParser.getDocumentBuilder(); org.osgi.framework.Bundle[] osgiBundles = ctx.getBundles(); for (org.osgi.framework.Bundle osgiBundle : osgiBundles) { URL pluginURL = osgiBundle.getEntry("plugin.xml"); if (pluginURL == null) { continue; } Bundle bundle = registerBundle(osgiBundle); if (bundle == null) { // No MANIFEST.MF for this plugin.xml so ignore it continue; } List[] elements = OSGiBundleParser.parsePluginElements(docBuilder, this, pluginURL, bundle, osgiBundle); registerExtensionPointsForPluginInternal(elements[0], false); registeringExtensions.addAll(elements[1]); } extensionPoints = extensionPointsByUniqueId .values() .toArray(new ExtensionPoint[extensionPointsByUniqueId.values().size()]); // Register the extensions now that we have the extension-points all loaded for (int i = 0; i < registeringExtensions.size(); i++) { Extension extension = (Extension) registeringExtensions.get(i); ExtensionPoint exPoint = getExtensionPoint(extension.getExtensionPointId()); if (exPoint == null) { if (extension.getPlugin() != null && extension.getPlugin().getSymbolicName() != null && extension.getPlugin().getSymbolicName().startsWith(DATANUCLEUS_PKG)) { NucleusLogger.GENERAL.warn( Localiser.msg( "024002", extension.getExtensionPointId(), extension.getPlugin().getSymbolicName(), extension.getPlugin().getManifestLocation())); } } else { extension.setExtensionPoint(exPoint); exPoint.addExtension(extension); } } }
/** * Register the plugin bundle. * * @param osgiBundle the OSGi bundle * @return the Plugin */ private Bundle registerBundle(org.osgi.framework.Bundle osgiBundle) { Bundle bundle = OSGiBundleParser.parseManifest(osgiBundle); if (bundle == null) { // Didn't parse correctly, so ignore it return null; } if (registeredPluginByPluginId.get(bundle.getSymbolicName()) == null) { if (NucleusLogger.GENERAL.isDebugEnabled()) { NucleusLogger.GENERAL.debug( "Registering bundle " + bundle.getSymbolicName() + " version " + bundle.getVersion() + " at URL " + bundle.getManifestLocation() + "."); } registeredPluginByPluginId.put(bundle.getSymbolicName(), bundle); } return bundle; }