/** Dispose of this component activator instance and all the component managers. */ void dispose(int reason) { if (m_context == null) { return; } // mark instance inactive (no more component activations) m_active = false; log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] will destroy {1} instances", new Object[] { new Long(m_context.getBundle().getBundleId()), new Integer(m_managers.size()) }, null, null); while (m_managers.size() != 0) { ComponentHolder holder = (ComponentHolder) m_managers.get(0); try { m_managers.remove(holder); holder.disposeComponents(reason); } catch (Exception e) { log( LogService.LOG_ERROR, "BundleComponentActivator : Exception invalidating", holder.getComponentMetadata(), e); } finally { m_componentRegistry.unregisterComponentHolder(holder.getComponentMetadata().getName()); } } log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] STOPPED", new Object[] {new Long(m_context.getBundle().getBundleId())}, null, null); if (m_logService != null) { m_logService.close(); m_logService = null; } m_componentActor = null; m_componentRegistry = null; m_context = null; }
private void loadDescriptor(final URL descriptorURL) { // simple path for log messages final String descriptorLocation = descriptorURL.getPath(); InputStream stream = null; try { stream = descriptorURL.openStream(); BufferedReader in = new BufferedReader(new InputStreamReader(stream)); XmlHandler handler = new XmlHandler(m_context.getBundle(), this); KXml2SAXParser parser; parser = new KXml2SAXParser(in); parser.parseXML(handler); // 112.4.2 Component descriptors may contain a single, root component element // or one or more component elements embedded in a larger document Iterator i = handler.getComponentMetadataList().iterator(); while (i.hasNext()) { ComponentMetadata metadata = (ComponentMetadata) i.next(); try { // check and reserve the component name m_componentRegistry.checkComponentName(metadata.getName()); // validate the component metadata metadata.validate(this); // Request creation of the component manager ComponentHolder holder = m_componentRegistry.createComponentHolder(this, metadata); // register the component after validation m_componentRegistry.registerComponentHolder(metadata.getName(), holder); m_managers.add(holder); // enable the component if (metadata.isEnabled()) { holder.enableComponents(); } } catch (Throwable t) { // There is a problem with this particular component, we'll log the error // and proceed to the next one log(LogService.LOG_ERROR, "Cannot register Component", metadata, t); // make sure the name is not reserved any more m_componentRegistry.unregisterComponentHolder(metadata.getName()); } } } catch (IOException ex) { // 112.4.1 If an XML document specified by the header cannot be located in the bundle and its // attached // fragments, SCR must log an error message with the Log Service, if present, and continue. log( LogService.LOG_ERROR, "Problem reading descriptor entry ''{0}''", new Object[] {descriptorLocation}, null, ex); } catch (Exception ex) { log( LogService.LOG_ERROR, "General problem with descriptor entry ''{0}''", new Object[] {descriptorLocation}, null, ex); } finally { if (stream != null) { try { stream.close(); } catch (IOException ignore) { } } } }